handle other languages in component

This commit is contained in:
Alex O'Connell
2024-04-21 20:38:46 -04:00
parent 33a6cd96ed
commit 3326bd7d6e
6 changed files with 62 additions and 30 deletions

View File

@@ -79,7 +79,8 @@ from .const import (
DEFAULT_PORT,
DEFAULT_SSL,
DEFAULT_MAX_TOKENS,
DEFAULT_PROMPT,
PERSONA_PROMPTS,
DEFAULT_PROMPT_BASE,
DEFAULT_TEMPERATURE,
DEFAULT_TOP_K,
DEFAULT_TOP_P,
@@ -553,7 +554,7 @@ class ConfigFlow(BaseLlamaConversationConfigFlow, config_entries.ConfigFlow, dom
if key in model_name:
selected_default_options.update(OPTIONS_OVERRIDES[key])
schema = vol.Schema(local_llama_config_option_schema(selected_default_options, backend_type))
schema = vol.Schema(local_llama_config_option_schema(selected_default_options, backend_type, self.hass.config.language))
if user_input:
self.options = user_input
@@ -630,6 +631,7 @@ class OptionsFlow(config_entries.OptionsFlow):
schema = local_llama_config_option_schema(
self.config_entry.options,
self.config_entry.data[CONF_BACKEND_TYPE],
self.hass.config.language
)
return self.async_show_form(
step_id="init",
@@ -651,16 +653,19 @@ def insert_after_key(input_dict: dict, key_name: str, other_dict: dict):
return result
def local_llama_config_option_schema(options: MappingProxyType[str, Any], backend_type: str) -> dict:
def local_llama_config_option_schema(options: MappingProxyType[str, Any], backend_type: str, language: str) -> dict:
"""Return a schema for Local LLaMA completion options."""
if not options:
options = DEFAULT_OPTIONS
persona = PERSONA_PROMPTS.get(language, PERSONA_PROMPTS.get("en"))
options[CONF_PROMPT] = options[CONF_PROMPT].replace("<persona>", persona)
result = {
vol.Required(
CONF_PROMPT,
description={"suggested_value": options.get(CONF_PROMPT)},
default=DEFAULT_PROMPT,
default=options[CONF_PROMPT],
): TemplateSelector(),
vol.Required(
CONF_PROMPT_TEMPLATE,

View File

@@ -3,26 +3,26 @@ import types, os
DOMAIN = "llama_conversation"
CONF_PROMPT = "prompt"
DEFAULT_PROMPT = """You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task ask instructed with the information provided only.
PERSONA_PROMPTS = {
"en": "You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task as instructed with the information provided only.",
"de": "Du bist \u201eAl\u201c, ein hilfreicher KI-Assistent, der die Ger\u00e4te in einem Haus steuert. F\u00fchren Sie die folgende Aufgabe gem\u00e4\u00df den Anweisungen durch oder beantworten Sie die folgende Frage nur mit den bereitgestellten Informationen.",
"fr": "Vous \u00eates \u00ab\u00a0Al\u00a0\u00bb, un assistant IA utile qui contr\u00f4le les appareils d'une maison. Effectuez la t\u00e2che suivante comme indiqu\u00e9 ou r\u00e9pondez \u00e0 la question suivante avec les informations fournies uniquement.",
"es": "Eres 'Al', un \u00fatil asistente de IA que controla los dispositivos de una casa. Complete la siguiente tarea seg\u00fan las instrucciones o responda la siguiente pregunta \u00fanicamente con la informaci\u00f3n proporcionada.",
}
DEFAULT_PROMPT_BASE = """<persona>
The current time and date is {{ (as_timestamp(now()) | timestamp_custom("%I:%M %p on %A %B %d, %Y", "")) }}
Services: {{ services }}
Devices:
{{ devices }}
{{ devices }}"""
ICL_EXTRAS = """
Respond to the following user instruction by responding in the same format as the following examples:
{{ response_examples }}"""
ICL_NO_SYSTEM_PROMPT = """You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task ask instructed with the information provided only.
Services: {{ services }}
Devices:
{{ devices }}
ICL_NO_SYSTEM_PROMPT_EXTRAS = """
Respond to the following user instruction by responding in the same format as the following examples:
{{ response_examples }}
User instruction:"""
NO_ICL_PROMPT = """You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task ask instructed with the information provided only.
Services: {{ services }}
Devices:
{{ devices }}"""
DEFAULT_PROMPT = DEFAULT_PROMPT_BASE + ICL_EXTRAS
CONF_CHAT_MODEL = "huggingface_model"
DEFAULT_CHAT_MODEL = "acon96/Home-3B-v3-GGUF"
RECOMMENDED_CHAT_MODELS = [ "acon96/Home-3B-v3-GGUF", "acon96/Home-1B-v2-GGUF", "TheBloke/Mistral-7B-Instruct-v0.2-GGUF" ]
@@ -56,7 +56,7 @@ DEFAULT_DOWNLOADED_MODEL_FILE = ""
DEFAULT_PORT = "5000"
DEFAULT_SSL = False
CONF_EXTRA_ATTRIBUTES_TO_EXPOSE = "extra_attributes_to_expose"
DEFAULT_EXTRA_ATTRIBUTES_TO_EXPOSE = ["rgb_color", "brightness", "temperature", "humidity", "fan_mode", "media_title", "volume_level", "item"]
DEFAULT_EXTRA_ATTRIBUTES_TO_EXPOSE = ["rgb_color", "brightness", "temperature", "humidity", "fan_mode", "media_title", "volume_level", "item", "wind_speed"]
CONF_ALLOWED_SERVICE_CALL_ARGUMENTS = "allowed_service_call_arguments"
DEFAULT_ALLOWED_SERVICE_CALL_ARGUMENTS = ["rgb_color", "brightness", "temperature", "humidity", "fan_mode", "hvac_mode", "preset_mode", "item", "duration"]
CONF_PROMPT_TEMPLATE = "prompt_template"
@@ -64,7 +64,7 @@ PROMPT_TEMPLATE_CHATML = "chatml"
PROMPT_TEMPLATE_ALPACA = "alpaca"
PROMPT_TEMPLATE_VICUNA = "vicuna"
PROMPT_TEMPLATE_MISTRAL = "mistral"
PROMPT_TEMPLATE_LLAMA2 = "llama2"
PROMPT_TEMPLATE_LLAMA3 = "llama3"
PROMPT_TEMPLATE_NONE = "no_prompt_template"
PROMPT_TEMPLATE_ZEPHYR = "zephyr"
DEFAULT_PROMPT_TEMPLATE = PROMPT_TEMPLATE_CHATML
@@ -103,6 +103,12 @@ PROMPT_TEMPLATE_DESCRIPTIONS = {
"user": { "prefix": "<|user|>\n", "suffix": "<|endoftext|>" },
"assistant": { "prefix": "<|assistant|>\n", "suffix": "<|endoftext|>" },
"generation_prompt": "<|assistant|>\n"
},
PROMPT_TEMPLATE_LLAMA3: {
"system": { "prefix": "<|start_header_id|>system<|end_header_id|>\n\n", "suffix": "<|eot_id|>"},
"user": { "prefix": "<|start_header_id|>user<|end_header_id|>\n\n", "suffix": "<|eot_id|>"},
"assistant": { "prefix": "<|start_header_id|>assistant<|end_header_id|>\n\n", "suffix": "<|eot_id|>"},
"generation_prompt": "<|start_header_id|>assistant<|end_header_id|>\n\n"
}
}
CONF_USE_GBNF_GRAMMAR = "gbnf_grammar"
@@ -188,45 +194,47 @@ DEFAULT_OPTIONS = types.MappingProxyType(
OPTIONS_OVERRIDES = {
"home-3b-v3": {
CONF_PROMPT: NO_ICL_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE,
CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_ZEPHYR,
CONF_USE_IN_CONTEXT_LEARNING_EXAMPLES: False,
CONF_SERVICE_CALL_REGEX: FINE_TUNED_SERVICE_CALL_REGEX,
CONF_USE_GBNF_GRAMMAR: True,
},
"home-3b-v2": {
CONF_PROMPT: NO_ICL_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE,
CONF_USE_IN_CONTEXT_LEARNING_EXAMPLES: False,
CONF_SERVICE_CALL_REGEX: FINE_TUNED_SERVICE_CALL_REGEX,
CONF_USE_GBNF_GRAMMAR: True,
},
"home-3b-v1": {
CONF_PROMPT: NO_ICL_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE,
CONF_USE_IN_CONTEXT_LEARNING_EXAMPLES: False,
CONF_SERVICE_CALL_REGEX: FINE_TUNED_SERVICE_CALL_REGEX,
},
"home-1b-v2": {
CONF_PROMPT: NO_ICL_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE,
CONF_USE_IN_CONTEXT_LEARNING_EXAMPLES: False,
CONF_SERVICE_CALL_REGEX: FINE_TUNED_SERVICE_CALL_REGEX,
},
"home-1b-v1": {
CONF_PROMPT: NO_ICL_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE,
CONF_USE_IN_CONTEXT_LEARNING_EXAMPLES: False,
CONF_SERVICE_CALL_REGEX: FINE_TUNED_SERVICE_CALL_REGEX,
},
"mistral": {
CONF_PROMPT: ICL_NO_SYSTEM_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE + ICL_NO_SYSTEM_PROMPT_EXTRAS,
CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_MISTRAL,
},
"mixtral": {
CONF_PROMPT: ICL_NO_SYSTEM_PROMPT,
CONF_PROMPT: DEFAULT_PROMPT_BASE + ICL_NO_SYSTEM_PROMPT_EXTRAS,
CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_MISTRAL,
},
"llama-2": {
CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_LLAMA2,
"llama-3": {
CONF_PROMPT: DEFAULT_PROMPT_BASE + ICL_EXTRAS,
CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_LLAMA3,
},
"zephyr": {
CONF_PROMPT: DEFAULT_PROMPT_BASE + ICL_EXTRAS,
CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_ZEPHYR,
}
}

View File

@@ -159,6 +159,7 @@
"alpaca": "Alpaca",
"mistral": "Mistral",
"zephyr": "Zephyr",
"llama-3": "Llama 3",
"no_prompt_template": "None"
}
},

View File

@@ -1,5 +1,5 @@
<|im_start|>system
You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task ask instructed with the information provided only.
You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task as instructed with the information provided only.
Services: cover.open_cover(), cover.close_cover(), cover.set_cover_position(), cover.stop_cover(), cover.toggle(), cover.open_cover_tilt(), cover.close_cover_tilt(), cover.stop_cover_tilt(), cover.set_cover_tilt_position(), cover.toggle_cover_tilt(), media_player.turn_on(), media_player.turn_off(), media_player.toggle(), media_player.volume_up(), media_player.volume_down(), media_player.media_play_pause(), media_player.media_play(), media_player.media_pause(), media_player.media_stop(), media_player.media_next_track(), media_player.media_previous_track(), media_player.clear_playlist(), media_player.volume_set(volume_level), media_player.volume_mute(), media_player.media_seek(), media_player.join(), media_player.select_source(), media_player.select_sound_mode(), media_player.play_media(), media_player.shuffle_set(), media_player.unjoin(), media_player.repeat_set(), climate.turn_on(), climate.turn_off(), climate.set_hvac_mode(), climate.set_preset_mode(), climate.set_aux_heat(), climate.set_temperature(temperature), climate.set_humidity(humidity), climate.set_fan_mode(fan_mode), climate.set_swing_mode(), lock.unlock(), lock.lock(), lock.open(), fan.turn_on(), fan.turn_off(), fan.toggle(), fan.increase_speed(), fan.decrease_speed(), fan.oscillate(), fan.set_direction(), fan.set_percentage(), fan.set_preset_mode(), light.turn_on(rgb_color,brightness), light.turn_off(), light.toggle(rgb_color,brightness)
Devices:
media_player.bedroom 'Bedroom' = playing;Epic sax guy 10 hours;vol=100

View File

@@ -1,5 +1,5 @@
<|system|>
You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task ask instructed with the information provided only.
You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task as instructed with the information provided only.
Services: cover.open_cover(), cover.close_cover(), cover.set_cover_position(), cover.stop_cover(), cover.toggle(), cover.open_cover_tilt(), cover.close_cover_tilt(), cover.stop_cover_tilt(), cover.set_cover_tilt_position(), cover.toggle_cover_tilt(), media_player.turn_on(), media_player.turn_off(), media_player.toggle(), media_player.volume_up(), media_player.volume_down(), media_player.media_play_pause(), media_player.media_play(), media_player.media_pause(), media_player.media_stop(), media_player.media_next_track(), media_player.media_previous_track(), media_player.clear_playlist(), media_player.volume_set(volume_level), media_player.volume_mute(), media_player.media_seek(), media_player.join(), media_player.select_source(), media_player.select_sound_mode(), media_player.play_media(), media_player.shuffle_set(), media_player.unjoin(), media_player.repeat_set(), climate.turn_on(), climate.turn_off(), climate.set_hvac_mode(), climate.set_preset_mode(), climate.set_aux_heat(), climate.set_temperature(temperature), climate.set_humidity(humidity), climate.set_fan_mode(fan_mode), climate.set_swing_mode(), lock.unlock(), lock.lock(), lock.open(), fan.turn_on(), fan.turn_off(), fan.toggle(), fan.increase_speed(), fan.decrease_speed(), fan.oscillate(), fan.set_direction(), fan.set_percentage(), fan.set_preset_mode(), light.turn_on(rgb_color,brightness), light.turn_off(), light.toggle(rgb_color,brightness)
Devices:
media_player.bedroom 'Bedroom' = playing;Epic sax guy 10 hours;vol=100

View File

@@ -33,6 +33,24 @@ Robo the Robot - Sounds like a robot
You are 'Robo', a helpful AI Robot that controls the devices in a house. Complete the following task as instructed or answer the following question with the information provided only. Your response should be robotic and always begin with 'Beep-Boop'.
```
### Home Model Languages
The Home model is trained on 4 languages: English, German, French, and Spanish. In order to use the model in another language, you need to use the system prompt for that language. Each persona listed above also exists in each language.
**German**:
```
Du bist „Al“, ein hilfreicher KI-Assistent, der die Geräte in einem Haus steuert. Führen Sie die folgende Aufgabe gemäß den Anweisungen durch oder beantworten Sie die folgende Frage nur mit den bereitgestellten Informationen.
```
**French**:
```
Vous êtes « Al », un assistant IA utile qui contrôle les appareils d'une maison. Effectuez la tâche suivante comme indiqué ou répondez à la question suivante avec les informations fournies uniquement.
```
**Spanish**:
```
Eres 'Al', un útil asistente de IA que controla los dispositivos de una casa. Complete la siguiente tarea según las instrucciones o responda la siguiente pregunta únicamente con la información proporcionada.
```
## Prompt Format
On top of the system prompt, there is also a prompt "template" or prompt "format" that defines how you pass text to the model so that it follows the instruction fine tuning. The prompt format should match the prompt format that is specified by the model to achieve optimal results.
@@ -53,7 +71,7 @@ Then, navigate to the conversation agent's configuration page and set the follow
System Prompt:
```
You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task ask instructed with the information provided only.
You are 'Al', a helpful AI Assistant that controls the devices in a house. Complete the following task as instructed with the information provided only.
Services: {{ services }}
Devices:
{{ devices }}