From e3e15e765d164454db72ca30290c2d3a4917daf9 Mon Sep 17 00:00:00 2001 From: Aguirre Matteo Date: Thu, 25 Sep 2025 19:15:22 -0300 Subject: [PATCH] aichat: add agents option --- modules/programs/aichat.nix | 56 +++++++++++++++++----- tests/modules/programs/aichat/llama.yaml | 3 ++ tests/modules/programs/aichat/openai.yaml | 5 ++ tests/modules/programs/aichat/settings.nix | 25 +++++++++- 4 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 tests/modules/programs/aichat/llama.yaml create mode 100644 tests/modules/programs/aichat/openai.yaml diff --git a/modules/programs/aichat.nix b/modules/programs/aichat.nix index cba7b0b07..2192abbf1 100644 --- a/modules/programs/aichat.nix +++ b/modules/programs/aichat.nix @@ -11,7 +11,7 @@ let settingsFormat = pkgs.formats.yaml { }; - inherit (pkgs.stdenv.hostPlatform) isLinux isDarwin; + inherit (pkgs.stdenv.hostPlatform) isDarwin; in { meta.maintainers = [ @@ -56,19 +56,53 @@ in for supported values. ''; }; - }; - config = mkIf cfg.enable { - home.packages = mkIf (cfg.package != null) [ cfg.package ]; - - home.file."Library/Application Support/aichat/config.yaml" = - mkIf (cfg.settings != { } && (isDarwin && !config.xdg.enable)) - { - source = settingsFormat.generate "aichat-config" cfg.settings; + agents = lib.mkOption { + type = lib.types.attrsOf settingsFormat.type; + default = { }; + example = { + openai = { + model = "openai:gpt-4o"; + temperature = 0.5; + top_p = 0.7; + use_tools = "fs,web_search"; + agent_prelude = "default"; }; - xdg.configFile."aichat/config.yaml" = mkIf (cfg.settings != { } && (isLinux || config.xdg.enable)) { - source = settingsFormat.generate "aichat-config" cfg.settings; + llama = { + model = "llama3.2:latest"; + temperature = 0.5; + use_tools = "web_search"; + }; + }; + description = '' + Agent-specific configurations. See + + for supported values. + ''; }; }; + + config = + let + aichatConfigPath = + if (isDarwin && !config.xdg.enable) then + "Library/Application Support/aichat" + else + "${lib.removePrefix config.home.homeDirectory config.xdg.configHome}/aichat"; + in + mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + home.file = { + "${aichatConfigPath}/config.yaml" = mkIf (cfg.settings != { }) { + source = settingsFormat.generate "aichat-config" cfg.settings; + }; + } + // (lib.mapAttrs' ( + k: v: + lib.nameValuePair "${aichatConfigPath}/agents/${k}/config.yaml" { + source = settingsFormat.generate "aichat-agent-${k}" v; + } + ) cfg.agents); + }; } diff --git a/tests/modules/programs/aichat/llama.yaml b/tests/modules/programs/aichat/llama.yaml new file mode 100644 index 000000000..5f7e7b0c0 --- /dev/null +++ b/tests/modules/programs/aichat/llama.yaml @@ -0,0 +1,3 @@ +model: llama3.2:latest +temperature: 0.5 +use_tools: web_search diff --git a/tests/modules/programs/aichat/openai.yaml b/tests/modules/programs/aichat/openai.yaml new file mode 100644 index 000000000..e9e771e5c --- /dev/null +++ b/tests/modules/programs/aichat/openai.yaml @@ -0,0 +1,5 @@ +agent_prelude: default +model: openai:gpt-4o +temperature: 0.5 +top_p: 0.7 +use_tools: fs,web_search diff --git a/tests/modules/programs/aichat/settings.nix b/tests/modules/programs/aichat/settings.nix index d8d5085a9..4d81c53a4 100644 --- a/tests/modules/programs/aichat/settings.nix +++ b/tests/modules/programs/aichat/settings.nix @@ -1,4 +1,3 @@ -{ ... }: { programs.aichat = { enable = true; @@ -18,10 +17,34 @@ } ]; }; + + agents = { + openai = { + model = "openai:gpt-4o"; + temperature = 0.5; + top_p = 0.7; + use_tools = "fs,web_search"; + agent_prelude = "default"; + }; + + llama = { + model = "llama3.2:latest"; + temperature = 0.5; + use_tools = "web_search"; + }; + }; }; + nmt.script = '' assertFileExists home-files/.config/aichat/config.yaml assertFileContent home-files/.config/aichat/config.yaml \ ${./settings.yml} + + assertFileExists home-files/.config/aichat/agents/openai/config.yaml + assertFileExists home-files/.config/aichat/agents/llama/config.yaml + assertFileContent home-files/.config/aichat/agents/openai/config.yaml \ + ${./openai.yaml} + assertFileContent home-files/.config/aichat/agents/llama/config.yaml \ + ${./llama.yaml} ''; }