Spaces:
Paused
Paused
Fix: Directory Error & Feedback DB
Browse files
src/core/__pycache__/config.cpython-312.pyc
CHANGED
|
Binary files a/src/core/__pycache__/config.cpython-312.pyc and b/src/core/__pycache__/config.cpython-312.pyc differ
|
|
|
src/server.py
CHANGED
|
@@ -48,7 +48,7 @@ def clean_output(text):
|
|
| 48 |
text = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL)
|
| 49 |
return text.replace("</think>", "").replace("<think>", "").strip()
|
| 50 |
|
| 51 |
-
# --- HTML
|
| 52 |
html_content = """
|
| 53 |
<!DOCTYPE html>
|
| 54 |
<html lang="vi">
|
|
@@ -83,16 +83,16 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 83 |
|
| 84 |
@app.post("/feedback")
|
| 85 |
async def save_feedback(req: FeedbackRequest):
|
| 86 |
-
# ---
|
| 87 |
try:
|
| 88 |
with memory.get_conn() as conn:
|
| 89 |
conn.execute(text("""
|
| 90 |
INSERT INTO feedback_logs (user_id, prompt, ai_response, user_correction, feedback_type)
|
| 91 |
VALUES (:uid, :p, :r, :c, :f)
|
| 92 |
"""), {
|
| 93 |
-
"uid": 1,
|
| 94 |
"p": req.prompt,
|
| 95 |
-
"r": req.
|
| 96 |
"c": req.correction,
|
| 97 |
"f": req.feedback
|
| 98 |
})
|
|
|
|
| 48 |
text = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL)
|
| 49 |
return text.replace("</think>", "").replace("<think>", "").strip()
|
| 50 |
|
| 51 |
+
# --- HTML UI (Minified) ---
|
| 52 |
html_content = """
|
| 53 |
<!DOCTYPE html>
|
| 54 |
<html lang="vi">
|
|
|
|
| 83 |
|
| 84 |
@app.post("/feedback")
|
| 85 |
async def save_feedback(req: FeedbackRequest):
|
| 86 |
+
# --- SAVE TO NEON DB ---
|
| 87 |
try:
|
| 88 |
with memory.get_conn() as conn:
|
| 89 |
conn.execute(text("""
|
| 90 |
INSERT INTO feedback_logs (user_id, prompt, ai_response, user_correction, feedback_type)
|
| 91 |
VALUES (:uid, :p, :r, :c, :f)
|
| 92 |
"""), {
|
| 93 |
+
"uid": 1,
|
| 94 |
"p": req.prompt,
|
| 95 |
+
"r": req.response,
|
| 96 |
"c": req.correction,
|
| 97 |
"f": req.feedback
|
| 98 |
})
|
src/tools/create_feedback_table.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
from sqlalchemy import create_engine, text
|
| 5 |
+
|
| 6 |
+
# Add path to find config
|
| 7 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
| 8 |
+
from src.core.config import Config
|
| 9 |
+
|
| 10 |
+
def create_table():
|
| 11 |
+
print("🔧 Connecting to Cloud DB...")
|
| 12 |
+
config = Config()
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
engine = create_engine(config.DB_URL)
|
| 16 |
+
with engine.connect() as conn:
|
| 17 |
+
print("🔨 Creating 'feedback_logs' table...")
|
| 18 |
+
conn.execute(text("""
|
| 19 |
+
CREATE TABLE IF NOT EXISTS feedback_logs (
|
| 20 |
+
id SERIAL PRIMARY KEY,
|
| 21 |
+
user_id INTEGER,
|
| 22 |
+
prompt TEXT,
|
| 23 |
+
ai_response TEXT,
|
| 24 |
+
user_correction TEXT,
|
| 25 |
+
feedback_type TEXT,
|
| 26 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
| 27 |
+
);
|
| 28 |
+
"""))
|
| 29 |
+
conn.commit()
|
| 30 |
+
print("✅ Success! Feedback table is ready in Neon.")
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"❌ DB Error: {e}")
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
create_table()
|