Spaces:
Sleeping
Sleeping
chcunks
Browse files- analyzer.py +16 -14
- chatbot_page.py +4 -2
analyzer.py
CHANGED
|
@@ -11,17 +11,12 @@ def analyze_code(code: str) -> str:
|
|
| 11 |
client = OpenAI(api_key=os.getenv("modal_api"))
|
| 12 |
client.base_url = os.getenv("base_url")
|
| 13 |
system_prompt = (
|
| 14 |
-
"You are a
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
"{"
|
| 20 |
-
" 'strength': '...', "
|
| 21 |
-
" 'weaknesses': '...', "
|
| 22 |
-
" 'speciality': '...', "
|
| 23 |
-
" 'relevance rating': '...'"
|
| 24 |
-
"}"
|
| 25 |
)
|
| 26 |
response = client.chat.completions.create(
|
| 27 |
model="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16", # Updated model
|
|
@@ -80,12 +75,19 @@ def combine_repo_files_for_llm(repo_dir="repo_files", output_file="combined_repo
|
|
| 80 |
|
| 81 |
def analyze_combined_file(output_file="combined_repo.txt"):
|
| 82 |
"""
|
| 83 |
-
Reads the combined file
|
|
|
|
| 84 |
"""
|
| 85 |
try:
|
| 86 |
with open(output_file, "r", encoding="utf-8") as f:
|
| 87 |
lines = f.readlines()
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
return f"Error analyzing combined file: {e}"
|
|
|
|
| 11 |
client = OpenAI(api_key=os.getenv("modal_api"))
|
| 12 |
client.base_url = os.getenv("base_url")
|
| 13 |
system_prompt = (
|
| 14 |
+
"You are a highly precise and strict JSON generator. Analyze the code given to you. "
|
| 15 |
+
"Your ONLY output must be a valid JSON object with the following keys: 'strength', 'weaknesses', 'speciality', 'relevance rating'. "
|
| 16 |
+
"Do NOT include any explanation, markdown, or text outside the JSON. Do NOT add any commentary, preamble, or postscript. "
|
| 17 |
+
"If you cannot answer, still return a valid JSON with empty strings for each key. "
|
| 18 |
+
"Example of the ONLY valid output:\n"
|
| 19 |
+
"{\n 'strength': '...', \n 'weaknesses': '...', \n 'speciality': '...', \n 'relevance rating': '...'\n}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
)
|
| 21 |
response = client.chat.completions.create(
|
| 22 |
model="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16", # Updated model
|
|
|
|
| 75 |
|
| 76 |
def analyze_combined_file(output_file="combined_repo.txt"):
|
| 77 |
"""
|
| 78 |
+
Reads the combined file, splits it into 500-line chunks, analyzes each chunk, and aggregates the LLM's output.
|
| 79 |
+
Returns the aggregated analysis as a string.
|
| 80 |
"""
|
| 81 |
try:
|
| 82 |
with open(output_file, "r", encoding="utf-8") as f:
|
| 83 |
lines = f.readlines()
|
| 84 |
+
chunk_size = 500
|
| 85 |
+
analyses = []
|
| 86 |
+
for i in range(0, len(lines), chunk_size):
|
| 87 |
+
chunk = "".join(lines[i:i+chunk_size])
|
| 88 |
+
analysis = analyze_code(chunk)
|
| 89 |
+
analyses.append(analysis)
|
| 90 |
+
# Optionally, you could merge the JSONs here, but for now, return all analyses as a list
|
| 91 |
+
return "\n---\n".join(analyses)
|
| 92 |
except Exception as e:
|
| 93 |
return f"Error analyzing combined file: {e}"
|
chatbot_page.py
CHANGED
|
@@ -4,7 +4,7 @@ import os
|
|
| 4 |
|
| 5 |
# System prompt for the chatbot
|
| 6 |
CHATBOT_SYSTEM_PROMPT = (
|
| 7 |
-
"You are a helpful assistant. Your goal is to help the user describe their ideal
|
| 8 |
"Ask questions to clarify what they want, their use case, preferred language, features, etc. "
|
| 9 |
"When the user clicks 'End Chat', analyze the conversation and return about 5 keywords for repo search. "
|
| 10 |
"Return only the keywords as a comma-separated list."
|
|
@@ -69,7 +69,9 @@ def extract_keywords_from_conversation(history):
|
|
| 69 |
with gr.Blocks() as chatbot_demo:
|
| 70 |
gr.Markdown("## Repo Recommendation Chatbot")
|
| 71 |
chatbot = gr.Chatbot()
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
user_input = gr.Textbox(label="Your message", placeholder="Describe your ideal repo or answer the assistant's questions...")
|
| 74 |
send_btn = gr.Button("Send")
|
| 75 |
end_btn = gr.Button("End Chat and Extract Keywords")
|
|
|
|
| 4 |
|
| 5 |
# System prompt for the chatbot
|
| 6 |
CHATBOT_SYSTEM_PROMPT = (
|
| 7 |
+
"You are a helpful assistant. Your goal is to help the user describe their ideal Hugging face repo. "
|
| 8 |
"Ask questions to clarify what they want, their use case, preferred language, features, etc. "
|
| 9 |
"When the user clicks 'End Chat', analyze the conversation and return about 5 keywords for repo search. "
|
| 10 |
"Return only the keywords as a comma-separated list."
|
|
|
|
| 69 |
with gr.Blocks() as chatbot_demo:
|
| 70 |
gr.Markdown("## Repo Recommendation Chatbot")
|
| 71 |
chatbot = gr.Chatbot()
|
| 72 |
+
# Initial assistant message
|
| 73 |
+
initial_message = "Hello! What kind of open-source repo are you looking for? Please describe your ideal repo, use case, preferred language, or any features you want."
|
| 74 |
+
state = gr.State([["", initial_message]]) # Start with assistant message
|
| 75 |
user_input = gr.Textbox(label="Your message", placeholder="Describe your ideal repo or answer the assistant's questions...")
|
| 76 |
send_btn = gr.Button("Send")
|
| 77 |
end_btn = gr.Button("End Chat and Extract Keywords")
|