Skip to content

Commit

Permalink
Confluence added (langchain-ai#6432)
Browse files Browse the repository at this point in the history
Adding Confluence to Jira tool. Can create a page in Confluence with
this PR. If accepted, will extend functionality to Bitbucket and
additional Confluence features.



---------

Co-authored-by: Ethan Bowen <[email protected]>
  • Loading branch information
ethanabowen and Ethan Bowen authored Jun 26, 2023
1 parent 2aeb8e7 commit cc33bde
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion langchain/tools/jira/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Zapier Tool."""
"""Jira Tool."""
7 changes: 7 additions & 0 deletions langchain/tools/jira/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@
self.jira.projects()
For more information on the Jira API, refer to https://atlassian-python-api.readthedocs.io/jira.html
"""

JIRA_CONFLUENCE_PAGE_CREATE_PROMPT = """This tool is a wrapper around atlassian-python-api's Confluence
atlassian-python-api API, useful when you need to create a Confluence page. The input to this tool is a dictionary
specifying the fields of the Confluence page, and will be passed into atlassian-python-api's Confluence `create_page`
function. For example, to create a page in the DEMO space titled "This is the title" with body "This is the body. You can use
<strong>HTML tags</strong>!", you would pass in the following dictionary: {{"space": "DEMO", "title":"This is the
title","body":"This is the body. You can use <strong>HTML tags</strong>!"}} """
34 changes: 31 additions & 3 deletions langchain/utilities/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from langchain.tools.jira.prompt import (
JIRA_CATCH_ALL_PROMPT,
JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
JIRA_GET_ALL_PROJECTS_PROMPT,
JIRA_ISSUE_CREATE_PROMPT,
JIRA_JQL_PROMPT,
Expand All @@ -17,6 +18,7 @@ class JiraAPIWrapper(BaseModel):
"""Wrapper for Jira API."""

jira: Any #: :meta private:
confluence: Any
jira_username: Optional[str] = None
jira_api_token: Optional[str] = None
jira_instance_url: Optional[str] = None
Expand All @@ -42,6 +44,11 @@ class JiraAPIWrapper(BaseModel):
"name": "Catch all Jira API call",
"description": JIRA_CATCH_ALL_PROMPT,
},
{
"mode": "create_page",
"name": "Create confluence page",
"description": JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
},
]

class Config:
Expand Down Expand Up @@ -69,7 +76,7 @@ def validate_environment(cls, values: Dict) -> Dict:
values["jira_instance_url"] = jira_instance_url

try:
from atlassian import Jira
from atlassian import Confluence, Jira
except ImportError:
raise ImportError(
"atlassian-python-api is not installed. "
Expand All @@ -82,7 +89,16 @@ def validate_environment(cls, values: Dict) -> Dict:
password=jira_api_token,
cloud=True,
)

confluence = Confluence(
url=jira_instance_url,
username=jira_username,
password=jira_api_token,
cloud=True,
)

values["jira"] = jira
values["confluence"] = confluence

return values

Expand Down Expand Up @@ -151,7 +167,7 @@ def project(self) -> str:
)
return parsed_projects_str

def create(self, query: str) -> str:
def issue_create(self, query: str) -> str:
try:
import json
except ImportError:
Expand All @@ -161,6 +177,16 @@ def create(self, query: str) -> str:
params = json.loads(query)
return self.jira.issue_create(fields=dict(params))

def page_create(self, query: str) -> str:
try:
import json
except ImportError:
raise ImportError(
"json is not installed. Please install it with `pip install json`"
)
params = json.loads(query)
return self.confluence.create_page(**dict(params))

def other(self, query: str) -> str:
context = {"self": self}
exec(f"result = {query}", context)
Expand All @@ -173,8 +199,10 @@ def run(self, mode: str, query: str) -> str:
elif mode == "get_projects":
return self.project()
elif mode == "create_issue":
return self.create(query)
return self.issue_create(query)
elif mode == "other":
return self.other(query)
elif mode == "create_page":
return self.page_create(query)
else:
raise ValueError(f"Got unexpected mode {mode}")
14 changes: 14 additions & 0 deletions tests/integration_tests/utilities/test_jira_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ def test_create_ticket() -> None:
output = jira.run("create_issue", issue_string)
assert "id" in output
assert "key" in output


def test_create_confluence_page() -> None:
"""Test for getting projects on JIRA"""
jira = JiraAPIWrapper()
create_page_dict = (
'{"space": "ROC", "title":"This is the title",'
'"body":"This is the body. You can use '
'<strong>HTML tags</strong>!"}'
)

output = jira.run("create_page", create_page_dict)
assert "type" in output
assert "page" in output

0 comments on commit cc33bde

Please sign in to comment.