diff --git a/web/src/pages/qa.tsx b/web/src/pages/qa.tsx new file mode 100644 index 0000000..a2d7bfa --- /dev/null +++ b/web/src/pages/qa.tsx @@ -0,0 +1,105 @@ +import { type NextPage } from "next"; +import { useState, useEffect, useCallback } from "react"; +import Link from "next/link"; + +import { API_URL, STAMPY_URL, STAMPY_CONTENT_URL } from "../settings"; +import useSettings from "../hooks/useSettings"; +import Page from "../components/page"; +import Chat from "../components/chat"; +import { Controls } from "../components/controls"; +import type { + CurrentSearch, + Citation, + Entry, + AssistantEntry as AssistantEntryType, + LLMSettings, + Followup, + SearchResult, +} from "../types"; + +const MAX_FOLLOWUPS = 4; + +export const saveRatings = async ( + sessionId: string, + score: number, + settings: LLMSettings +): Promise => + fetch(API_URL + "/ratings", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ sessionId, settings, score }), + }).then((r) => r.json()); + +const Rater = ({ + settings, + sessionId, + reset, +}: { + settings: LLMSettings; + sessionId: string; + reset: () => void; +}) => { + const onRate = async (rate: number) => { + const res = await saveRatings(sessionId, rate, settings); + if (!res.error) reset(); + }; + + return ( +
+
Rate this session (will reset once rated):
+
+ Bad + {[1, 2, 3, 4, 5].map((i) => ( + + ))} + Good +
+
+ ); +}; + +const QA: NextPage = () => { + const [sessionId, setSessionId] = useState(""); + const [entries, setEntries] = useState([]); + const { settings, setMode, randomize } = useSettings(); + + const reset = useCallback(() => { + randomize(); + setSessionId(crypto.randomUUID()); + setEntries([]); + }, [randomize]); + + // initial load + useEffect(() => { + reset(); + }, [reset]); + + return ( + + + +

+ + Feedback + {" "} + welcomed. +

+ + setEntries((entries) => [...entries, ...e])} + /> + {entries.length > 0 && ( + + )} +
+ ); +}; + +export default QA;