46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""
|
|
FILE: app/frontend/ui_api.py
|
|
DESCRIPTION: Wrapper für Backend-Calls (Chat, Ingest, Feedback). Kapselt requests und Error-Handling.
|
|
VERSION: 2.6.0
|
|
STATUS: Active
|
|
DEPENDENCIES: requests, streamlit, ui_config
|
|
LAST_ANALYSIS: 2025-12-15
|
|
"""
|
|
|
|
import requests
|
|
import streamlit as st
|
|
from ui_config import CHAT_ENDPOINT, INGEST_ANALYZE_ENDPOINT, INGEST_SAVE_ENDPOINT, FEEDBACK_ENDPOINT, API_TIMEOUT
|
|
|
|
def send_chat_message(message: str, top_k: int, explain: bool):
|
|
try:
|
|
response = requests.post(
|
|
CHAT_ENDPOINT,
|
|
json={"message": message, "top_k": top_k, "explain": explain},
|
|
timeout=API_TIMEOUT
|
|
)
|
|
response.raise_for_status()
|
|
return response.json()
|
|
except Exception as e:
|
|
return {"error": str(e)}
|
|
|
|
def analyze_draft_text(text: str, n_type: str):
|
|
try:
|
|
response = requests.post(INGEST_ANALYZE_ENDPOINT, json={"text": text, "type": n_type}, timeout=15)
|
|
response.raise_for_status()
|
|
return response.json()
|
|
except Exception as e:
|
|
return {"error": str(e)}
|
|
|
|
def save_draft_to_vault(markdown_content: str, filename: str = None):
|
|
try:
|
|
response = requests.post(INGEST_SAVE_ENDPOINT, json={"markdown_content": markdown_content, "filename": filename}, timeout=API_TIMEOUT)
|
|
response.raise_for_status()
|
|
return response.json()
|
|
except Exception as e:
|
|
return {"error": str(e)}
|
|
|
|
def submit_feedback(query_id, node_id, score, comment=None):
|
|
try:
|
|
requests.post(FEEDBACK_ENDPOINT, json={"query_id": query_id, "node_id": node_id, "score": score, "comment": comment}, timeout=2)
|
|
st.toast(f"Feedback ({score}) gesendet!")
|
|
except: pass |