From 757ed2e80ca13db1519dc806691c36fd235edad5 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 20 Nov 2024 13:24:50 -0500 Subject: [PATCH] Add local processing option to pipeline for LLM conversation agents (#22561) * Add local processing field to pipeline * update * Update wording * handle current pipelines --------- Co-authored-by: Bram Kragten --- src/data/assist_pipeline.ts | 2 + .../assist-pipeline-detail-conversation.ts | 58 ++++++++++++++----- .../dialog-voice-assistant-pipeline-detail.ts | 5 +- src/translations/en.json | 2 + 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/data/assist_pipeline.ts b/src/data/assist_pipeline.ts index e5f60c2d9c..c0c8b4b788 100644 --- a/src/data/assist_pipeline.ts +++ b/src/data/assist_pipeline.ts @@ -9,6 +9,7 @@ export interface AssistPipeline { language: string; conversation_engine: string; conversation_language: string | null; + prefer_local_intents?: boolean; stt_engine: string | null; stt_language: string | null; tts_engine: string | null; @@ -28,6 +29,7 @@ export interface AssistPipelineMutableParams { language: string; conversation_engine: string; conversation_language: string | null; + prefer_local_intents?: boolean; stt_engine: string | null; stt_language: string | null; tts_engine: string | null; diff --git a/src/panels/config/voice-assistants/assist-pipeline-detail/assist-pipeline-detail-conversation.ts b/src/panels/config/voice-assistants/assist-pipeline-detail/assist-pipeline-detail-conversation.ts index 22c93108d3..1fb3871614 100644 --- a/src/panels/config/voice-assistants/assist-pipeline-detail/assist-pipeline-detail-conversation.ts +++ b/src/panels/config/voice-assistants/assist-pipeline-detail/assist-pipeline-detail-conversation.ts @@ -17,8 +17,12 @@ export class AssistPipelineDetailConversation extends LitElement { @state() private _supportedLanguages?: "*" | string[]; private _schema = memoizeOne( - (language?: string, supportedLanguages?: "*" | string[]) => - [ + ( + engine?: string, + language?: string, + supportedLanguages?: "*" | string[] + ) => { + const fields: any = [ { name: "", type: "grid", @@ -32,18 +36,32 @@ export class AssistPipelineDetailConversation extends LitElement { }, }, }, - supportedLanguages !== "*" && supportedLanguages?.length - ? { - name: "conversation_language", - required: true, - selector: { - language: { languages: supportedLanguages, no_sort: true }, - }, - } - : { name: "", type: "constant" }, - ] as const, + ], }, - ] as const + ]; + + if (supportedLanguages !== "*" && supportedLanguages?.length) { + fields[0].schema.push({ + name: "conversation_language", + required: true, + selector: { + language: { languages: supportedLanguages, no_sort: true }, + }, + }); + } + + if (engine !== "conversation.home_assistant") { + fields.push({ + name: "prefer_local_intents", + default: true, + selector: { + boolean: {}, + }, + }); + } + + return fields; + } ); private _computeLabel = (schema): string => @@ -53,6 +71,13 @@ export class AssistPipelineDetailConversation extends LitElement { ) : ""; + private _computeHelper = (schema): string => + schema.name + ? this.hass.localize( + `ui.panel.config.voice_assistants.assistants.pipeline.detail.form.${schema.name}_description` as LocalizeKeys + ) + : ""; + protected render() { return html`
@@ -69,10 +94,15 @@ export class AssistPipelineDetailConversation extends LitElement {

diff --git a/src/panels/config/voice-assistants/dialog-voice-assistant-pipeline-detail.ts b/src/panels/config/voice-assistants/dialog-voice-assistant-pipeline-detail.ts index 3404dd91ee..097be756b0 100644 --- a/src/panels/config/voice-assistants/dialog-voice-assistant-pipeline-detail.ts +++ b/src/panels/config/voice-assistants/dialog-voice-assistant-pipeline-detail.ts @@ -48,7 +48,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement { this._cloudActive = this._params.cloudActiveSubscription; if (this._params.pipeline) { - this._data = this._params.pipeline; + this._data = { prefer_local_intents: false, ...this._params.pipeline }; this._hideWakeWord = this._params.hideWakeWord || !this._data.wake_word_entity; @@ -170,7 +170,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement { ${!this._cloudActive && @@ -259,6 +259,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement { language: data.language!, conversation_engine: data.conversation_engine!, conversation_language: data.conversation_language ?? null, + prefer_local_intents: data.prefer_local_intents ?? true, stt_engine: data.stt_engine ?? null, stt_language: data.stt_language ?? null, tts_engine: data.tts_engine ?? null, diff --git a/src/translations/en.json b/src/translations/en.json index be36b79488..554cb931a1 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2724,6 +2724,8 @@ "name": "[%key:ui::common::name%]", "conversation_engine": "Conversation agent", "conversation_language": "[%key:ui::panel::config::voice_assistants::assistants::pipeline::detail::form::language%]", + "prefer_local_intents": "Prefer handling commands locally", + "prefer_local_intents_description": "A command will first be sent to the local conversation agent. If the local agent does not handle the command, it will be sent to selected agent.", "language": "Language", "stt_engine": "Speech-to-text", "stt_language": "[%key:ui::panel::config::voice_assistants::assistants::pipeline::detail::form::language%]",