add context after connected

This commit is contained in:
lloydzhou 2024-11-07 16:56:15 +08:00
parent 7bdc45ed3e
commit 6f81bb3b8a
1 changed files with 14 additions and 1 deletions

View File

@ -76,7 +76,7 @@ export function RealtimeChat({
? { type: "server_vad" } ? { type: "server_vad" }
: null; : null;
clientRef.current.configure({ clientRef.current.configure({
instructions: "Hi", instructions: "",
input_audio_transcription: { model: "whisper-1" }, input_audio_transcription: { model: "whisper-1" },
turn_detection: turnDetection, turn_detection: turnDetection,
tools: [], tools: [],
@ -86,6 +86,19 @@ export function RealtimeChat({
startResponseListener(); startResponseListener();
setIsConnected(true); setIsConnected(true);
try {
const recentMessages = chatStore.getMessagesWithMemory();
for (const message of recentMessages) {
const { role, content } = message;
await clientRef.current.sendItem({
type: "message",
role,
content: [{ type: "input_text", text: content }],
});
}
} catch (error) {
console.error("Set message failed:", error);
}
} catch (error) { } catch (error) {
console.error("Connection failed:", error); console.error("Connection failed:", error);
} finally { } finally {