import streamlit as st
from SearchManager import perform_search, parse_results
def generate_prompt(user_message: str) -> str:
if "debug" in st.session_state:
system_content = """\
You are a code-review assistant. You ALWAYS respond with valid JSON and
nothing else — no markdown code fences, no introductory text, no trailing
commentary. Your entire response must be parseable by json.loads().
"""
task = f"""\
{user_message} Follow the schema
{{
"summary": "",
"bugs": [
{{
"id": 1,
"severity": "Critical|Medium|Style",
"line": ,
"function": "",
"description": "",
"fix": ""
}}
],
"overall_quality": "Poor|Fair|Good|Excellent"
}}
"""
context = (f" {st.session_state['file_content']} ")
if "code_error" in st.session_state:
context += (f" {st.session_state['code_error']} ")
prompt = system_content + task + context
#st.session_state["last_prompt"] = (f"{prompt}")
return prompt
else:
system_content = """\
You are an experienced Python coding assistant.
Keep each answer under 200 words.
"""
task = (f" {user_message} ")
context = ""
if "internet" in st.session_state:
context += (f" {parse_results(perform_search(user_message))} ")
if "file_content" in st.session_state:
context += (f" {st.session_state['file_content']} ")
if "code_error" in st.session_state:
context += (f" {st.session_state['code_error']} ")
prompt = system_content + task + context
#st.session_state["last_prompt"] = (f"{prompt}")
return prompt