diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e6ad1e5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+# Created by venv; see https://docs.python.org/3/library/venv.html
+.env
+.venv
+__pycache__/
diff --git a/DebugLogger.py b/DebugLogger.py
index df3f48a..e0bf67d 100644
--- a/DebugLogger.py
+++ b/DebugLogger.py
@@ -1,8 +1,26 @@
+import streamlit as st
+import subprocess
-
+error_log = []
def log_error(error_message):
- pass
+ #if "error_log" not in st.session_state:
+ # st.session_state["log_error"] = ""
+ #if "code_error" in st.session_state:
+ error_log.append(error_message)
+
def format_debug_output(output):
- pass
\ No newline at end of file
+ pass
+
+#qwen
+def format_output(text: bytes) -> str:
+ return text.decode('utf-8', errors='replace').strip()
+
+def format_error(exc: Exception) -> str:
+ msg = ""
+ if hasattr(exc, 'stderr') and exc.stderr:
+ msg = exc.stderr.decode('utf-8', errors='replace').strip()
+ if isinstance(exc, subprocess.CalledProcessError):
+ msg = f"[Exit: {exc.returncode}] {msg}"
+ return msg or "Execution failed"
\ No newline at end of file
diff --git a/ExecutionEngine.py b/ExecutionEngine.py
index 24be21b..90a4166 100644
--- a/ExecutionEngine.py
+++ b/ExecutionEngine.py
@@ -1,6 +1,7 @@
import subprocess
import streamlit as st
from pathlib import Path
+from DebugLogger import log_error, format_output, format_error
def run_code(code: Path):
@@ -9,21 +10,52 @@ def run_code(code: Path):
if "code_error" in st.session_state:
del st.session_state['code_error']
try:
- sub = subprocess.run(["python", code], capture_output=True, check=True)
- st.session_state['code_output'] = sub.stdout
+ sub = subprocess.run(["python", code], capture_output=True, timeout=20, check=True)
+ st.session_state['code_output'] = format_output(sub.stdout)
except subprocess.CalledProcessError as exc:
- st.session_state['code_error'] = (f"{exc.returncode}")
+ st.session_state['code_error'] = format_error(exc)
+ log_error(st.session_state['code_error'])
+ #st.session_state['code_error'] = (f"{exc.returncode}{exc.stderr}")
+ #log_error(st.session_state['code_error'])
+ #if subprocess.CalledProcessError.stderr:
+ #print(vars(subprocess.CalledProcessError))
+
+ except subprocess.TimeoutExpired as exc:
+ st.session_state['code_error'] = format_error(exc)
+ log_error(st.session_state['code_error'])
+ #st.session_state['code_error'] = (f"{exc.stderr}")
+ #log_error(st.session_state['code_error'])
#print(sub.returncode)
#print(sub.check_returncode)
#print(sub.stderr)
#st.session_state['code_error'] = sub.stderr
-
+#brauchts diese Funktion noch? macht eigentlich schon run_code
def capture_output():
errors = st.session_state['code_error']
#if errors == 0:
# errors = "There are no errors"
return st.session_state['code_output'], errors
+#qwen
+
+
+
+#def run_code(code: Path):
+# for key in ('code_output', 'code_error'):
+# st.session_state.pop(key, None)
+
+ try:
+ res = subprocess.run(["python", code], capture_output=True, timeout=20, check=True)
+ st.session_state['code_output'] = format_output(res.stdout)
+ except subprocess.CalledProcessError as exc:
+ st.session_state['code_error'] = format_error(exc)
+ log_error(st.session_state['code_error'])
+ except subprocess.TimeoutExpired as exc:
+ st.session_state['code_error'] = format_error(exc)
+ log_error(st.session_state['code_error'])
+
+
+
diff --git a/SystemPrompter.py b/SystemPrompter.py
index ed77914..572d30a 100644
--- a/SystemPrompter.py
+++ b/SystemPrompter.py
@@ -22,7 +22,12 @@ def generate_prompt(user_message: str, file_context=None) -> str:
context = (f" {st.session_state['file_content']} ")
else:
context = ""
-
+ if "code_error" in st.session_state:
+ context += (f" {st.session_state['code_error']} ")
- return system_content + task + context
+ prompt = system_content + task + context
+
+ st.session_state["last_prompt"] = (f"{prompt}")
+
+ return prompt
diff --git a/app.py b/app.py
index ce921ec..eca4e74 100644
--- a/app.py
+++ b/app.py
@@ -5,7 +5,9 @@ from FileManager import list_files, read_file, save_file, open_file
from ExecutionEngine import run_code
-"st.session_state object:", st.session_state
+"Last sent prompt:",
+if "last_prompt" in st.session_state:
+ st.session_state["last_prompt"]
st.set_page_config(layout="wide")
@@ -24,7 +26,7 @@ col_editor_output, col_chat = st.columns([0.6, 0.4], gap="large", vertical_align
with col_editor_output:
if "file_content" in st.session_state:
- text = st.text_area("Code Editor", key="file_content")
+ text = st.text_area("Code Editor", height="stretch", key="file_content")
# Preferred pattern for editor
if st.session_state["selected_file"] != "":
@@ -38,9 +40,11 @@ with col_editor_output:
if "code_output" in st.session_state:
st.text_area("Output", key="code_output")
+
if "code_error" in st.session_state:
st.text_area("Errors", key="code_error")
+ #st.button("Ask qwen?", key="debug", on_click=send_message, args=["Explain this error message and help me debug it"])
with col_chat:
@@ -62,12 +66,15 @@ with col_chat:
# Input & Response
message = st.chat_input("How can qwen help you?", key="chat")
+ internet = st.toggle("enable internet search")
if message:
st.session_state.messages.append({"role": "user", "content": message})
response = send_message(message)
st.session_state.messages.append({"role": "assistant", "content": response})
st.rerun()
+
+
#st.write("Chat with qwen")
#message = st.chat_input("How can qwen help you?", key="chat")
#if message:
diff --git a/example_2.py b/example_2.py
index c57fd9f..3a2afa4 100644
--- a/example_2.py
+++ b/example_2.py
@@ -1 +1,11 @@
-hiHa
\ No newline at end of file
+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!")