Преглед на файлове

add context after connected

lloydzhou преди 1 година
родител
ревизия
6f81bb3b8a
променени са 1 файла, в които са добавени 14 реда и са изтрити 1 реда
  1. 14 1
      app/components/realtime-chat/realtime-chat.tsx

+ 14 - 1
app/components/realtime-chat/realtime-chat.tsx

@@ -76,7 +76,7 @@ export function RealtimeChat({
           ? { type: "server_vad" }
           : null;
         clientRef.current.configure({
-          instructions: "Hi",
+          instructions: "",
           input_audio_transcription: { model: "whisper-1" },
           turn_detection: turnDetection,
           tools: [],
@@ -86,6 +86,19 @@ export function RealtimeChat({
         startResponseListener();
 
         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) {
         console.error("Connection failed:", error);
       } finally {