mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
Confluence added (#6432)
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 <ethan.bowen@slalom.com>
This commit is contained in:
parent
2aeb8e7dbc
commit
cc33bde74f
@ -1 +1 @@
|
|||||||
"""Zapier Tool."""
|
"""Jira Tool."""
|
||||||
|
@ -32,3 +32,10 @@ JIRA_CATCH_ALL_PROMPT = """
|
|||||||
self.jira.projects()
|
self.jira.projects()
|
||||||
For more information on the Jira API, refer to https://atlassian-python-api.readthedocs.io/jira.html
|
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>!"}} """
|
||||||
|
@ -5,6 +5,7 @@ from pydantic import BaseModel, Extra, root_validator
|
|||||||
|
|
||||||
from langchain.tools.jira.prompt import (
|
from langchain.tools.jira.prompt import (
|
||||||
JIRA_CATCH_ALL_PROMPT,
|
JIRA_CATCH_ALL_PROMPT,
|
||||||
|
JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
|
||||||
JIRA_GET_ALL_PROJECTS_PROMPT,
|
JIRA_GET_ALL_PROJECTS_PROMPT,
|
||||||
JIRA_ISSUE_CREATE_PROMPT,
|
JIRA_ISSUE_CREATE_PROMPT,
|
||||||
JIRA_JQL_PROMPT,
|
JIRA_JQL_PROMPT,
|
||||||
@ -17,6 +18,7 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
"""Wrapper for Jira API."""
|
"""Wrapper for Jira API."""
|
||||||
|
|
||||||
jira: Any #: :meta private:
|
jira: Any #: :meta private:
|
||||||
|
confluence: Any
|
||||||
jira_username: Optional[str] = None
|
jira_username: Optional[str] = None
|
||||||
jira_api_token: Optional[str] = None
|
jira_api_token: Optional[str] = None
|
||||||
jira_instance_url: Optional[str] = None
|
jira_instance_url: Optional[str] = None
|
||||||
@ -42,6 +44,11 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
"name": "Catch all Jira API call",
|
"name": "Catch all Jira API call",
|
||||||
"description": JIRA_CATCH_ALL_PROMPT,
|
"description": JIRA_CATCH_ALL_PROMPT,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mode": "create_page",
|
||||||
|
"name": "Create confluence page",
|
||||||
|
"description": JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -69,7 +76,7 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
values["jira_instance_url"] = jira_instance_url
|
values["jira_instance_url"] = jira_instance_url
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from atlassian import Jira
|
from atlassian import Confluence, Jira
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"atlassian-python-api is not installed. "
|
"atlassian-python-api is not installed. "
|
||||||
@ -82,7 +89,16 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
password=jira_api_token,
|
password=jira_api_token,
|
||||||
cloud=True,
|
cloud=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
confluence = Confluence(
|
||||||
|
url=jira_instance_url,
|
||||||
|
username=jira_username,
|
||||||
|
password=jira_api_token,
|
||||||
|
cloud=True,
|
||||||
|
)
|
||||||
|
|
||||||
values["jira"] = jira
|
values["jira"] = jira
|
||||||
|
values["confluence"] = confluence
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@ -151,7 +167,7 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
)
|
)
|
||||||
return parsed_projects_str
|
return parsed_projects_str
|
||||||
|
|
||||||
def create(self, query: str) -> str:
|
def issue_create(self, query: str) -> str:
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -161,6 +177,16 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
params = json.loads(query)
|
params = json.loads(query)
|
||||||
return self.jira.issue_create(fields=dict(params))
|
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:
|
def other(self, query: str) -> str:
|
||||||
context = {"self": self}
|
context = {"self": self}
|
||||||
exec(f"result = {query}", context)
|
exec(f"result = {query}", context)
|
||||||
@ -173,8 +199,10 @@ class JiraAPIWrapper(BaseModel):
|
|||||||
elif mode == "get_projects":
|
elif mode == "get_projects":
|
||||||
return self.project()
|
return self.project()
|
||||||
elif mode == "create_issue":
|
elif mode == "create_issue":
|
||||||
return self.create(query)
|
return self.issue_create(query)
|
||||||
elif mode == "other":
|
elif mode == "other":
|
||||||
return self.other(query)
|
return self.other(query)
|
||||||
|
elif mode == "create_page":
|
||||||
|
return self.page_create(query)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Got unexpected mode {mode}")
|
raise ValueError(f"Got unexpected mode {mode}")
|
||||||
|
@ -27,3 +27,17 @@ def test_create_ticket() -> None:
|
|||||||
output = jira.run("create_issue", issue_string)
|
output = jira.run("create_issue", issue_string)
|
||||||
assert "id" in output
|
assert "id" in output
|
||||||
assert "key" 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
|
||||||
|
Loading…
Reference in New Issue
Block a user