Anustup commited on
Commit
0ba81ce
·
verified ·
1 Parent(s): 39e64d7

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +70 -0
  2. chat_ai.py +102 -0
  3. constants.py +55 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+
4
+ from chat_ai import generate_response_for_pre_indexed_repo, generate_response_for_custom_repo
5
+
6
+ st.set_page_config(page_title="Tune AI Git Issue Chat")
7
+
8
+ if 'clicked' not in st.session_state:
9
+ st.session_state.clicked = False
10
+
11
+
12
+ def click_button():
13
+ st.session_state.clicked = True
14
+
15
+
16
+ with st.sidebar:
17
+ option = st.selectbox(
18
+ 'What repo you are looking for?',
19
+ ('Pre-Indexed', 'Custom'),
20
+ index=None,
21
+ placeholder="please choose an option"
22
+ )
23
+ if option == 'Pre-Indexed':
24
+ option_of_repo = st.selectbox(
25
+ 'Choose any one of the pre-index repo',
26
+ ('Tensorflow', 'Pytorch'),
27
+ index=None,
28
+ placeholder="please choose an option"
29
+ )
30
+ st.write("Select number of top issues you are looking for!")
31
+ number_of_issues = st.number_input('Insert a number')
32
+ elif option == 'Custom':
33
+ repo_link = st.text_area("Please enter your public repo link!")
34
+ st.write("Select number of top issues you are looking for!")
35
+ number_of_issues = st.number_input('Insert a number')
36
+
37
+ st.button("Ask Tune AI!", on_click=click_button)
38
+
39
+ if st.session_state.clicked:
40
+ with st.spinner("Generating, It may take some minutes🫡..."):
41
+ if option == 'Pre-Indexed' and number_of_issues:
42
+ if option_of_repo == "Tensorflow":
43
+ repo_choice = "Tensorflow"
44
+ elif option_of_repo == "Pytorch":
45
+ repo_choice = "Pytorch"
46
+ gpt_response = generate_response_for_pre_indexed_repo(repo_choice, number_of_issues)
47
+ if gpt_response["success"]:
48
+ try:
49
+ json_data = json.loads(gpt_response["data"])
50
+ for issue in json_data['issues']:
51
+ st.markdown(f"**{issue['issue_title']}**", unsafe_allow_html=True)
52
+ st.write("Rating:", issue['rating']['type'])
53
+ st.write("Description:", issue['rating']['description'])
54
+ except:
55
+ st.json(gpt_response["data"])
56
+ else:
57
+ st.write("Sorry we encountered some issues!")
58
+ elif option == 'Custom' and number_of_issues and repo_link:
59
+ gpt_response = generate_response_for_custom_repo(number_of_issues, repo_link)
60
+ if gpt_response["success"]:
61
+ try:
62
+ json_data = json.loads(gpt_response["data"])
63
+ for issue in json_data['issues']:
64
+ st.markdown(f"**{issue['issue_title']}**", unsafe_allow_html=True)
65
+ st.write("Rating:", issue['rating']['type'])
66
+ st.write("Description:", issue['rating']['description'])
67
+ except:
68
+ st.json(gpt_response["data"])
69
+ else:
70
+ st.write("Sorry we encountered some issues!")
chat_ai.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import pandas as pd
4
+ from constants import JSON_SCHEMA_FOR_GPT, REPO_NAME_EXTRACTION_PATTERN
5
+ from utils import create_open_ai_query, get_issues_csv, convert_repo_url_to_git_api_url
6
+
7
+
8
+ def generate_response_for_pre_indexed_repo(repo_choice, number_of_issues):
9
+ if repo_choice == "Tensorflow":
10
+ csv_key = "tf.csv"
11
+ repo_name = "Tensorflow"
12
+ else:
13
+ csv_key = "torch.csv"
14
+ repo_name = "Pytorch"
15
+ issues_df = pd.read_csv(csv_key)
16
+ context_of_issues = ""
17
+ for i, row in issues_df.iterrows():
18
+ issue_title = row["Issue Title"]
19
+ issue_description = row["Description"]
20
+ issue_creation_date = row["Created At"]
21
+ issue_comments = row["Comments"]
22
+
23
+ formulated_issue = f"""
24
+ Issue_title : {issue_title},
25
+ Issue_description : {issue_description},
26
+ Issue_creation_date: {issue_creation_date},
27
+ Issue_comments: {issue_comments}
28
+
29
+ """
30
+ context_of_issues += formulated_issue
31
+ schema_context = f"""Output JSON format : {JSON_SCHEMA_FOR_GPT}"""
32
+ additional_prompt = f"""You have to provide top {number_of_issues}"""
33
+ prompt = f"""Act as a Software Developer, you are provided with Github Issues details: {context_of_issues} for
34
+ github repo of {repo_name}. User has asked you to list top {number_of_issues} issues for this repository.
35
+ Let's break down your task of listing top issues step by step:
36
+ 1. First take time to think and understand the github repo.
37
+ 2. Take time to think and understand the Github Issues details provided. Understand the title, description,
38
+ number of comments.
39
+ 3. Try to understand what impact each issue will have on the repository if it is resolved.
40
+ 4. Understand why the issues which are highly commented with aspect of its impact on github repo
41
+ 5. calculate rating for issues and select top {number_of_issues} issues.
42
+ 5. Finally provide a JSON response which will have selected top {number_of_issues} issues.
43
+ Follow the mentioned format for the JSON.
44
+ """
45
+ final_prompt = (schema_context + additional_prompt + prompt)
46
+ response = create_open_ai_query(final_prompt)
47
+ if response["success"]:
48
+ return {"success": True, "data": response["data"]}
49
+ else:
50
+ return {"success": False, "error": response}
51
+
52
+
53
+ def generate_response_for_custom_repo(number_of_issues, repo_url):
54
+ converted_url = convert_repo_url_to_git_api_url(repo_url)
55
+ print(converted_url)
56
+ match = re.match(REPO_NAME_EXTRACTION_PATTERN, repo_url)
57
+ print(match)
58
+ if match:
59
+ repo_name = match.group(2)
60
+ csv_file_name = f"{repo_name}.csv"
61
+ else:
62
+ repo_name = repo_url
63
+ csv_file_name = "test.csv"
64
+ issues_csv = get_issues_csv(converted_url, csv_file_name)
65
+ if issues_csv["success"]:
66
+ issues_df = pd.read_csv(csv_file_name)
67
+ context_of_issues = ""
68
+ for i, row in issues_df.iterrows():
69
+ issue_title = row["Issue Title"]
70
+ issue_description = row["Description"]
71
+ issue_creation_date = row["Created At"]
72
+ issue_comments = row["Comments"]
73
+ formulated_issue = f"""
74
+ Issue_title : {issue_title},
75
+ Issue_description : {issue_description},
76
+ Issue_creation_date: {issue_creation_date},
77
+ Issue_comments: {issue_comments}
78
+ """
79
+ context_of_issues += formulated_issue
80
+ schema_context = f"""Output JSON format : {JSON_SCHEMA_FOR_GPT}"""
81
+ additional_prompt = f"""You have to provide top {number_of_issues}"""
82
+ prompt = f"""Act as a Software Developer, you are provided with Github Issues details: {context_of_issues} for
83
+ github repo of {repo_name}. User has asked you to list top {number_of_issues} issues for this repository.
84
+ Let's break down your task of listing top issues step by step:
85
+ 1. First take time to think and understand the github repo.
86
+ 2. Take time to think and understand the Github Issues details provided. Understand the title, description,
87
+ number of comments.
88
+ 3. Try to understand what impact each issue will have on the repository if it is resolved.
89
+ 4. Understand why the issues which are highly commented with aspect of its impact on github repo
90
+ 5. calculate rating for issues and select top {number_of_issues} issues.
91
+ 5. Finally provide a JSON response which will have selected top {number_of_issues} issues.
92
+ Follow the mentioned format for the JSON.
93
+ """
94
+ final_prompt = (schema_context + additional_prompt + prompt)
95
+ response = create_open_ai_query(final_prompt)
96
+ os.remove(csv_file_name)
97
+ if response["success"]:
98
+ return {"success": True, "data": response["data"]}
99
+ else:
100
+ return {"success": False, "error": response}
101
+ else:
102
+ return {"success": False}
constants.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ # OPENAI
4
+
5
+ OPENAI_API_BASE_URL = "https://api.openai.com/v1"
6
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
7
+ TEXT_MODEL_ENGINE = 'gpt-4-0125-preview'
8
+
9
+ # GITHUB
10
+ GITHUB_AUTH_KEY = os.getenv("GITHUB_AUTH_KEY")
11
+
12
+ # REGEX
13
+ REPO_NAME_EXTRACTION_PATTERN = r"https://github.com/([^/]+)/([^/]+)$"
14
+
15
+ # SCHEMA
16
+ JSON_SCHEMA_FOR_GPT = {
17
+ "type": "object",
18
+ "properties": {
19
+ "issues": {
20
+ "type": "array",
21
+ "items": [
22
+ {
23
+ "type": "object",
24
+ "properties": {
25
+ "issue_title": {
26
+ "type": "string"
27
+ },
28
+ "rating": {
29
+ "type": "object",
30
+ "properties": {
31
+ "type": {
32
+ "type": "string"
33
+ },
34
+ "description": {
35
+ "type": "string"
36
+ }
37
+ },
38
+ "required": [
39
+ "type",
40
+ "description"
41
+ ]
42
+ }
43
+ },
44
+ "required": [
45
+ "issue_title",
46
+ "rating"
47
+ ]
48
+ }
49
+ ]
50
+ }
51
+ },
52
+ "required": [
53
+ "issues"
54
+ ]
55
+ }