-
Notifications
You must be signed in to change notification settings - Fork 55
Add support for new bot-output event, providing corresponding callbac… #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,16 @@ All notable changes to **Pipecat Client JS** will be documented in this file. | |||||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||||||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||||||
|
|
||||||
| ## [Unreleased] | ||||||
|
|
||||||
| ### Added | ||||||
|
|
||||||
| - BotOutput | ||||||
|
|
||||||
| ### Deprecated | ||||||
|
|
||||||
| - BotTranscription | ||||||
|
||||||
| - BotTranscription | |
| - Deprecated `BotTranscription` in favor of the new `BotOutput` event. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ import packageJson from "../package.json"; | |||||
| import { | ||||||
| BotLLMSearchResponseData, | ||||||
| BotLLMTextData, | ||||||
| BotOutputData, | ||||||
| BotReadyData, | ||||||
| BotTTSTextData, | ||||||
| ClientMessageData, | ||||||
|
|
@@ -101,6 +102,7 @@ export type RTVIEventCallbacks = Partial<{ | |||||
| onUserStartedSpeaking: () => void; | ||||||
| onUserStoppedSpeaking: () => void; | ||||||
| onUserTranscript: (data: TranscriptData) => void; | ||||||
| onBotOutput: (data: BotOutputData) => void; | ||||||
| onBotTranscript: (data: BotLLMTextData) => void; | ||||||
|
|
||||||
| onBotLlmText: (data: BotLLMTextData) => void; | ||||||
|
|
@@ -158,6 +160,8 @@ export class PipecatClient extends RTVIEventEmitter { | |||||
| protected _functionCallCallbacks: Record<string, FunctionCallCallback> = {}; | ||||||
| protected _abortController: AbortController | undefined; | ||||||
|
|
||||||
| private _botTranscriptionWarned = false; | ||||||
|
|
||||||
| constructor(options: PipecatClientOptions) { | ||||||
| super(); | ||||||
|
|
||||||
|
|
@@ -300,7 +304,17 @@ export class PipecatClient extends RTVIEventEmitter { | |||||
| options?.callbacks?.onUserTranscript?.(data); | ||||||
| this.emit(RTVIEvent.UserTranscript, data); | ||||||
| }, | ||||||
| onBotOutput: (data) => { | ||||||
| options?.callbacks?.onBotOutput?.(data); | ||||||
| this.emit(RTVIEvent.BotOutput, data); | ||||||
| }, | ||||||
| onBotTranscript: (text) => { | ||||||
| if (!this._botTranscriptionWarned) { | ||||||
| logger.warn( | ||||||
| "[Pipecat Client] Bot transcription is deprecated. Please use the onBotOutput instead." | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||
| ); | ||||||
| this._botTranscriptionWarned = true; | ||||||
| } | ||||||
| options?.callbacks?.onBotTranscript?.(text); | ||||||
| this.emit(RTVIEvent.BotTranscript, text); | ||||||
| }, | ||||||
|
|
@@ -369,7 +383,7 @@ export class PipecatClient extends RTVIEventEmitter { | |||||
| @transportAlreadyStarted | ||||||
| public async startBot(startBotParams: APIRequest): Promise<unknown> { | ||||||
| this._transport.state = "authenticating"; | ||||||
| this._transport.startBotParams = startBotParams | ||||||
| this._transport.startBotParams = startBotParams; | ||||||
| this._abortController = new AbortController(); | ||||||
| let response: unknown; | ||||||
| try { | ||||||
|
|
@@ -701,6 +715,10 @@ export class PipecatClient extends RTVIEventEmitter { | |||||
| this._options.callbacks?.onUserTranscript?.(TranscriptData); | ||||||
| break; | ||||||
| } | ||||||
| case RTVIMessageType.BOT_OUTPUT: { | ||||||
| this._options.callbacks?.onBotOutput?.(ev.data as BotOutputData); | ||||||
| break; | ||||||
| } | ||||||
| case RTVIMessageType.BOT_TRANSCRIPTION: { | ||||||
| this._options.callbacks?.onBotTranscript?.(ev.data as BotLLMTextData); | ||||||
| break; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,8 @@ export enum RTVIMessageType { | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** Transcription Messages */ | ||||||||||||||||||||||||||||
| USER_TRANSCRIPTION = "user-transcription", // Local user speech to text transcription (partials and finals) | ||||||||||||||||||||||||||||
| BOT_OUTPUT = "bot-output", // A best effort aggregation of all bot output along with metadata like if it's spoken | ||||||||||||||||||||||||||||
| // DEPRECATED | ||||||||||||||||||||||||||||
| BOT_TRANSCRIPTION = "bot-transcription", // Bot full text transcription (sentence aggregated) | ||||||||||||||||||||||||||||
| USER_STARTED_SPEAKING = "user-started-speaking", // User started speaking | ||||||||||||||||||||||||||||
| USER_STOPPED_SPEAKING = "user-stopped-speaking", // User stopped speaking | ||||||||||||||||||||||||||||
|
|
@@ -119,6 +121,12 @@ export type TranscriptData = { | |||||||||||||||||||||||||||
| user_id: string; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export type BotOutputData = { | ||||||||||||||||||||||||||||
| text: string; | ||||||||||||||||||||||||||||
| spoken: boolean; | ||||||||||||||||||||||||||||
| aggregated_by?: "word" | "sentence" | string; | ||||||||||||||||||||||||||||
|
Comment on lines
+124
to
+127
|
||||||||||||||||||||||||||||
| export type BotOutputData = { | |
| text: string; | |
| spoken: boolean; | |
| aggregated_by?: "word" | "sentence" | string; | |
| export enum AggregatedByType { | |
| WORD = "word", | |
| SENTENCE = "sentence", | |
| } | |
| export type BotOutputData = { | |
| text: string; | |
| spoken: boolean; | |
| aggregated_by?: AggregatedByType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. the point is that the value can be any string, but adding in the "word" | "sentence" makes it clear that those are sort-of built-in or common values that can be expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if we should have an extra field like "type" or "kind." But I’m not sure whether we’ll have that information inside Pipecat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entry for BotOutput lacks detail. Include a brief description of what the feature does, such as 'Added BotOutput event providing unified bot output with spoken metadata and aggregation information'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Copilot on this one. 😅
But I guess you just left it here for now so you’d remember to describe it later.