diff --git a/homes/aarch64-darwin/evanreichard@mac-va-mbp-work/default.nix b/homes/aarch64-darwin/evanreichard@mac-va-mbp-work/default.nix index cd67bea..6750d5a 100755 --- a/homes/aarch64-darwin/evanreichard@mac-va-mbp-work/default.nix +++ b/homes/aarch64-darwin/evanreichard@mac-va-mbp-work/default.nix @@ -30,6 +30,7 @@ in k9s = enabled; nvim = enabled; opencode = enabled; + pi = enabled; }; }; diff --git a/modules/home/programs/terminal/pi/default.nix b/modules/home/programs/terminal/pi/default.nix new file mode 100755 index 0000000..125b938 --- /dev/null +++ b/modules/home/programs/terminal/pi/default.nix @@ -0,0 +1,46 @@ +{ lib +, pkgs +, config +, namespace +, ... +}: +let + inherit (lib) mkIf; + + helpers = import ./lib.nix { inherit lib; }; + llamaSwapConfig = import ./../../../../nixos/services/llama-swap/config.nix { inherit pkgs; }; + + cfg = config.${namespace}.programs.terminal.pi; +in +{ + options.${namespace}.programs.terminal.pi = { + enable = lib.mkEnableOption "enable pi"; + }; + + config = mkIf cfg.enable { + # Add Pi Coding Agent to Home Packages + home.packages = with pkgs; [ + reichard.pi-coding-agent + ]; + + # Define Pi Configuration + sops = { + secrets.context7_apikey = { + sopsFile = lib.snowfall.fs.get-file "secrets/common/evanreichard.yaml"; + }; + templates."pi.json" = { + path = "${config.home.homeDirectory}/.pi/agent/models.json"; + content = builtins.toJSON { + providers = { + "llama-swap" = { + baseUrl = "https://llm-api.va.reichard.io/v1"; + api = "openai-completions"; + apiKey = "none"; + models = helpers.toPiModels llamaSwapConfig; + }; + }; + }; + }; + }; + }; +} diff --git a/modules/home/programs/terminal/pi/lib.nix b/modules/home/programs/terminal/pi/lib.nix new file mode 100644 index 0000000..f9c258a --- /dev/null +++ b/modules/home/programs/terminal/pi/lib.nix @@ -0,0 +1,60 @@ +{ lib }: +let + inherit (lib) + mapAttrs + filterAttrs + any + flatten + listToAttrs + nameValuePair + ; +in +{ + toPiModels = + llamaSwapConfig: + let + textGenModels = filterAttrs + ( + name: model: any (t: t == "text-generation") (model.metadata.type or [ ]) + ) + (llamaSwapConfig.models or { }); + + localModels = mapAttrs + ( + name: model: + { + id = name; + inherit (model) name; + } + // ( + if model.macros.ctx or null != null then + { + contextWindow = lib.toInt model.macros.ctx; + } + else + { } + ) + ) + textGenModels; + + peerModels = listToAttrs ( + flatten ( + map + ( + peer: + map + ( + modelName: + nameValuePair modelName { + id = modelName; + name = modelName; + } + ) + peer.models + ) + (builtins.attrValues (llamaSwapConfig.peers or { })) + ) + ); + in + builtins.attrValues (localModels // peerModels); +}