-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
79 lines (68 loc) · 2.9 KB
/
app.py
File metadata and controls
79 lines (68 loc) · 2.9 KB
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
# Imports
from Document_Loading import *
from flask import Flask, render_template, request
import validators
import sys
# Initialize flask app
app = Flask(__name__)
QA_dict = dict()
@app.route('/', methods=['GET', 'POST'])
def index():
valid_url = ''
if request.method == 'POST':
url = request.form['repo']
if validators.url(url):
valid_url = True
else:
valid_url = False
render_template('index.html', valid_url=valid_url)
# If the url provided by the user is valid then only proceed further
if valid_url:
db_store_retrieve(url)
repositories = get_repository_links(url)
print(QA_dict)
final_retirever = create_questions_db(QA_dict)
final_questions = [
# "Which repositories are we discussing about?",
# "Tell me a brief summary of each repository",
"Compare the complexities of the repositories in the context and say which is the most technically "
"complex repository for an entry level junior developer fresh out of college? Mention the repository name"
]
final_answers = ask_gpt(final_retirever, final_questions)
print("Conclusion:")
print(final_answers[-1][-1])
return render_template('index.html', valid_url=True, results=True,
repositories=repositories, most_complex_repo=final_answers[-1][-1])
return render_template('index.html', valid_url=valid_url)
def db_store_retrieve(url: str):
"""
This function creates vector store databases for the repositories available in the url. Then it prompts the GPT with
questions and stores the questions and responses by the GPT which will be further used by another GPT model to
compare code complexity.
Parameters
----------
url: str
The github profile URL
Returns
-------
None
"""
repositories = sorted(get_repository_links(url + "?tab=repositories"))
print(f"Found {len(repositories)} repositories")
if len(repositories) > 0:
embeddings = OpenAIEmbeddings(disallowed_special=())
for repo_url in repositories:
_, repository_name = parse_github_url(repo_url)
repo_retriever = create_repo_db(repo_url, embeddings)
repo_questions = [
f"The code snippets in your context are from a single repository called {repository_name}. How "
f"difficult or technically complex are the code snippets in the context, for an entry level junior "
f"developer?"
]
chats = ask_gpt(repo_retriever, repo_questions)
print("Conversation")
print(chats)
QA_dict[repository_name] = chats
if __name__ == "__main__":
sys.executable = sys.executable.replace('\\App', '\\..\\..\\App')
app.run(debug=True)