mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 23:36:36 +00:00
parent
3aafa47f6d
commit
9afc4260c9
@ -1,12 +1,12 @@
|
||||
import type { HomeAssistant } from "../types";
|
||||
|
||||
export interface AITaskPreferences {
|
||||
gen_text_entity_id: string | null;
|
||||
gen_data_entity_id: string | null;
|
||||
}
|
||||
|
||||
export interface GenTextTaskResult {
|
||||
export interface GenDataTaskResult {
|
||||
conversation_id: string;
|
||||
text: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
export const fetchAITaskPreferences = (hass: HomeAssistant) =>
|
||||
@ -23,17 +23,17 @@ export const saveAITaskPreferences = (
|
||||
...preferences,
|
||||
});
|
||||
|
||||
export const generateTextAITask = async (
|
||||
export const generateDataAITask = async (
|
||||
hass: HomeAssistant,
|
||||
task: {
|
||||
task_name: string;
|
||||
entity_id?: string;
|
||||
instructions: string;
|
||||
}
|
||||
): Promise<GenTextTaskResult> => {
|
||||
const result = await hass.callService<GenTextTaskResult>(
|
||||
): Promise<GenDataTaskResult> => {
|
||||
const result = await hass.callService<GenDataTaskResult>(
|
||||
"ai_task",
|
||||
"generate_text",
|
||||
"generate_data",
|
||||
task,
|
||||
undefined,
|
||||
true,
|
||||
|
@ -27,7 +27,7 @@ import type {
|
||||
import { supportsMarkdownHelper } from "../../../../common/translations/markdown_support";
|
||||
import {
|
||||
fetchAITaskPreferences,
|
||||
generateTextAITask,
|
||||
generateDataAITask,
|
||||
} from "../../../../data/ai_task";
|
||||
import { isComponentLoaded } from "../../../../common/config/is_component_loaded";
|
||||
|
||||
@ -93,7 +93,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
|
||||
super.firstUpdated(changedProperties);
|
||||
if (isComponentLoaded(this.hass, "ai_task")) {
|
||||
fetchAITaskPreferences(this.hass).then((prefs) => {
|
||||
this._canSuggest = prefs.gen_text_entity_id !== null;
|
||||
this._canSuggest = prefs.gen_data_entity_id !== null;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -346,7 +346,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
|
||||
}
|
||||
|
||||
private async _suggest() {
|
||||
const result = await generateTextAITask(this.hass, {
|
||||
const result = await generateDataAITask(this.hass, {
|
||||
task_name: "frontend:automation:save",
|
||||
instructions: `Suggest one name for the following Home Assistant automation.
|
||||
Your answer should only contain the name, without any additional text or formatting.
|
||||
@ -356,7 +356,7 @@ The name should be short, descriptive, sentence case, and written in the languag
|
||||
${dump(this._params.config)}
|
||||
`,
|
||||
});
|
||||
this._newName = result.text.trim();
|
||||
this._newName = result.data.trim();
|
||||
}
|
||||
|
||||
private async _save(): Promise<void> {
|
||||
|
@ -47,9 +47,7 @@ export class AITaskPref extends LitElement {
|
||||
})}
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
/>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.ai_task.header"
|
||||
)}
|
||||
/>${this.hass.localize("ui.panel.config.ai_task.header")}
|
||||
</h1>
|
||||
<div class="header-actions">
|
||||
<a
|
||||
@ -68,30 +66,25 @@ export class AITaskPref extends LitElement {
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p>
|
||||
${this.hass!.localize(
|
||||
"ui.panel.config.voice_assistants.ai_task.description",
|
||||
{
|
||||
button: html`<ha-svg-icon
|
||||
.path=${mdiStarFourPoints}
|
||||
></ha-svg-icon>`,
|
||||
}
|
||||
)}
|
||||
${this.hass!.localize("ui.panel.config.ai_task.description", {
|
||||
button: html`<ha-svg-icon
|
||||
.path=${mdiStarFourPoints}
|
||||
></ha-svg-icon>`,
|
||||
})}
|
||||
</p>
|
||||
<ha-settings-row .narrow=${this.narrow}>
|
||||
<span slot="heading">
|
||||
${this.hass!.localize(
|
||||
"ui.panel.config.voice_assistants.ai_task.gen_text_header"
|
||||
)}
|
||||
${this.hass!.localize("ui.panel.config.ai_task.gen_data_header")}
|
||||
</span>
|
||||
<span slot="description">
|
||||
${this.hass!.localize(
|
||||
"ui.panel.config.voice_assistants.ai_task.gen_text_description"
|
||||
"ui.panel.config.ai_task.gen_data_description"
|
||||
)}
|
||||
</span>
|
||||
<ha-entity-picker
|
||||
data-name="gen_text_entity_id"
|
||||
data-name="gen_data_entity_id"
|
||||
.hass=${this.hass}
|
||||
.value=${this._prefs.gen_text_entity_id}
|
||||
.value=${this._prefs.gen_data_entity_id}
|
||||
.includeDomains=${["ai_task"]}
|
||||
@value-changed=${this._handlePrefChange}
|
||||
></ha-entity-picker>
|
||||
@ -119,6 +112,14 @@ export class AITaskPref extends LitElement {
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.card-header img {
|
||||
max-width: 28px;
|
||||
margin-right: 16px;
|
||||
}
|
||||
a {
|
||||
color: var(--primary-color);
|
||||
}
|
@ -25,8 +25,10 @@ import type { ConfigUpdateValues } from "../../../data/core";
|
||||
import { saveCoreConfig } from "../../../data/core";
|
||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import "../../../layouts/hass-subpage";
|
||||
import "./ai-task-pref";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import type { HomeAssistant, ValueChangedEvent } from "../../../types";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
|
||||
@customElement("ha-config-section-general")
|
||||
class HaConfigSectionGeneral extends LitElement {
|
||||
@ -265,6 +267,12 @@ class HaConfigSectionGeneral extends LitElement {
|
||||
</ha-progress-button>
|
||||
</div>
|
||||
</ha-card>
|
||||
${isComponentLoaded(this.hass, "ai_task")
|
||||
? html`<ai-task-pref
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ai-task-pref>`
|
||||
: nothing}
|
||||
</div>
|
||||
</hass-subpage>
|
||||
`;
|
||||
@ -377,7 +385,8 @@ class HaConfigSectionGeneral extends LitElement {
|
||||
max-width: 1040px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
ha-card {
|
||||
ha-card,
|
||||
ai-task-pref {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
height: 100%;
|
||||
@ -385,6 +394,9 @@ class HaConfigSectionGeneral extends LitElement {
|
||||
flex-direction: column;
|
||||
display: flex;
|
||||
}
|
||||
ha-card {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.card-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
@ -8,7 +8,6 @@ import "../../../layouts/hass-loading-screen";
|
||||
import "../../../layouts/hass-tabs-subpage";
|
||||
import type { HomeAssistant, Route } from "../../../types";
|
||||
import "./assist-pref";
|
||||
import "./ai-task-pref";
|
||||
import "./cloud-alexa-pref";
|
||||
import "./cloud-discover";
|
||||
import "./cloud-google-pref";
|
||||
@ -54,12 +53,6 @@ export class HaConfigVoiceAssistantsAssistants extends LitElement {
|
||||
></assist-pref>
|
||||
`
|
||||
: nothing}
|
||||
${isComponentLoaded(this.hass, "ai_task")
|
||||
? html`<ai-task-pref
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ai-task-pref>`
|
||||
: nothing}
|
||||
${this.cloudStatus?.logged_in
|
||||
? html`
|
||||
<cloud-alexa-pref
|
||||
|
@ -2207,6 +2207,12 @@
|
||||
"add_area": "Add area"
|
||||
}
|
||||
},
|
||||
"ai_task": {
|
||||
"header": "AI suggestions",
|
||||
"description": "Home Assistant can use generative AI to help you with tasks like writing automations, creating scripts, and more. Look for the button with the {button} icon throughout Home Assistant to get suggestions.",
|
||||
"gen_data_header": "Data generation tasks",
|
||||
"gen_data_description": "Suggest automation names or dashboards."
|
||||
},
|
||||
"category": {
|
||||
"caption": "Categories",
|
||||
"assign": {
|
||||
@ -3442,12 +3448,6 @@
|
||||
"sign_in": "Sign in"
|
||||
}
|
||||
},
|
||||
"ai_task": {
|
||||
"header": "AI suggestions",
|
||||
"description": "Home Assistant can use generative AI to help you with tasks like writing automations, creating scripts, and more. Look for the button with the {button} icon throughout Home Assistant to get suggestions.",
|
||||
"gen_text_header": "Text generation tasks",
|
||||
"gen_text_description": "Used to create summaries and names."
|
||||
},
|
||||
"debug": {
|
||||
"header": "Debug assistant",
|
||||
"no_runs_found": "No runs found",
|
||||
|
Loading…
x
Reference in New Issue
Block a user