diff --git a/src/components/Messages/Ai.tsx b/src/components/Messages/Ai.tsx index 46cd83e..69afce4 100644 --- a/src/components/Messages/Ai.tsx +++ b/src/components/Messages/Ai.tsx @@ -5,13 +5,49 @@ import { CopyToClipboard } from "./CopyToClipboard"; import { PencilIcon } from "@heroicons/react/24/outline"; import { Persona } from "../../dto/PersonaOptions"; import { Avatar } from "../Icons"; -import {AvatarItem} from "./AvatarItem"; +import { AvatarItem } from "./AvatarItem"; +import { useState } from "react"; +import { HandThumbDownIcon, HandThumbUpIcon } from "@heroicons/react/24/outline"; +import { HandThumbDownIcon as SHandThumbDownIcon, HandThumbUpIcon as SHandThumbUpIcon } from "@heroicons/react/24/solid"; +import { DEV_SERVER_URL } from "../adapter"; +export interface AiMessageProps { message?: string; typing?: boolean; persona?: Persona, threadId?: string, messageId?: string, getHeaders: () => Promise, serverUrl?: string }; +export const AiMessage: React.FC = ({ message, typing, persona, threadId, messageId, getHeaders, serverUrl }) => { + const [score, setScore] = useState(); + const [error, setError] = useState(); + const handleScore = async (score: number) => { + if (!threadId || !messageId) { + setError("streaming message doesnt have thread and messageIds"); + return; + } + let scoreRequest = { + thread_id: threadId, + message_id: messageId, + score: score, + }; + try { + const headers = await getHeaders(); + const apiUrl = serverUrl || DEV_SERVER_URL; + const response = await fetch(`${apiUrl}/threads/score`, { + method: 'POST', + headers, + body: JSON.stringify(scoreRequest), + }); -export const AiMessage: React.FC<{ message?: string; typing?: boolean; persona?: Persona }> = ({ message, typing, persona }) => ( -
+ if (!response.ok) { + throw new Error('Failed to record score'); + } + setScore(score); + } catch (error: any) { + setError(error.toString()); + console.error('Error recording score:', error); + } + + }; + + return (
- {!persona ? : ( persona.url ? : )} + {!persona ? : (persona.url ? : )}
- {typing && ( -
- - Typing... -
- )} -
-); \ No newline at end of file + {!typing &&
+ + + {error &&
{error}
} +
} + { + typing && ( +
+ + Typing... +
+ ) + } +
) +}; \ No newline at end of file