diff --git a/ChatManager.py b/ChatManager.py index 7b16742..31f8823 100644 --- a/ChatManager.py +++ b/ChatManager.py @@ -3,25 +3,24 @@ from dotenv import load_dotenv import os from SystemPrompter import generate_prompt -#environment vaarables sind in eigener .env Datei abgespeichert +#environment variables sind in eigener .env Datei abgespeichert load_dotenv(dotenv_path=".env") - HOST = os.getenv('HOST') PORT = os.getenv('PORT') API_KEY = os.getenv('API_KEY') MODEL = os.getenv('MODEL') def get_client() -> OpenAI: - """Return an OpenAI-compatible client pointing at the vLLM server.""" + #gibt qwen zurück base_url = f"http://{HOST}:{PORT}/v1" return OpenAI(base_url=base_url, api_key=API_KEY) client = get_client() - def send_message(message: str) -> str: - # hier gehts darum, die message vorzubereiten -> also nachricht aus den Chatfenster mit systemprompts und file_conntext verknüpfen + # hier gehts darum, die message vorzubereiten + # -> also nachricht aus den Chatfenster mit systemprompts und file_conntext verknüpfen prompt = generate_prompt(message) response = send_prompt(prompt) return response diff --git a/DebugLogger.py b/DebugLogger.py index ce026d0..01d5887 100644 --- a/DebugLogger.py +++ b/DebugLogger.py @@ -1,18 +1,13 @@ import streamlit as st import subprocess -error_log = [] - def log_error(error_message): + #speichern wieder über session_state st.session_state["bugs"] = error_message - #if "bugs" not in st.session_state: - # st.session_state["bugs"] = "" - #if "bugs" in st.session_state: - #error_log.append(error_message) def format_debug_output(output: dict) -> str: - """Format debug output dictionary into a readable string.""" + #formatiert das dictionary in einen lesbareren string lines = ["=== DEBUG REPORT ===", f"Summary: {output.get('summary', 'N/A')}", f"Quality: {output.get('overall_quality', 'N/A')}", diff --git a/ExecutionEngine.py b/ExecutionEngine.py index d74858e..70adbdf 100644 --- a/ExecutionEngine.py +++ b/ExecutionEngine.py @@ -5,7 +5,7 @@ import ast from DebugLogger import log_error, format_output, format_error -def run_code(code: Path): +def run_code(code: Path) -> None | str: if "code_output" in st.session_state: del st.session_state['code_output'] if "code_error" in st.session_state: @@ -23,21 +23,12 @@ def run_code(code: Path): except subprocess.CalledProcessError as exc: 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(): @@ -51,7 +42,7 @@ def capture_output(): #aus der uebungsloesung def check_code_safety(code: str) -> str | None: - """Analysiert den Code statisch nach verbotenen imports und builtins.""" + #Analysiert den Code statisch nach verbotenen imports und builtins. try: tree = ast.parse(code) except SyntaxError as e: diff --git a/FileManager.py b/FileManager.py index e41eacc..805a03f 100644 --- a/FileManager.py +++ b/FileManager.py @@ -10,7 +10,6 @@ def list_files() -> list: return files def read_file(file_path: Path) -> str: - # ErrorHandling einbauen, falls der Pfad falsch ist? # Datei wird im Sidebar angeklickt, Inhalt wird ausgelesen with file_path.open('r') as file: return file.read() diff --git a/SearchManager.py b/SearchManager.py index da42062..a257faf 100644 --- a/SearchManager.py +++ b/SearchManager.py @@ -1,33 +1,24 @@ from ddgs import DDGS - -#query = "python programming" +import re def perform_search(query: str) -> dict: - results = DDGS().text(query, max_results=3) - #print(results) - return results + try: + results = DDGS().text(query, max_results=3) + return results + except Exception as e: + return {"error":str(e), "results":[]} + + -#def parse_results(raw_results: dict) -> list: -# formatted_results = [] -# for result in raw_results: -# for key in result: -# if key == "href": -# formatted_results.append(result.get(key)) -# if key == "body": -# text = result.get(key) -# if len(text) > 500: -# text = text[0:500] -# formatted_results.append(text) - - return formatted_results def parse_results(results: list[dict]) -> list[dict]: - return [ + return [ { - "url": r.get("href", ""), + "url": r.get("href", ""), # "snippet": r.get("body", "")[:500] } for r in results + if r.get("href", "").startswith('https://') ] -#parse_results(perform_search(query)) + \ No newline at end of file diff --git a/SystemPrompter.py b/SystemPrompter.py index ed1919d..eaf5a61 100644 --- a/SystemPrompter.py +++ b/SystemPrompter.py @@ -4,7 +4,7 @@ from SearchManager import perform_search, parse_results def generate_prompt(user_message: str) -> str: - if "debug" in st.session_state: + if "debug" in st.session_state and st.session_state["debug"]: 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 diff --git a/app.py b/app.py index 36a0765..d6c6698 100644 --- a/app.py +++ b/app.py @@ -39,12 +39,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 - # fürs Ausführen vllt eigener Button machen? st.button("execute code", key="execution", on_click=run_code) - #st.write("Output and debugging messages") + if "code_output" in st.session_state: st.text_area("Output", key="code_output") @@ -59,12 +54,6 @@ with col_chat: if "messages" not in st.session_state: st.session_state.messages = [] - #if "history" in st.session_state: - # string = "" - # for item in st.session_state["history"]: - # string += item - # st.write(string) - # Display History with st.container(border=True, height=500): @@ -88,22 +77,4 @@ with col_chat: st.rerun() - - #st.write("Chat with qwen") - #message = st.chat_input("How can qwen help you?", key="chat") - #if message: - # response = send_message(message) - # #st.write(response) - - # if not "history" in st.session_state: - # st.session_state["history"] = [] - # st.session_state["history"].append(f"Message: {message} \n ----- \n Response: {response} \n ----- \n") - # st.rerun() - - - - #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 - \ No newline at end of file diff --git a/example.py b/example.py index c48b66e..81a0116 100644 --- a/example.py +++ b/example.py @@ -1,6 +1,4 @@ -print("blabliblu") print("Hello World") -print("Hello") diff --git a/example_2.py b/example_2.py index 04e6ca0..47dd12c 100644 --- a/example_2.py +++ b/example_2.py @@ -1,3 +1,46 @@ -import json +def calculate_statistics(numbers): + total = 0 + for n in numbers: + total = total + n + average = total / len(numbers) -json.load("summary": "The module fails to run due to a missing dependency and lacks defensive programming for session state access.", "bugs": [ { "id": 1, "severity": "Critical", "line": 2, "function": "", "description": "The code fails to import due to 'ddgs' library missing in the environment, causing a ModuleNotFoundError.", "fix": "Install the missing dependency by running 'pip install ddgs'." }, { "id": 2, "severity": "Medium", "line": 15, "function": "generate_prompt", "description": "Accessing st.session_state['file_content'] in the debug block without checking for key existence may raise a KeyError.", "fix": "Add a conditional check to verify the key exists before accessing it." } ], "overall_quality": "Poor") \ No newline at end of file + min_val = numbers[0] + max_val = numbers[0] + for n in numbers: + if n < min_val: + min_val = n + if n > max_val: + max_val = n + + variance = 0 + for n in numbers: + variance = variance + (n - average) ** 2 + variance = variance / len(numbers) + + return { + "count": len(numbers), + "sum": total, + "average": average, + "min": min_val, + "max": max_val, + "variance": variance, + } + + + +def normalize(numbers, method="minmax"): + if method == "minmax": + mn = min(numbers) + mx = max(numbers) + return [(x - mn) / mx - mn for x in numbers] + elif method == "zscore": + stats = calculate_statistics(numbers) + std = stats["variance"] ** 0.5 + return [(x - stats["average"]) / std for x in numbers] + else: + print("Unknown normalisation method") + + +if __name__ == "__main__": + sample = [4, 8, 15, 16, 23, 42] + print(calculate_statistics(sample)) \ No newline at end of file diff --git a/praesentation_ai_se.pptx b/praesentation_ai_se.pptx new file mode 100644 index 0000000..59a7220 Binary files /dev/null and b/praesentation_ai_se.pptx differ