From 616e37afb3ac671996a4e90bf481ad9c8b597bb3 Mon Sep 17 00:00:00 2001
From: Florian <45694132+flo-bit@users.noreply.github.com>
Date: Sun, 6 Oct 2024 14:35:00 +0200
Subject: [PATCH] update chat visualization
---
src/routes/visualizations-chat/+page.svelte | 118 ++++++++++++++-----
src/routes/visualizations-input/+page.svelte | 7 +-
2 files changed, 95 insertions(+), 30 deletions(-)
diff --git a/src/routes/visualizations-chat/+page.svelte b/src/routes/visualizations-chat/+page.svelte
index e75bb66..06aa638 100644
--- a/src/routes/visualizations-chat/+page.svelte
+++ b/src/routes/visualizations-chat/+page.svelte
@@ -8,6 +8,7 @@
import InnerGlowVisualizer from '$lib/realtime/visualizations/InnerGlowVisualizer.svelte';
import CircleCirclesVisualizer from '$lib/realtime/visualizations/CircleCirclesVisualizer.svelte';
import BarVisualizer from '$lib/realtime/visualizations/BarVisualizer.svelte';
+ import type { ItemType } from '@openai/realtime-api-beta/dist/lib/client';
export let wavRecorder: WavRecorder;
let wavStreamPlayer: WavStreamPlayer;
@@ -21,10 +22,40 @@
let current = 0;
$: shownVisualizer = visualizations[current];
+
+ let items: ItemType[] = [];
+
+ let lastAssistantText = '';
+ let lastUserText = '';
+
+ $: if (items && items.length > 0) {
+ // last item with role "assistant"
+
+ const lastAssistant = items
+ .slice()
+ .reverse()
+ .find((item) => item.role === 'assistant');
+
+ if (
+ lastAssistant?.formatted.transcript &&
+ lastAssistant.formatted.transcript !== lastAssistantText
+ ) {
+ lastAssistantText = lastAssistant.formatted.transcript;
+ }
+
+ const lastUser = items
+ .slice()
+ .reverse()
+ .find((item) => item.role === 'user');
+
+ if (lastUser?.formatted.transcript && lastUser.formatted.transcript !== lastUserText) {
+ lastUserText = lastUser.formatted.transcript;
+ }
+ }
{#if apiKey}
-