Spaces:
Sleeping
Sleeping
Update functions.py
Browse files- functions.py +41 -10
functions.py
CHANGED
@@ -15,7 +15,8 @@ from streamlit import secrets
|
|
15 |
# Constants
|
16 |
GITHUB_API = "https://api.github.com"
|
17 |
# No default TOKEN assignment here, we will handle it dynamically
|
18 |
-
|
|
|
19 |
# Function to update headers with a new token
|
20 |
def get_headers(updated_token=None):
|
21 |
# Use the provided token or fallback to the existing secret token
|
@@ -78,16 +79,16 @@ def extract_commit_summary(commit_data):
|
|
78 |
'message': commit_details.get('message', ''),
|
79 |
'author': author_info.get('name', ''),
|
80 |
'date': author_info.get('date', ''), # Include commit date
|
81 |
-
'file_patches': [
|
82 |
-
{'filename': file.get('filename', ''), 'patch': file.get('patch', '')}
|
83 |
-
for file in files_info if 'patch' in file
|
84 |
-
],
|
85 |
-
'stats': {
|
86 |
-
'additions': commit_details.get('stats', {}).get('additions', 0),
|
87 |
-
'deletions': commit_details.get('stats', {}).get('deletions', 0),
|
88 |
-
'total': commit_details.get('stats', {}).get('total', 0)
|
89 |
-
}
|
90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
return commit_summary
|
93 |
|
@@ -166,3 +167,33 @@ def get_contributor_commits(repo_name, contributor, period,branches, updated_tok
|
|
166 |
summarized_commits = [extract_commit_summary(commit) for commit in all_commits]
|
167 |
return summarized_commits
|
168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# Constants
|
16 |
GITHUB_API = "https://api.github.com"
|
17 |
# No default TOKEN assignment here, we will handle it dynamically
|
18 |
+
# Replace with your actual OpenAI API key
|
19 |
+
openai.api_key = secrets['GITHUB_API_TOKEN']
|
20 |
# Function to update headers with a new token
|
21 |
def get_headers(updated_token=None):
|
22 |
# Use the provided token or fallback to the existing secret token
|
|
|
79 |
'message': commit_details.get('message', ''),
|
80 |
'author': author_info.get('name', ''),
|
81 |
'date': author_info.get('date', ''), # Include commit date
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
+
# 'file_patches': [
|
84 |
+
# {'filename': file.get('filename', ''), 'patch': file.get('patch', '')}
|
85 |
+
# for file in files_info if 'patch' in file
|
86 |
+
# ],
|
87 |
+
# 'stats': {
|
88 |
+
# 'additions': commit_details.get('stats', {}).get('additions', 0),
|
89 |
+
# 'deletions': commit_details.get('stats', {}).get('deletions', 0),
|
90 |
+
# 'total': commit_details.get('stats', {}).get('total', 0)
|
91 |
+
# }
|
92 |
|
93 |
return commit_summary
|
94 |
|
|
|
167 |
summarized_commits = [extract_commit_summary(commit) for commit in all_commits]
|
168 |
return summarized_commits
|
169 |
|
170 |
+
def chat_complete(message, model="gpt-3.5-turbo"):
|
171 |
+
response = openai.ChatCompletion.create(
|
172 |
+
model=model,
|
173 |
+
messages=[
|
174 |
+
{"role": "user", "content": str(message)}
|
175 |
+
]
|
176 |
+
)
|
177 |
+
return response
|
178 |
+
|
179 |
+
def openai_get_AI_summary(commit_info):
|
180 |
+
prompt_prefix = "Summarize this git commit given the following context in JSON:\n"
|
181 |
+
prompt_suffix = "\n---\nPut the summary in the following JSON schema: {...}"
|
182 |
+
|
183 |
+
# Construct the message with commit_info
|
184 |
+
message = prompt_prefix + json.dumps(commit_info, indent=2) + prompt_suffix
|
185 |
+
|
186 |
+
# Fetch the summary from OpenAI
|
187 |
+
response = chat_complete(message)
|
188 |
+
return response.choices[0].message['content'] if response.choices else "No summary available"
|
189 |
+
|
190 |
+
def process_commits_with_openai_summaries(commits):
|
191 |
+
summaries = []
|
192 |
+
|
193 |
+
for commit in tqdm(commits, desc='Generating AI summaries'):
|
194 |
+
# Assuming each commit includes 'commit_files_stats' with detailed info
|
195 |
+
summary = openai_get_AI_summary(str(commit))
|
196 |
+
# commit['ai_summary'] = summary
|
197 |
+
summaries.append(summary)
|
198 |
+
|
199 |
+
return summaries
|