File size: 4,711 Bytes
cfd3735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "245a954a",
   "metadata": {},
   "source": [
    "# Jira\n",
    "\n",
    "This notebook goes over how to use the Jira tool.\n",
    "The Jira tool allows agents to interact with a given Jira instance, performing actions such as searching for issues and creating issues, the tool wraps the atlassian-python-api library, for more see: https://atlassian-python-api.readthedocs.io/jira.html\n",
    "\n",
    "To use this tool, you must first set as environment variables:\n",
    "    JIRA_API_TOKEN\n",
    "    JIRA_USERNAME\n",
    "    JIRA_INSTANCE_URL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "961b3689",
   "metadata": {
    "vscode": {
     "languageId": "shellscript"
    },
    "ExecuteTime": {
     "start_time": "2023-04-17T10:21:18.698672Z",
     "end_time": "2023-04-17T10:21:20.168639Z"
    }
   },
   "outputs": [],
   "source": [
    "%pip install atlassian-python-api"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "34bb5968",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-04-17T10:21:22.911233Z",
     "end_time": "2023-04-17T10:21:23.730922Z"
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "from langchain.agents import AgentType\n",
    "from langchain.agents import initialize_agent\n",
    "from langchain.agents.agent_toolkits.jira.toolkit import JiraToolkit\n",
    "from langchain.llms import OpenAI\n",
    "from langchain.utilities.jira import JiraAPIWrapper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "os.environ[\"JIRA_API_TOKEN\"] = \"abc\"\n",
    "os.environ[\"JIRA_USERNAME\"] = \"123\"\n",
    "os.environ[\"JIRA_INSTANCE_URL\"] = \"https://jira.atlassian.com\"\n",
    "os.environ[\"OPENAI_API_KEY\"] = \"xyz\""
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-17T10:22:42.499447Z",
     "end_time": "2023-04-17T10:22:42.505412Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ac4910f8",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-04-17T10:22:44.664481Z",
     "end_time": "2023-04-17T10:22:44.720538Z"
    }
   },
   "outputs": [],
   "source": [
    "llm = OpenAI(temperature=0)\n",
    "jira = JiraAPIWrapper()\n",
    "toolkit = JiraToolkit.from_jira_api_wrapper(jira)\n",
    "agent = initialize_agent(\n",
    "    toolkit.get_tools(),\n",
    "    llm,\n",
    "    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,\n",
    "    verbose=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
      "\u001B[32;1m\u001B[1;3m I need to create an issue in project PW\n",
      "Action: Create Issue\n",
      "Action Input: {\"summary\": \"Make more fried rice\", \"description\": \"Reminder to make more fried rice\", \"issuetype\": {\"name\": \"Task\"}, \"priority\": {\"name\": \"Low\"}, \"project\": {\"key\": \"PW\"}}\u001B[0m\n",
      "Observation: \u001B[38;5;200m\u001B[1;3mNone\u001B[0m\n",
      "Thought:\u001B[32;1m\u001B[1;3m I now know the final answer\n",
      "Final Answer: A new issue has been created in project PW with the summary \"Make more fried rice\" and description \"Reminder to make more fried rice\".\u001B[0m\n",
      "\n",
      "\u001B[1m> Finished chain.\u001B[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": "'A new issue has been created in project PW with the summary \"Make more fried rice\" and description \"Reminder to make more fried rice\".'"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "agent.run(\"make a new issue in project PW to remind me to make more fried rice\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-17T10:23:33.662454Z",
     "end_time": "2023-04-17T10:23:38.121883Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "vscode": {
   "interpreter": {
    "hash": "53f3bc57609c7a84333bb558594977aa5b4026b1d6070b93987956689e367341"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}