milestone 3 - connected Modules to app.py, FileManager: added function open_file for connection between file clicking and editor in app.py, ChatManager: made connections to SystemPrompter, SystemPrompter: wrote systemprompt, added file_context through session_state to prompts
This commit is contained in:
parent
626c10c129
commit
69f82f7f3e
@ -1,6 +1,7 @@
|
||||
from openai import OpenAI
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from SystemPrompter import generate_prompt
|
||||
|
||||
|
||||
load_dotenv(dotenv_path=".env")
|
||||
@ -19,16 +20,16 @@ def get_client() -> OpenAI:
|
||||
client = get_client()
|
||||
|
||||
|
||||
def send_message(message):
|
||||
def send_message(message: str):
|
||||
# hier gehts darum, die message vorzubereiten -> also nachricht aus den Chatfenster mit systemprompts und file_conntext verknüpfen
|
||||
# hier auch Zeug zusammenkürzen wenns zu lang wird?
|
||||
return "Explain what a system prompt is."
|
||||
prompt = generate_prompt(message)
|
||||
response = send_prompt(prompt)
|
||||
return response
|
||||
|
||||
def receive_response():
|
||||
def send_prompt(prompt: str):
|
||||
# hier wird send_message() aufgerufen, damit dann geschickt werden kann
|
||||
response = client.responses.create(
|
||||
input=send_message(""))
|
||||
input=prompt)
|
||||
return response.output_text
|
||||
|
||||
print(receive_response())
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import os
|
||||
import streamlit as st
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ def list_files() -> list:
|
||||
#mypath = "C:/FH_Graubünden/26FS/AI_in_SE/project_ai_se"
|
||||
#files = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
|
||||
mypath = Path.cwd()
|
||||
print(f"u ä {mypath}")
|
||||
#print(f"u ä {mypath}")
|
||||
files = list(mypath.glob('*.py'))
|
||||
return files
|
||||
|
||||
@ -24,6 +24,12 @@ def save_file(file_path: Path, content: str):
|
||||
with file_path.open('w') as file:
|
||||
file.write(content)
|
||||
|
||||
def open_file(file_path):
|
||||
content = read_file(file_path)
|
||||
st.session_state["file_content"] = content
|
||||
st.session_state["selected_file"] = file_path
|
||||
|
||||
|
||||
|
||||
print(list_files())
|
||||
print(read_file(Path("C:/FH_Graubünden/26FS/AI_in_SE/project_ai_se/example.py")))
|
||||
|
||||
@ -1,5 +1,23 @@
|
||||
import streamlit as st
|
||||
|
||||
|
||||
def generate_prompt(user_message: str, file_context=None):
|
||||
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 = (f" <code> {st.session_state["file_content"]} </code>")
|
||||
|
||||
|
||||
return system_content + task + context
|
||||
|
||||
def generate_prompt(user_message, file_context):
|
||||
pass
|
||||
27
app.py
27
app.py
@ -1,25 +1,31 @@
|
||||
import streamlit as st
|
||||
from pathlib import Path
|
||||
from ChatManager import send_message
|
||||
from FileManager import list_files, read_file, save_file, open_file
|
||||
|
||||
|
||||
"st.session_state object:", st.session_state
|
||||
|
||||
|
||||
def callback_test():
|
||||
st.write("hello")
|
||||
|
||||
bsp_list = ["Projekt", ["Datei 1", "Datei 2"]]
|
||||
with st.sidebar:
|
||||
#wenn FileManager integriert wird: Elemente mit list_files bauen
|
||||
st.write(bsp_list[0])
|
||||
st.button(bsp_list[1][0], key="datei1", on_click=callback_test)
|
||||
st.button(bsp_list[1][1], key="datei2")
|
||||
for file in list_files():
|
||||
st.button(file.name, on_click=open_file, args=[file])
|
||||
#bla_button = st.button("bla")
|
||||
#if bla_button:
|
||||
# st.session_state["bla"] = "text"
|
||||
# wenn Datei ausgewählt wird, sollte FileManager aufgerufen werden, der dann im Code Editor den Inhalt anzeigt
|
||||
# on_click: FileManager: read_file(file_path)
|
||||
|
||||
col_editor_output, col_chat = st.columns([0.6, 0.4], gap="xxlarge")
|
||||
|
||||
with col_editor_output:
|
||||
st.text_area("Code Editor", key="editor", on_change=callback_test)
|
||||
if "file_content" in st.session_state:
|
||||
text = st.text_area("Code Editor", key="file_content")
|
||||
#if st.session_state["file_content"] != text:
|
||||
# st.session_state["editor"] = st.session_state["file_content"]
|
||||
|
||||
# Verhalten bei Veränderungen mit on_change festlegen, mit File_Manager verknüpfen
|
||||
# on_change(save_file(file_path, content( -> das wär dann der Inhalt von text_area))
|
||||
# wenn angezigter Code bearbeitet wird, sollte ExecutionEngine aufgerufen werden, diese soll den Code ausführen und im Outputfenster angezeigt werden mit DebugLogger
|
||||
@ -29,9 +35,12 @@ with col_editor_output:
|
||||
|
||||
with col_chat:
|
||||
st.write("Chat with qwen")
|
||||
st.chat_input("How can qwen help you?", key="chat", on_submit=callback_test)
|
||||
message = st.chat_input("How can qwen help you?", key="chat")
|
||||
if message:
|
||||
response = send_message(message)
|
||||
st.write(response)
|
||||
#Verhalten bei Veränderungen mit on_submit festlegen
|
||||
#ChatManager kümmert sich um chat history und Verbindung mit AI API (qwen)
|
||||
#Systemprompter schickt Kontext mit
|
||||
st.write("History")
|
||||
st.write(st.session_state["chat"])
|
||||
st.write(message)
|
||||
Loading…
x
Reference in New Issue
Block a user