FiendHunter
commited on
Commit
•
9482221
1
Parent(s):
eddd638
Delete code_4.py
Browse files
code_4.py
DELETED
@@ -1,135 +0,0 @@
|
|
1 |
-
import openai
|
2 |
-
import csv
|
3 |
-
import os
|
4 |
-
import time
|
5 |
-
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
|
6 |
-
csv.field_size_limit(10**9)
|
7 |
-
|
8 |
-
API_BASE_URL = "https://llama.us.gaianet.network/v1"
|
9 |
-
MODEL_NAME = "llama"
|
10 |
-
API_KEY = "GAIA"
|
11 |
-
|
12 |
-
def create_retry_decorator():
|
13 |
-
return retry(
|
14 |
-
retry=retry_if_exception_type((openai.APIError, openai.APITimeoutError)),
|
15 |
-
stop=stop_after_attempt(3),
|
16 |
-
wait=wait_exponential(multiplier=1, min=4, max=10),
|
17 |
-
before_sleep=lambda retry_state: print(f"Retry attempt {retry_state.attempt_number} after {retry_state.outcome.exception()}")
|
18 |
-
)
|
19 |
-
|
20 |
-
@create_retry_decorator()
|
21 |
-
def make_api_call(client, messages, model):
|
22 |
-
return client.chat.completions.create(
|
23 |
-
messages=messages,
|
24 |
-
model=model,
|
25 |
-
stream=False,
|
26 |
-
)
|
27 |
-
|
28 |
-
def summarize(source_text):
|
29 |
-
client = openai.OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
30 |
-
messages = [
|
31 |
-
{
|
32 |
-
"role": "system",
|
33 |
-
"content": """
|
34 |
-
You are an AI assistant designed to review pull requests (PRs) in GitHub repositories. Your task is to:
|
35 |
-
|
36 |
-
1. Summarize Code-related Files:
|
37 |
-
- Focus on key changes in the code, including additions, deletions, and modifications.
|
38 |
-
- Capture essential details such as the purpose of the code, any new functions, classes, or methods, and the overall impact of these changes on the project.
|
39 |
-
- Highlight any dependencies, error handling, or performance implications.
|
40 |
-
|
41 |
-
2. Summarize Markdown Files:
|
42 |
-
- Extract key points from documentation, readme files, and other markdown content.
|
43 |
-
- Identify sections related to project setup, usage instructions, change logs, or contributor guidelines.
|
44 |
-
- Note updates in the documentation and the implications for users or developers.
|
45 |
-
""",
|
46 |
-
},
|
47 |
-
{
|
48 |
-
"role": "user",
|
49 |
-
"content": source_text,
|
50 |
-
}
|
51 |
-
]
|
52 |
-
chat_completion = make_api_call(client, messages, MODEL_NAME)
|
53 |
-
return chat_completion.choices[0].message.content
|
54 |
-
|
55 |
-
def qgen(source_text):
|
56 |
-
client = openai.OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
57 |
-
messages = [
|
58 |
-
{
|
59 |
-
"role": "system",
|
60 |
-
"content": "Respond with a list of 10 questions. The text in the user message must contain specific answers to each question. Each question must be on its own line. Just list the questions without any introductory text or numbers.",
|
61 |
-
},
|
62 |
-
{
|
63 |
-
"role": "user",
|
64 |
-
"content": source_text,
|
65 |
-
}
|
66 |
-
]
|
67 |
-
chat_completion = make_api_call(client, messages, MODEL_NAME)
|
68 |
-
return chat_completion.choices[0].message.content
|
69 |
-
|
70 |
-
def agen(source_text, question):
|
71 |
-
client = openai.OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
72 |
-
messages = [
|
73 |
-
{
|
74 |
-
"role": "system",
|
75 |
-
"content": "Give a comprehensive and well-reasoned answer to the user question strictly based on the context below and try to give a detailed explanation while answering the questions. Also try to add some bonus tip to in each answer and some relevant example outside of the content.\n" + source_text
|
76 |
-
},
|
77 |
-
{
|
78 |
-
"role": "user",
|
79 |
-
"content": question,
|
80 |
-
}
|
81 |
-
]
|
82 |
-
chat_completion = make_api_call(client, messages, MODEL_NAME)
|
83 |
-
return chat_completion.choices[0].message.content
|
84 |
-
|
85 |
-
def main():
|
86 |
-
input_path = r"C:\Users\91745\OneDrive\Desktop\Github_analyser\output\local_repo\docs\quick_js_js.csv"
|
87 |
-
output_path = r"C:\Users\91745\OneDrive\Desktop\Github_analyser\output\local_repo\summary\quick_js_js.csv"
|
88 |
-
processed_contents = set()
|
89 |
-
output_file_exists = os.path.exists(output_path)
|
90 |
-
|
91 |
-
row_count = 0
|
92 |
-
|
93 |
-
with open(input_path, 'r', newline='', encoding='utf-8') as infile, \
|
94 |
-
open(output_path, 'a', newline='', encoding='utf-8') as outfile:
|
95 |
-
|
96 |
-
csv_reader = csv.reader(infile)
|
97 |
-
csv_writer = csv.writer(outfile)
|
98 |
-
|
99 |
-
if not output_file_exists:
|
100 |
-
pass
|
101 |
-
|
102 |
-
for row in csv_reader:
|
103 |
-
try:
|
104 |
-
main_content = row[0]
|
105 |
-
|
106 |
-
if main_content in processed_contents:
|
107 |
-
continue
|
108 |
-
|
109 |
-
summary = summarize(main_content)
|
110 |
-
qs = qgen(main_content)
|
111 |
-
qna_list = []
|
112 |
-
for q in qs.splitlines():
|
113 |
-
if len(q.strip()) == 0:
|
114 |
-
continue
|
115 |
-
answer = agen(main_content, q)
|
116 |
-
qna_list.append(f"Q: {q}\nA: {answer}")
|
117 |
-
|
118 |
-
csv_writer.writerow([main_content, f"Summary:\n{summary}"])
|
119 |
-
for qna in qna_list:
|
120 |
-
csv_writer.writerow([main_content, qna])
|
121 |
-
|
122 |
-
processed_contents.add(main_content)
|
123 |
-
|
124 |
-
row_count += 1
|
125 |
-
print(f"Processed row {row_count}")
|
126 |
-
|
127 |
-
except Exception as e:
|
128 |
-
print(f"Error processing row {row_count + 1}: {str(e)}")
|
129 |
-
continue
|
130 |
-
|
131 |
-
print(f"Modified data has been written to {output_path}")
|
132 |
-
print(f"Total rows summarized: {row_count}")
|
133 |
-
|
134 |
-
if __name__ == "__main__":
|
135 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|