From 026a95d576778cb946c3efa7f156bd3f3f31afe1 Mon Sep 17 00:00:00 2001 From: Alex O'Connell Date: Sat, 4 May 2024 12:59:48 -0400 Subject: [PATCH 1/3] add prompt format for phi-3 --- custom_components/llama_conversation/agent.py | 2 +- custom_components/llama_conversation/const.py | 10 ++++++++++ .../llama_conversation/translations/en.json | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/custom_components/llama_conversation/agent.py b/custom_components/llama_conversation/agent.py index fe2b8df..7df88e8 100644 --- a/custom_components/llama_conversation/agent.py +++ b/custom_components/llama_conversation/agent.py @@ -270,7 +270,7 @@ async def async_process( intent_response = intent.IntentResponse(language=user_input.language) intent_response.async_set_error( intent.IntentResponseErrorCode.UNKNOWN, - f"Sorry, there was a problem talking to the backend: {err}", + f"Sorry, there was a problem talking to the backend: {repr(err)}", ) return ConversationResult( response=intent_response, conversation_id=conversation_id diff --git a/custom_components/llama_conversation/const.py b/custom_components/llama_conversation/const.py index f6e8e47..4c5e14a 100644 --- a/custom_components/llama_conversation/const.py +++ b/custom_components/llama_conversation/const.py @@ -70,6 +70,7 @@ PROMPT_TEMPLATE_NONE = "no_prompt_template" PROMPT_TEMPLATE_ZEPHYR = "zephyr" PROMPT_TEMPLATE_ZEPHYR2 = "zephyr2" +PROMPT_TEMPLATE_ZEPHYR3 = "zephyr3" DEFAULT_PROMPT_TEMPLATE = PROMPT_TEMPLATE_CHATML PROMPT_TEMPLATE_DESCRIPTIONS = { PROMPT_TEMPLATE_CHATML: { @@ -113,6 +114,12 @@ "assistant": { "prefix": "<|assistant|>\n", "suffix": "" }, "generation_prompt": "<|assistant|>\n" }, + PROMPT_TEMPLATE_ZEPHYR3: { + "system": { "prefix": "<|system|>\n", "suffix": "<|end|>" }, + "user": { "prefix": "<|user|>\n", "suffix": "<|end|>" }, + "assistant": { "prefix": "<|assistant|>\n", "suffix": "<|end|>" }, + "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|>"}, @@ -271,6 +278,9 @@ "zephyr": { CONF_PROMPT: DEFAULT_PROMPT_BASE + ICL_EXTRAS, CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_ZEPHYR, + }, + "phi-3": { + CONF_PROMPT_TEMPLATE: PROMPT_TEMPLATE_ZEPHYR3 } } diff --git a/custom_components/llama_conversation/translations/en.json b/custom_components/llama_conversation/translations/en.json index 24afee4..7c5d7ea 100644 --- a/custom_components/llama_conversation/translations/en.json +++ b/custom_components/llama_conversation/translations/en.json @@ -164,6 +164,7 @@ "mistral": "Mistral", "zephyr": "Zephyr (<|endoftext|>)", "zephyr2": "Zephyr ('')", + "zephyr3": "Zephyr (<|end|>)", "llama3": "Llama 3", "no_prompt_template": "None" } From dc79b2615e41f5e39aff6da9f7227836e9567221 Mon Sep 17 00:00:00 2001 From: Alex O'Connell Date: Sat, 4 May 2024 13:23:42 -0400 Subject: [PATCH 2/3] pin dependencies + fix huggingface import error after HA updates --- custom_components/llama_conversation/manifest.json | 6 +++--- custom_components/llama_conversation/utils.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/llama_conversation/manifest.json b/custom_components/llama_conversation/manifest.json index 3079207..32b2da8 100644 --- a/custom_components/llama_conversation/manifest.json +++ b/custom_components/llama_conversation/manifest.json @@ -9,8 +9,8 @@ "integration_type": "service", "iot_class": "local_polling", "requirements": [ - "requests", - "huggingface-hub", - "webcolors" + "requests==2.31.0", + "huggingface-hub==0.23.0", + "webcolors==1.13" ] } diff --git a/custom_components/llama_conversation/utils.py b/custom_components/llama_conversation/utils.py index a42654e..2bd688d 100644 --- a/custom_components/llama_conversation/utils.py +++ b/custom_components/llama_conversation/utils.py @@ -7,7 +7,6 @@ import voluptuous as vol import webcolors from importlib.metadata import version -from huggingface_hub import hf_hub_download, HfFileSystem from homeassistant.requirements import pip_kwargs from homeassistant.util.package import install_package, is_installed @@ -48,6 +47,11 @@ def _flatten(current_schema, prefix=''): return flattened def download_model_from_hf(model_name: str, quantization_type: str, storage_folder: str): + try: + from huggingface_hub import hf_hub_download, HfFileSystem + except Exception as ex: + raise Exception(f"Failed to import huggingface-hub library. Please re-install the integration.") from ex + fs = HfFileSystem() potential_files = [ f for f in fs.glob(f"{model_name}/*.gguf") ] wanted_file = [f for f in potential_files if (f".{quantization_type.lower()}." in f or f".{quantization_type.upper()}." in f)] From 6f2ce8828ee4e303e521a294d06801639f9e7c16 Mon Sep 17 00:00:00 2001 From: Alex O'Connell Date: Sat, 4 May 2024 13:28:51 -0400 Subject: [PATCH 3/3] Release v0.2.16 --- README.md | 1 + custom_components/llama_conversation/const.py | 2 +- custom_components/llama_conversation/manifest.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd06d7b..435bf73 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ In order to facilitate running the project entirely on the system where Home Ass ## Version History | Version | Description | |---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| v0.2.16 | Fix for missing huggingface_hub package preventing startup | | v0.2.15 | Fix startup error when using llama.cpp backend and add flash attention to llama.cpp backend | | v0.2.14 | Fix llama.cpp wheels + AVX detection | | v0.2.13 | Add support for Llama 3, build llama.cpp wheels that are compatible with non-AVX systems, fix an error with exposing script entities, fix multiple small Ollama backend issues, and add basic multi-language support | diff --git a/custom_components/llama_conversation/const.py b/custom_components/llama_conversation/const.py index 4c5e14a..b22a6bd 100644 --- a/custom_components/llama_conversation/const.py +++ b/custom_components/llama_conversation/const.py @@ -284,5 +284,5 @@ } } -INTEGRATION_VERSION = "0.2.15" +INTEGRATION_VERSION = "0.2.16" EMBEDDED_LLAMA_CPP_PYTHON_VERSION = "0.2.69" \ No newline at end of file diff --git a/custom_components/llama_conversation/manifest.json b/custom_components/llama_conversation/manifest.json index 32b2da8..3700ba7 100644 --- a/custom_components/llama_conversation/manifest.json +++ b/custom_components/llama_conversation/manifest.json @@ -1,7 +1,7 @@ { "domain": "llama_conversation", "name": "LLaMA Conversation", - "version": "0.2.15", + "version": "0.2.16", "codeowners": ["@acon96"], "config_flow": true, "dependencies": ["conversation"],