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 <mail@bramkragten.nl>
This commit is contained in:
Paulus Schoutsen 2024-11-20 13:24:50 -05:00 committed by GitHub
parent d2665f1349
commit 757ed2e80c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 16 deletions

View File

@ -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;

View File

@ -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
? {
],
},
];
if (supportedLanguages !== "*" && supportedLanguages?.length) {
fields[0].schema.push({
name: "conversation_language",
required: true,
selector: {
language: { languages: supportedLanguages, no_sort: true },
},
});
}
: { name: "", type: "constant" },
] as const,
if (engine !== "conversation.home_assistant") {
fields.push({
name: "prefer_local_intents",
default: true,
selector: {
boolean: {},
},
] as const
});
}
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`
<div class="section">
@ -69,10 +94,15 @@ export class AssistPipelineDetailConversation extends LitElement {
</p>
</div>
<ha-form
.schema=${this._schema(this.data?.language, this._supportedLanguages)}
.schema=${this._schema(
this.data?.conversation_engine,
this.data?.language,
this._supportedLanguages
)}
.data=${this.data}
.hass=${this.hass}
.computeLabel=${this._computeLabel}
.computeHelper=${this._computeHelper}
@supported-languages-changed=${this._supportedLanguagesChanged}
></ha-form>
</div>

View File

@ -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 {
<assist-pipeline-detail-conversation
.hass=${this.hass}
.data=${this._data}
keys="conversation_engine,conversation_language"
keys="conversation_engine,conversation_language,prefer_local_intents"
@value-changed=${this._valueChanged}
></assist-pipeline-detail-conversation>
${!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,

View File

@ -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%]",