From 3207e56df267927b98785e9acb8ac4b87c86ceb8 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 11 Sep 2024 13:07:51 -0400 Subject: [PATCH] feat(hass): switch to ollama with mistral-nemo --- .../homie/modules/home-assistant/assist.nix | 4 +-- .../modules/home-assistant/bluetooth.nix | 6 +++- .../homie/modules/home-assistant/default.nix | 1 - devices/nos/modules/llm.nix | 2 +- flake.lock | 17 ++++++++++ flake.nix | 6 ++++ inputs.nix | 6 ++++ legacyPackages/hass-components/default.nix | 1 + .../extended-openai-conversation.nix | 33 +++++++++++++++++++ legacyPackages/hass-components/home-llm.nix | 4 ++- 10 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 legacyPackages/hass-components/extended-openai-conversation.nix diff --git a/devices/homie/modules/home-assistant/assist.nix b/devices/homie/modules/home-assistant/assist.nix index 180e4b51..8ac48480 100644 --- a/devices/homie/modules/home-assistant/assist.nix +++ b/devices/homie/modules/home-assistant/assist.nix @@ -1,5 +1,4 @@ { - pkgs, self, wakewords-src, ... @@ -18,7 +17,8 @@ ]; customComponents = builtins.attrValues { - inherit (self.legacyPackages.${pkgs.system}.hass-components) home-llm; + # Switched to HASS Ollama integration + # inherit (self.legacyPackages.${pkgs.system}.hass-components) home-llm; # Home-llm prompt: /* You are 'Homie', a helpful AI Assistant that controls the devices in a house. Complete the following task as instructed. diff --git a/devices/homie/modules/home-assistant/bluetooth.nix b/devices/homie/modules/home-assistant/bluetooth.nix index 5db94f21..c2f100e6 100644 --- a/devices/homie/modules/home-assistant/bluetooth.nix +++ b/devices/homie/modules/home-assistant/bluetooth.nix @@ -4,7 +4,6 @@ pkgs, ... }: { - # Setup Bluetooth hardware.bluetooth = { enable = true; @@ -78,6 +77,11 @@ # Setup MPD services.home-assistant.extraComponents = [ "mpd" + + # BT components + "ibeacon" + "led_ble" + "kegtron" ]; services.mpd = { enable = true; diff --git a/devices/homie/modules/home-assistant/default.nix b/devices/homie/modules/home-assistant/default.nix index 27cba9e3..c7f9f1db 100644 --- a/devices/homie/modules/home-assistant/default.nix +++ b/devices/homie/modules/home-assistant/default.nix @@ -14,7 +14,6 @@ "caldav" "holiday" "isal" - "led_ble" "met" "spotify" "upnp" diff --git a/devices/nos/modules/llm.nix b/devices/nos/modules/llm.nix index ef2e435a..2b5684fa 100644 --- a/devices/nos/modules/llm.nix +++ b/devices/nos/modules/llm.nix @@ -26,7 +26,7 @@ in { host = tailscaleIP; port = 11434; - loadModels = ["fixt/home-3b-v3"]; + loadModels = ["mistral-nemo"]; environmentVariables.OLLAMA_DEBUG = "1"; }; }; diff --git a/flake.lock b/flake.lock index 5d374195..d371afbd 100644 --- a/flake.lock +++ b/flake.lock @@ -233,6 +233,22 @@ "type": "github" } }, + "extended-openai-conversation-src": { + "flake": false, + "locked": { + "lastModified": 1708531177, + "narHash": "sha256-BwBroYcPQX3pv4iFR1ynmC5xQRTVAFAsOGfDGyXkES4=", + "owner": "jekalmin", + "repo": "extended_openai_conversation", + "rev": "1b20b56e81e5e5067b72a2ba2c8f51dd0a73eef1", + "type": "github" + }, + "original": { + "owner": "jekalmin", + "repo": "extended_openai_conversation", + "type": "github" + } + }, "firefox-gx-src": { "flake": false, "locked": { @@ -1677,6 +1693,7 @@ "dracul-ha-src": "dracul-ha-src", "dracula-plymouth-src": "dracula-plymouth-src", "eisa-scripts-src": "eisa-scripts-src", + "extended-openai-conversation-src": "extended-openai-conversation-src", "firefox-gx-src": "firefox-gx-src", "flake-utils": "flake-utils", "flakegen": "flakegen", diff --git a/flake.nix b/flake.nix index 6d49bbbc..64235186 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,12 @@ repo = "mpv-scripts"; type = "github"; }; + extended-openai-conversation-src = { + flake = false; + owner = "jekalmin"; + repo = "extended_openai_conversation"; + type = "github"; + }; firefox-gx-src = { flake = false; owner = "Godiesc"; diff --git a/inputs.nix b/inputs.nix index d6ed7526..7fe82421 100644 --- a/inputs.nix +++ b/inputs.nix @@ -181,6 +181,12 @@ let owner = "acon96"; repo = "home-llm"; } + { + name = "extended-openai-conversation-src"; + owner = "jekalmin"; + repo = "extended_openai_conversation"; + } + { name = "wakewords-src"; owner = "fwartner"; diff --git a/legacyPackages/hass-components/default.nix b/legacyPackages/hass-components/default.nix index 6a1e5f53..9b3c3027 100644 --- a/legacyPackages/hass-components/default.nix +++ b/legacyPackages/hass-components/default.nix @@ -4,4 +4,5 @@ pkgs.lib.makeScope pkgs.newScope (hass: let hass.callPackage file (inputs // {}); in { home-llm = buildHassComponent ./home-llm.nix; + extended-openai-conversation = buildHassComponent ./extended-openai-conversation.nix; }) diff --git a/legacyPackages/hass-components/extended-openai-conversation.nix b/legacyPackages/hass-components/extended-openai-conversation.nix new file mode 100644 index 00000000..67c8bd73 --- /dev/null +++ b/legacyPackages/hass-components/extended-openai-conversation.nix @@ -0,0 +1,33 @@ +{ + extended-openai-conversation-src, + buildHomeAssistantComponent, + fetchFromGitHub, + python312Packages, + ... +}: let + inherit (builtins) fromJSON readFile; + + manifest = fromJSON (readFile "${extended-openai-conversation-src}/custom_components/extended_openai_conversation/manifest.json"); + + openai = python312Packages.openai.overrideAttrs (o: rec { + version = "1.3.8"; + + src = fetchFromGitHub { + owner = "openai"; + repo = "openai-python"; + rev = "refs/tags/v${version}"; + hash = "sha256-yU0XWEDYl/oBPpYNFg256H0Hn5AaJiP0vOQhbRLnAxQ="; + }; + + disabledTests = o.disabledTests ++ ["test_retrying_timeout_errors_doesnt_leak" "test_retrying_status_errors_doesnt_leak"]; + }); +in + buildHomeAssistantComponent { + owner = "jekalmin"; + + inherit (manifest) domain version; + + src = extended-openai-conversation-src; + + propagatedBuildInputs = [openai]; + } diff --git a/legacyPackages/hass-components/home-llm.nix b/legacyPackages/hass-components/home-llm.nix index 90c864f5..97d45505 100644 --- a/legacyPackages/hass-components/home-llm.nix +++ b/legacyPackages/hass-components/home-llm.nix @@ -4,7 +4,9 @@ python3Packages, ... }: let - manifest = builtins.fromJSON (builtins.readFile "${home-llm-src}/custom_components/llama_conversation/manifest.json"); + inherit (builtins) fromJSON readFile; + + manifest = fromJSON (readFile "${home-llm-src}/custom_components/llama_conversation/manifest.json"); in buildHomeAssistantComponent { owner = "acon96";