Spaces:
Sleeping
Sleeping
openai4
Browse files- analyzer.py +10 -11
- app.py +2 -2
- chatbot_page.py +4 -4
- repo_explorer.py +2 -2
analyzer.py
CHANGED
@@ -15,7 +15,7 @@ def analyze_code(code: str) -> str:
|
|
15 |
Returns the analysis as a string.
|
16 |
"""
|
17 |
from openai import OpenAI
|
18 |
-
client = OpenAI(api_key=os.getenv("
|
19 |
client.base_url = os.getenv("base_url")
|
20 |
system_prompt = (
|
21 |
"You are a highly precise and strict JSON generator. Analyze the code given to you. "
|
@@ -27,7 +27,7 @@ def analyze_code(code: str) -> str:
|
|
27 |
"{\n 'strength': '...', \n 'weaknesses': '...', \n 'speciality': '...', \n 'relevance rating': 'high'\n}"
|
28 |
)
|
29 |
response = client.chat.completions.create(
|
30 |
-
model="
|
31 |
messages=[
|
32 |
{"role": "system", "content": system_prompt},
|
33 |
{"role": "user", "content": code}
|
@@ -235,7 +235,7 @@ def analyze_code_chunk(code: str, user_requirements: str = "") -> str:
|
|
235 |
Analyzes a code chunk and returns a JSON summary for that chunk.
|
236 |
"""
|
237 |
from openai import OpenAI
|
238 |
-
client = OpenAI(api_key=os.getenv("
|
239 |
client.base_url = os.getenv("base_url")
|
240 |
|
241 |
# Build the user requirements section
|
@@ -256,12 +256,11 @@ def analyze_code_chunk(code: str, user_requirements: str = "") -> str:
|
|
256 |
)
|
257 |
|
258 |
response = client.chat.completions.create(
|
259 |
-
model="
|
260 |
messages=[
|
261 |
{"role": "system", "content": chunk_prompt},
|
262 |
{"role": "user", "content": code}
|
263 |
],
|
264 |
-
|
265 |
temperature=0.4
|
266 |
)
|
267 |
return response.choices[0].message.content
|
@@ -271,7 +270,7 @@ def aggregate_chunk_analyses(chunk_jsons: list, user_requirements: str = "") ->
|
|
271 |
Aggregates a list of chunk JSONs into a single JSON summary using the LLM.
|
272 |
"""
|
273 |
from openai import OpenAI
|
274 |
-
client = OpenAI(api_key=os.getenv("
|
275 |
client.base_url = os.getenv("base_url")
|
276 |
|
277 |
# Build the user requirements section
|
@@ -292,7 +291,7 @@ def aggregate_chunk_analyses(chunk_jsons: list, user_requirements: str = "") ->
|
|
292 |
)
|
293 |
user_content = "Here are the chunk analyses:\n" + "\n".join(chunk_jsons)
|
294 |
response = client.chat.completions.create(
|
295 |
-
model="
|
296 |
messages=[
|
297 |
{"role": "system", "content": aggregation_prompt},
|
298 |
{"role": "user", "content": user_content}
|
@@ -329,7 +328,7 @@ def analyze_repo_chunk_for_context(chunk: str, repo_id: str) -> str:
|
|
329 |
"""
|
330 |
try:
|
331 |
from openai import OpenAI
|
332 |
-
client = OpenAI(api_key=os.getenv("
|
333 |
client.base_url = os.getenv("base_url")
|
334 |
|
335 |
context_prompt = f"""You are analyzing a chunk of code from the repository '{repo_id}' to create a conversational summary for a chatbot assistant.
|
@@ -349,7 +348,7 @@ Repository chunk:
|
|
349 |
Provide a clear, conversational summary in 2-3 paragraphs:"""
|
350 |
|
351 |
response = client.chat.completions.create(
|
352 |
-
model="
|
353 |
messages=[
|
354 |
{"role": "system", "content": "You are an expert code analyst creating conversational summaries for a repository assistant chatbot."},
|
355 |
{"role": "user", "content": context_prompt}
|
@@ -385,7 +384,7 @@ def create_repo_context_summary(repo_content: str, repo_id: str) -> str:
|
|
385 |
# Create final comprehensive summary
|
386 |
try:
|
387 |
from openai import OpenAI
|
388 |
-
client = OpenAI(api_key=os.getenv("
|
389 |
client.base_url = os.getenv("base_url")
|
390 |
|
391 |
final_prompt = f"""Based on the following section summaries of repository '{repo_id}', create a comprehensive overview that a chatbot can use to answer user questions.
|
@@ -403,7 +402,7 @@ Create a well-structured overview covering:
|
|
403 |
Make this comprehensive but conversational - it will be used by a chatbot to answer user questions about the repository."""
|
404 |
|
405 |
response = client.chat.completions.create(
|
406 |
-
model="
|
407 |
messages=[
|
408 |
{"role": "system", "content": "You are creating a comprehensive repository summary for a chatbot assistant."},
|
409 |
{"role": "user", "content": final_prompt}
|
|
|
15 |
Returns the analysis as a string.
|
16 |
"""
|
17 |
from openai import OpenAI
|
18 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
19 |
client.base_url = os.getenv("base_url")
|
20 |
system_prompt = (
|
21 |
"You are a highly precise and strict JSON generator. Analyze the code given to you. "
|
|
|
27 |
"{\n 'strength': '...', \n 'weaknesses': '...', \n 'speciality': '...', \n 'relevance rating': 'high'\n}"
|
28 |
)
|
29 |
response = client.chat.completions.create(
|
30 |
+
model="openai/gpt-4.1-nano", # Updated to GPT-4.1 Nano model
|
31 |
messages=[
|
32 |
{"role": "system", "content": system_prompt},
|
33 |
{"role": "user", "content": code}
|
|
|
235 |
Analyzes a code chunk and returns a JSON summary for that chunk.
|
236 |
"""
|
237 |
from openai import OpenAI
|
238 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
239 |
client.base_url = os.getenv("base_url")
|
240 |
|
241 |
# Build the user requirements section
|
|
|
256 |
)
|
257 |
|
258 |
response = client.chat.completions.create(
|
259 |
+
model="openai/gpt-4.1-nano",
|
260 |
messages=[
|
261 |
{"role": "system", "content": chunk_prompt},
|
262 |
{"role": "user", "content": code}
|
263 |
],
|
|
|
264 |
temperature=0.4
|
265 |
)
|
266 |
return response.choices[0].message.content
|
|
|
270 |
Aggregates a list of chunk JSONs into a single JSON summary using the LLM.
|
271 |
"""
|
272 |
from openai import OpenAI
|
273 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
274 |
client.base_url = os.getenv("base_url")
|
275 |
|
276 |
# Build the user requirements section
|
|
|
291 |
)
|
292 |
user_content = "Here are the chunk analyses:\n" + "\n".join(chunk_jsons)
|
293 |
response = client.chat.completions.create(
|
294 |
+
model="openai/gpt-4.1-nano",
|
295 |
messages=[
|
296 |
{"role": "system", "content": aggregation_prompt},
|
297 |
{"role": "user", "content": user_content}
|
|
|
328 |
"""
|
329 |
try:
|
330 |
from openai import OpenAI
|
331 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
332 |
client.base_url = os.getenv("base_url")
|
333 |
|
334 |
context_prompt = f"""You are analyzing a chunk of code from the repository '{repo_id}' to create a conversational summary for a chatbot assistant.
|
|
|
348 |
Provide a clear, conversational summary in 2-3 paragraphs:"""
|
349 |
|
350 |
response = client.chat.completions.create(
|
351 |
+
model="openai/gpt-4.1-nano",
|
352 |
messages=[
|
353 |
{"role": "system", "content": "You are an expert code analyst creating conversational summaries for a repository assistant chatbot."},
|
354 |
{"role": "user", "content": context_prompt}
|
|
|
384 |
# Create final comprehensive summary
|
385 |
try:
|
386 |
from openai import OpenAI
|
387 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
388 |
client.base_url = os.getenv("base_url")
|
389 |
|
390 |
final_prompt = f"""Based on the following section summaries of repository '{repo_id}', create a comprehensive overview that a chatbot can use to answer user questions.
|
|
|
402 |
Make this comprehensive but conversational - it will be used by a chatbot to answer user questions about the repository."""
|
403 |
|
404 |
response = client.chat.completions.create(
|
405 |
+
model="openai/gpt-4.1-nano",
|
406 |
messages=[
|
407 |
{"role": "system", "content": "You are creating a comprehensive repository summary for a chatbot assistant."},
|
408 |
{"role": "user", "content": final_prompt}
|
app.py
CHANGED
@@ -124,11 +124,11 @@ Selected repositories:"""
|
|
124 |
|
125 |
try:
|
126 |
from openai import OpenAI
|
127 |
-
client = OpenAI(api_key=os.getenv("
|
128 |
client.base_url = os.getenv("base_url")
|
129 |
|
130 |
response = client.chat.completions.create(
|
131 |
-
model="
|
132 |
messages=[
|
133 |
{"role": "system", "content": "You are an expert at analyzing and ranking repositories based on user requirements. Always return valid JSON."},
|
134 |
{"role": "user", "content": prompt}
|
|
|
124 |
|
125 |
try:
|
126 |
from openai import OpenAI
|
127 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
128 |
client.base_url = os.getenv("base_url")
|
129 |
|
130 |
response = client.chat.completions.create(
|
131 |
+
model="openai/gpt-4.1-nano",
|
132 |
messages=[
|
133 |
{"role": "system", "content": "You are an expert at analyzing and ranking repositories based on user requirements. Always return valid JSON."},
|
134 |
{"role": "user", "content": prompt}
|
chatbot_page.py
CHANGED
@@ -17,7 +17,7 @@ conversation_history = []
|
|
17 |
# Function to handle chat
|
18 |
def chat_with_user(user_message, history):
|
19 |
from openai import OpenAI
|
20 |
-
client = OpenAI(api_key=os.getenv("
|
21 |
client.base_url = os.getenv("base_url")
|
22 |
# Build the message list for the LLM
|
23 |
messages = [
|
@@ -29,7 +29,7 @@ def chat_with_user(user_message, history):
|
|
29 |
messages.append({"role": "assistant", "content": msg[1]})
|
30 |
messages.append({"role": "user", "content": user_message})
|
31 |
response = client.chat.completions.create(
|
32 |
-
model="
|
33 |
messages=messages,
|
34 |
max_tokens=256,
|
35 |
temperature=0.7
|
@@ -40,7 +40,7 @@ def chat_with_user(user_message, history):
|
|
40 |
# Function to end chat and extract keywords
|
41 |
def extract_keywords_from_conversation(history):
|
42 |
from openai import OpenAI
|
43 |
-
client = OpenAI(api_key=os.getenv("
|
44 |
client.base_url = os.getenv("base_url")
|
45 |
# Combine all user and assistant messages into a single string
|
46 |
conversation = "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[1]])
|
@@ -56,7 +56,7 @@ def extract_keywords_from_conversation(history):
|
|
56 |
"Conversation:\n" + conversation + "\n\nExtract about 5 keywords for Hugging Face repo search."
|
57 |
)
|
58 |
response = client.chat.completions.create(
|
59 |
-
model="
|
60 |
messages=[
|
61 |
{"role": "system", "content": system_prompt},
|
62 |
{"role": "user", "content": user_prompt}
|
|
|
17 |
# Function to handle chat
|
18 |
def chat_with_user(user_message, history):
|
19 |
from openai import OpenAI
|
20 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
21 |
client.base_url = os.getenv("base_url")
|
22 |
# Build the message list for the LLM
|
23 |
messages = [
|
|
|
29 |
messages.append({"role": "assistant", "content": msg[1]})
|
30 |
messages.append({"role": "user", "content": user_message})
|
31 |
response = client.chat.completions.create(
|
32 |
+
model="openai/gpt-4.1-nano",
|
33 |
messages=messages,
|
34 |
max_tokens=256,
|
35 |
temperature=0.7
|
|
|
40 |
# Function to end chat and extract keywords
|
41 |
def extract_keywords_from_conversation(history):
|
42 |
from openai import OpenAI
|
43 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
44 |
client.base_url = os.getenv("base_url")
|
45 |
# Combine all user and assistant messages into a single string
|
46 |
conversation = "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[1]])
|
|
|
56 |
"Conversation:\n" + conversation + "\n\nExtract about 5 keywords for Hugging Face repo search."
|
57 |
)
|
58 |
response = client.chat.completions.create(
|
59 |
+
model="openai/gpt-4.1-nano",
|
60 |
messages=[
|
61 |
{"role": "system", "content": system_prompt},
|
62 |
{"role": "user", "content": user_prompt}
|
repo_explorer.py
CHANGED
@@ -275,11 +275,11 @@ Answer the user's question based on your comprehensive knowledge of this reposit
|
|
275 |
|
276 |
try:
|
277 |
from openai import OpenAI
|
278 |
-
client = OpenAI(api_key=os.getenv("
|
279 |
client.base_url = os.getenv("base_url")
|
280 |
|
281 |
response = client.chat.completions.create(
|
282 |
-
model="
|
283 |
messages=[
|
284 |
{"role": "system", "content": repo_system_prompt},
|
285 |
{"role": "user", "content": user_message}
|
|
|
275 |
|
276 |
try:
|
277 |
from openai import OpenAI
|
278 |
+
client = OpenAI(api_key=os.getenv("OpenAI_API"))
|
279 |
client.base_url = os.getenv("base_url")
|
280 |
|
281 |
response = client.chat.completions.create(
|
282 |
+
model="openai/gpt-4.1-nano",
|
283 |
messages=[
|
284 |
{"role": "system", "content": repo_system_prompt},
|
285 |
{"role": "user", "content": user_message}
|