-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
122 lines (97 loc) · 3.79 KB
/
app.py
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
from flask import Flask, request, jsonify, render_template
import anthropic
import json
import requests
from requests.auth import HTTPBasicAuth
import re
from dotenv import load_dotenv
import os
from threading import Thread
app = Flask(__name__)
load_dotenv()
claude_api_key = os.getenv("CLAUDE_API_KEY")
jira_api_token = os.getenv("JIRA_API_TOKEN")
jira_user = os.getenv("JIRA_USER")
client = anthropic.Anthropic(api_key=claude_api_key)
claude_model = "claude-3-5-sonnet-20240620"
system_prompt = """
You are an assistant that is part of a team of software developers.
You'll be given a bulk of information and you need to extract the relevant information to create a Jira issue describing it.
In your response, the first sentence should always be the title of the issue and the rest of the text should the description.
The 'title' should be a short description of the task.
The 'description' should contain clear information about the all the context you can gather about that task. Feel free to include links and lists here. Make is as short as possible.
Do not include the strings 'title' or 'description' on the response.
"""
jira_url = "https://ridecircuit.atlassian.net/rest/api/2/issue"
jira_auth = HTTPBasicAuth(jira_user, jira_api_token)
jira_headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
def process_issue(issue_text, project_id, issue_id):
message = client.messages.create(
model=claude_model,
max_tokens=1024,
system=system_prompt,
messages=[
{"role": "user", "content": issue_text}
],
)
jissue_dict = {
"title": "[JISSUE]",
"description": ""
}
issue_response = message.content[0].text
issue_title = issue_response.split('\n', 1)[0]
jissue_dict['title'] = "[JISSUE] " + issue_title.strip()
jissue_dict['description'] = issue_response[len(issue_title):].strip()
payload = json.dumps({
"fields": {
"description": jissue_dict['description'],
"project": {
"id": project_id
},
"issuetype": {
"id": issue_id
},
"summary": jissue_dict['title'],
}
})
response = requests.request(
"POST",
jira_url,
data=payload,
headers=jira_headers,
auth=jira_auth
)
return jsonify({"response": response.text}), 200
@app.route('/issue-mobile', methods=['POST'])
def issue_mobile():
text = request.form.get('text', None)
if not text:
return jsonify({"error": "No text provided"}), 400
Thread(target=process_issue, args=(text, "10012", "10002")).start()
return jsonify("Ok, let me see what I can do..."), 200
@app.route('/issue-backend', methods=['POST'])
def issue_backend():
text = request.form.get('text', None)
if not text:
return jsonify({"error": "No text provided"}), 400
Thread(target=process_issue, args=(text, "10013", "10002")).start()
return jsonify("Ok, let me see what I can do..."), 200
@app.route('/issue-infra', methods=['POST'])
def issue_infra():
text = request.form.get('text', None)
if not text:
return jsonify({"error": "No text provided"}), 400
Thread(target=process_issue, args=(text, "10014", "10002")).start()
return jsonify("Ok, let me see what I can do..."), 200
@app.route('/issue-test', methods=['POST'])
def issue_test():
text = request.form.get('text', None)
if not text:
return jsonify({"error": "No text provided"}), 400
Thread(target=process_issue, args=(text, "10002", "10008")).start()
return jsonify("Ok, let me see what I can do..."), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=1024, debug=True)