65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
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 respond with a list of bugs and how to fix them.
|
|
"""
|
|
task = f"""\
|
|
<task> {user_message} </task>
|
|
<schema>
|
|
summary: "<one-sentence overview of the code quality>",
|
|
for each bug:
|
|
"severity": "Critical|Medium|Style",
|
|
"function": "<name of the affected function>",
|
|
"description": "<what is wrong and why it matters>",
|
|
"fix": "<one-sentence fix hint>"
|
|
overall_quality: "Poor|Fair|Good|Excellent
|
|
</schema>"
|
|
"""
|
|
|
|
context = (f" <code> {st.session_state['file_content']} </code>")
|
|
if "code_error" in st.session_state:
|
|
context += (f" <error> {st.session_state['code_error']} </error>")
|
|
|
|
prompt = system_content + task + context
|
|
#st.session_state["last_prompt"] = (f"{prompt}")
|
|
return prompt
|
|
|
|
else:
|
|
system_content = """\
|
|
<persona>
|
|
You are an experienced Python coding assistant.
|
|
</persona>
|
|
<style>
|
|
Write python in PEP8 style. Keep explanaitions short.
|
|
</style>
|
|
<constraints>
|
|
Keep each answer under 200 words.
|
|
</constraints>
|
|
"""
|
|
|
|
task = (f"<task> {user_message} </task>")
|
|
|
|
context = ""
|
|
|
|
if "internet" in st.session_state:
|
|
context += (f"<internet_info> {parse_results(perform_search(user_message))} </internet_info>")
|
|
|
|
if "file_content" in st.session_state:
|
|
context += (f" <code> {st.session_state['file_content']} </code>")
|
|
|
|
if "code_error" in st.session_state:
|
|
context += (f" <error> {st.session_state['code_error']} </error>")
|
|
|
|
prompt = system_content + task + context
|
|
|
|
#st.session_state["last_prompt"] = (f"{prompt}")
|
|
|
|
return prompt
|
|
|
|
|