milestone 3 - SystemPrompter: added a somewhat structured prompt option, app: added a toggle for the different prompt
This commit is contained in:
parent
0fdcd8d547
commit
e4d8dc6123
@ -33,3 +33,4 @@ def send_prompt(prompt: str) -> str:
|
||||
input=prompt)
|
||||
return response.output_text
|
||||
|
||||
|
||||
|
||||
@ -81,9 +81,11 @@ def check_code_safety(code: str) -> str | None:
|
||||
|
||||
BLOCKED_IMPORTS = {
|
||||
# Filesystem access
|
||||
"os", "pathlib", "shutil", "glob", "tempfile", "fileinput",
|
||||
#"os", "pathlib" die beiden wieder reingenommen, da sie in meinen Modulen auftauchen
|
||||
"shutil", "glob", "tempfile", "fileinput",
|
||||
# Process execution
|
||||
"subprocess", "multiprocessing", "threading",
|
||||
#"subprocess" wieder reingenommen, da es in meinem Modul auftaucht
|
||||
"multiprocessing", "threading",
|
||||
# Network access
|
||||
"socket", "http", "urllib", "requests", "ftplib", "smtplib",
|
||||
"xmlrpc", "asyncio",
|
||||
|
||||
@ -2,9 +2,34 @@ import streamlit as st
|
||||
from SearchManager import perform_search, parse_results
|
||||
|
||||
|
||||
def generate_prompt(user_message: str, file_context=None) -> str:
|
||||
# Kontext ist entweder leer oder die angeklickte und geöffnete Datei
|
||||
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.
|
||||
@ -26,14 +51,14 @@ def generate_prompt(user_message: str, file_context=None) -> str:
|
||||
|
||||
if "file_content" in st.session_state:
|
||||
context += (f" <code> {st.session_state['file_content']} </code>")
|
||||
else:
|
||||
context = ""
|
||||
|
||||
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}")
|
||||
#st.session_state["last_prompt"] = (f"{prompt}")
|
||||
|
||||
return prompt
|
||||
|
||||
|
||||
|
||||
13
app.py
13
app.py
@ -5,9 +5,13 @@ from FileManager import list_files, read_file, save_file, open_file
|
||||
from ExecutionEngine import run_code
|
||||
|
||||
|
||||
"Last sent prompt:",
|
||||
if "last_prompt" in st.session_state:
|
||||
st.session_state["last_prompt"]
|
||||
#"Last sent prompt:",
|
||||
#if "last_prompt" in st.session_state:
|
||||
# st.session_state["last_prompt"]
|
||||
#if "file_content" in st.session_state:
|
||||
# st.session_state["file_content"]
|
||||
#type(st.session_state["file_content"])
|
||||
#print(type(st.session_state["file_content"]))
|
||||
|
||||
st.set_page_config(layout="wide")
|
||||
|
||||
@ -32,6 +36,7 @@ with col_editor_output:
|
||||
if st.session_state["selected_file"] != "":
|
||||
st.button("Save", on_click=save_file, args=[st.session_state["selected_file"], st.session_state["file_content"]])
|
||||
st.button("Execute Code", on_click=run_code, args=[st.session_state["selected_file"]])
|
||||
#st.button("Debugging mode", on_click=send_debug_message)
|
||||
|
||||
|
||||
# wenn angezigter Code bearbeitet wird, sollte ExecutionEngine aufgerufen werden, diese soll den Code ausführen und im Outputfenster angezeigt werden mit DebugLogger
|
||||
@ -67,6 +72,8 @@ with col_chat:
|
||||
# Input & Response
|
||||
message = st.chat_input("How can qwen help you?", key="chat")
|
||||
internet = st.toggle("enable internet search", key="internet")
|
||||
if "code_output" in st.session_state or "code_error" in st.session_state:
|
||||
debug = st.toggle("debug with qwen", key="debug")
|
||||
if message:
|
||||
st.session_state.messages.append({"role": "user", "content": message})
|
||||
response = send_message(message)
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
|
||||
|
||||
print("blabliblu")
|
||||
print("Hello World")
|
||||
print("Hello")
|
||||
|
||||
|
||||
11
example_2.py
11
example_2.py
@ -1,11 +0,0 @@
|
||||
from argparse import ArgumentParser
|
||||
from time import sleep
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("time", type=int)
|
||||
args = parser.parse_args()
|
||||
print(f"Starting timer of {args.time} seconds")
|
||||
for _ in range(args.time):
|
||||
print(".", end="", flush=True)
|
||||
sleep(1)
|
||||
print("Done!")
|
||||
Loading…
x
Reference in New Issue
Block a user