diff --git a/api/main.py b/api/main.py index 912778f..d5bb0e8 100644 --- a/api/main.py +++ b/api/main.py @@ -103,13 +103,14 @@ def human(id): def ratings(): session_id = request.json.get('sessionId') settings = request.json.get('settings', {}) + comment = (request.json.get('comment') or '').strip() or None # only save strings if not empty score = request.json.get('score') if not session_id or score is None: return Response('{"error": "missing params}', 400, mimetype='application/json') with make_session() as s: - s.add(Rating(session_id=session_id, score=score, settings=json.dumps(settings))) + s.add(Rating(session_id=session_id, score=score, settings=json.dumps(settings), comment=comment)) s.commit() return jsonify({'status': 'ok'}) diff --git a/web/src/pages/qa.tsx b/web/src/pages/qa.tsx index a2d7bfa..19e5932 100644 --- a/web/src/pages/qa.tsx +++ b/web/src/pages/qa.tsx @@ -22,6 +22,7 @@ const MAX_FOLLOWUPS = 4; export const saveRatings = async ( sessionId: string, score: number, + comment: string | null, settings: LLMSettings ): Promise => fetch(API_URL + "/ratings", { @@ -29,7 +30,7 @@ export const saveRatings = async ( headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ sessionId, settings, score }), + body: JSON.stringify({ sessionId, settings, score, comment }), }).then((r) => r.json()); const Rater = ({ @@ -41,8 +42,10 @@ const Rater = ({ sessionId: string; reset: () => void; }) => { + const [comment, setComment] = useState(null); + const onRate = async (rate: number) => { - const res = await saveRatings(sessionId, rate, settings); + const res = await saveRatings(sessionId, rate, comment, settings); if (!res.error) reset(); }; @@ -58,6 +61,10 @@ const Rater = ({ ))} Good + ); }; diff --git a/web/src/styles/globals.css b/web/src/styles/globals.css index 854e94e..9b83fe8 100644 --- a/web/src/styles/globals.css +++ b/web/src/styles/globals.css @@ -65,3 +65,8 @@ ol { width: 2.5em; margin: 0.5em; } + +.rate-container textarea { + width: 100%; + border: black solid 1px; +}