From 761e0487ee36df4bc2b704262c756a88646e9483 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Mon, 2 Sep 2024 22:14:49 -0400 Subject: [PATCH] feat(hass): use LLM as voice assistant --- devices/homie/modules/home-assistant.nix | 6 ++++++ devices/nos/default.nix | 1 + devices/nos/modules/ollama.nix | 11 ++++++++++ flake.lock | 17 +++++++++++++++ flake.nix | 6 ++++++ inputs.nix | 4 ++++ legacyPackages/default.nix | 1 + legacyPackages/hass-addons/default.nix | 7 ++++++ legacyPackages/hass-addons/home-llm.nix | 27 ++++++++++++++++++++++++ 9 files changed, 80 insertions(+) create mode 100644 devices/nos/modules/ollama.nix create mode 100644 legacyPackages/hass-addons/default.nix create mode 100644 legacyPackages/hass-addons/home-llm.nix diff --git a/devices/homie/modules/home-assistant.nix b/devices/homie/modules/home-assistant.nix index 2bbcbcfe..329b6ed4 100644 --- a/devices/homie/modules/home-assistant.nix +++ b/devices/homie/modules/home-assistant.nix @@ -1,4 +1,5 @@ { + pkgs, self, wakewords-src, ... @@ -13,12 +14,17 @@ "esphome" "holiday" "met" + "ollama" "spotify" "upnp" "wyoming" "yamaha_musiccast" ]; + customComponents = builtins.attrValues { + inherit (self.legacyPackages.${pkgs.system}.hass-addons) home-llm; + }; + config = { http = { server_host = "0.0.0.0"; diff --git a/devices/nos/default.nix b/devices/nos/default.nix index 6c6ff512..4ffefb8d 100644 --- a/devices/nos/default.nix +++ b/devices/nos/default.nix @@ -14,6 +14,7 @@ in { ./modules/docker ./modules/jellyfin ./modules/mergerfs.nix + ./modules/ollama.nix ./modules/qbittorrent ./modules/snapraid.nix ./modules/subtitles diff --git a/devices/nos/modules/ollama.nix b/devices/nos/modules/ollama.nix new file mode 100644 index 00000000..f9325d7c --- /dev/null +++ b/devices/nos/modules/ollama.nix @@ -0,0 +1,11 @@ +{...}: { + services.ollama = { + enable = true; + acceleration = "cuda"; + + host = "100.64.0.4"; + port = 11434; + + loadModels = ["fixt/home-3b-v3"]; + }; +} diff --git a/flake.lock b/flake.lock index 966ec85b..7a990d1b 100644 --- a/flake.lock +++ b/flake.lock @@ -495,6 +495,22 @@ "type": "github" } }, + "home-llm-src": { + "flake": false, + "locked": { + "lastModified": 1724280404, + "narHash": "sha256-mfMnESuXJH8vCzBcvv3lzhV7k/Hg1GfZn/4055dVuqk=", + "owner": "acon96", + "repo": "home-llm", + "rev": "90c0edc0907e4567eeca89a6f89b43c0b0b807eb", + "type": "github" + }, + "original": { + "owner": "acon96", + "repo": "home-llm", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -1653,6 +1669,7 @@ "gtk-session-lock": "gtk-session-lock", "gtk-theme-src": "gtk-theme-src", "headscale": "headscale", + "home-llm-src": "home-llm-src", "home-manager": "home-manager", "hyprgrass": "hyprgrass", "hyprland": "hyprland", diff --git a/flake.nix b/flake.nix index 3c5665d0..1401c9da 100644 --- a/flake.nix +++ b/flake.nix @@ -111,6 +111,12 @@ rev = "022fb24cd92035470496d50d86bf8c9ee74b1e7e"; type = "github"; }; + home-llm-src = { + flake = false; + owner = "acon96"; + repo = "home-llm"; + type = "github"; + }; home-manager = { inputs.nixpkgs.follows = "nixpkgs"; owner = "nix-community"; diff --git a/inputs.nix b/inputs.nix index 025bd5b9..b5df1663 100644 --- a/inputs.nix +++ b/inputs.nix @@ -177,6 +177,10 @@ let srcs = [ # Home-assistant + { + owner = "acon96"; + repo = "home-llm"; + } { name = "wakewords-src"; owner = "fwartner"; diff --git a/legacyPackages/default.nix b/legacyPackages/default.nix index b85a2dbf..515d7fa0 100644 --- a/legacyPackages/default.nix +++ b/legacyPackages/default.nix @@ -11,6 +11,7 @@ (pkgs.callPackage file ({inherit mkVersion;} // inputs)); in { dracula = mkScope ./dracula; + hass-addons = mkScope ./hass-addons; firefoxAddons = mkScope ./firefox-addons; mpvScripts = mkScope ./mpv-scripts; } diff --git a/legacyPackages/hass-addons/default.nix b/legacyPackages/hass-addons/default.nix new file mode 100644 index 00000000..7077bcfa --- /dev/null +++ b/legacyPackages/hass-addons/default.nix @@ -0,0 +1,7 @@ +{pkgs, ...} @ inputs: +pkgs.lib.makeScope pkgs.newScope (hass: let + buildHassAddon = file: + hass.callPackage file (inputs // {}); +in { + home-llm = buildHassAddon ./home-llm.nix; +}) diff --git a/legacyPackages/hass-addons/home-llm.nix b/legacyPackages/hass-addons/home-llm.nix new file mode 100644 index 00000000..66121d3f --- /dev/null +++ b/legacyPackages/hass-addons/home-llm.nix @@ -0,0 +1,27 @@ +{ + buildHomeAssistantComponent, + home-llm-src, + python3Packages, + ... +}: let + manifest = builtins.fromJSON (builtins.readFile "${home-llm-src}/custom_components/llama_conversation/manifest.json"); +in + buildHomeAssistantComponent { + owner = "acon96"; + + inherit (manifest) domain version; + + src = home-llm-src; + + postPatch = '' + substituteInPlace ./custom_components/llama_conversation/manifest.json \ + --replace-warn "huggingface-hub==0.23.0" "huggingface-hub>=0.23.0" \ + --replace-warn "webcolors<=1.13" "webcolors>=1.13" + ''; + + propagatedBuildInputs = with python3Packages; [ + huggingface-hub + requests + webcolors + ]; + }