mirror of
https://github.com/hwchase17/langchain
synced 2024-11-11 19:11:02 +00:00
25fbe356b4
This PR upgrades community to a recent version of mypy. It inserts type: ignore on all existing failures.
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
from typing import Dict, List
|
|
|
|
from langchain_core.tools import BaseToolkit
|
|
|
|
from langchain_community.tools import BaseTool
|
|
from langchain_community.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,
|
|
)
|
|
from langchain_community.tools.jira.tool import JiraAction
|
|
from langchain_community.utilities.jira import JiraAPIWrapper
|
|
|
|
|
|
class JiraToolkit(BaseToolkit):
|
|
"""Jira Toolkit.
|
|
|
|
*Security Note*: This toolkit contains tools that can read and modify
|
|
the state of a service; e.g., by creating, deleting, or updating,
|
|
reading underlying data.
|
|
|
|
See https://python.langchain.com/docs/security for more information.
|
|
"""
|
|
|
|
tools: List[BaseTool] = []
|
|
|
|
@classmethod
|
|
def from_jira_api_wrapper(cls, jira_api_wrapper: JiraAPIWrapper) -> "JiraToolkit":
|
|
operations: List[Dict] = [
|
|
{
|
|
"mode": "jql",
|
|
"name": "JQL Query",
|
|
"description": JIRA_JQL_PROMPT,
|
|
},
|
|
{
|
|
"mode": "get_projects",
|
|
"name": "Get Projects",
|
|
"description": JIRA_GET_ALL_PROJECTS_PROMPT,
|
|
},
|
|
{
|
|
"mode": "create_issue",
|
|
"name": "Create Issue",
|
|
"description": JIRA_ISSUE_CREATE_PROMPT,
|
|
},
|
|
{
|
|
"mode": "other",
|
|
"name": "Catch all Jira API call",
|
|
"description": JIRA_CATCH_ALL_PROMPT,
|
|
},
|
|
{
|
|
"mode": "create_page",
|
|
"name": "Create confluence page",
|
|
"description": JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
|
|
},
|
|
]
|
|
tools = [
|
|
JiraAction(
|
|
name=action["name"],
|
|
description=action["description"],
|
|
mode=action["mode"],
|
|
api_wrapper=jira_api_wrapper,
|
|
)
|
|
for action in operations
|
|
]
|
|
return cls(tools=tools) # type: ignore[arg-type]
|
|
|
|
def get_tools(self) -> List[BaseTool]:
|
|
"""Get the tools in the toolkit."""
|
|
return self.tools
|