From 52b393537aa26479ca603ec57688c8a4f751d8e2 Mon Sep 17 00:00:00 2001 From: James Hush Date: Tue, 29 Apr 2025 11:32:59 +0800 Subject: [PATCH] RTVI simple chat example --- .../simple-chatbot/client/react/src/App.tsx | 35 +++++++++++++++---- examples/simple-chatbot/server/bot-openai.py | 10 +++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/examples/simple-chatbot/client/react/src/App.tsx b/examples/simple-chatbot/client/react/src/App.tsx index a1e91c74e..93e4599e0 100644 --- a/examples/simple-chatbot/client/react/src/App.tsx +++ b/examples/simple-chatbot/client/react/src/App.tsx @@ -1,17 +1,18 @@ import { RTVIClientAudio, RTVIClientVideo, + useRTVIClient, useRTVIClientTransportState, -} from '@pipecat-ai/client-react'; -import { RTVIProvider } from './providers/RTVIProvider'; -import { ConnectButton } from './components/ConnectButton'; -import { StatusDisplay } from './components/StatusDisplay'; -import { DebugDisplay } from './components/DebugDisplay'; -import './App.css'; +} from "@pipecat-ai/client-react"; +import { RTVIProvider } from "./providers/RTVIProvider"; +import { ConnectButton } from "./components/ConnectButton"; +import { StatusDisplay } from "./components/StatusDisplay"; +import { DebugDisplay } from "./components/DebugDisplay"; +import "./App.css"; function BotVideo() { const transportState = useRTVIClientTransportState(); - const isConnected = transportState !== 'disconnected'; + const isConnected = transportState !== "disconnected"; return (
@@ -23,11 +24,31 @@ function BotVideo() { } function AppContent() { + const client = useRTVIClient(); return (
+
{ + if (!client) { + console.error("RTVI client is not initialized"); + return; + } + client.action({ + service: "tts", + action: "say", + arguments: [ + { name: "text", value: "Hello, world!" }, + { name: "interrupt", value: false }, + ], + }); + }} + > + +
diff --git a/examples/simple-chatbot/server/bot-openai.py b/examples/simple-chatbot/server/bot-openai.py index 07c56aa28..38fafe102 100644 --- a/examples/simple-chatbot/server/bot-openai.py +++ b/examples/simple-chatbot/server/bot-openai.py @@ -40,7 +40,13 @@ from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext from pipecat.processors.frame_processor import FrameDirection, FrameProcessor -from pipecat.processors.frameworks.rtvi import RTVIConfig, RTVIObserver, RTVIProcessor +from pipecat.processors.frameworks.rtvi import ( + RTVIConfig, + RTVIObserver, + RTVIProcessor, + RTVIServiceConfig, + RTVIServiceOptionConfig, +) from pipecat.services.elevenlabs.tts import ElevenLabsTTSService from pipecat.services.openai.llm import OpenAILLMService from pipecat.transports.services.daily import DailyParams, DailyTransport @@ -181,6 +187,8 @@ async def main(): # # RTVI events for Pipecat client UI # + options = RTVIServiceOptionConfig(name="say") + tts_interrupt = RTVIServiceConfig(service="tts", options=[options]) rtvi = RTVIProcessor(config=RTVIConfig(config=[])) pipeline = Pipeline(