1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

feat(kleim): add gpt, do not remove newlines

This commit is contained in:
2023-05-03 12:34:39 +02:00
parent 8be6375bcb
commit c17884a519
4 changed files with 19 additions and 1 deletions

15
packages/gpt.nix Normal file
View File

@@ -0,0 +1,15 @@
{
curl,
writers,
jq,
apiKeyCommand ? "pass api-keys/openai.com",
model ? "gpt-3.5-turbo",
}:
writers.writeDashBin "gpt" ''
json=$(jq --slurp --raw-input '{model:"${model}", messages: [{role: "user", content: .}]}')
${curl}/bin/curl -sSL https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(pass api-keys/openai.com)" \
-d "$json" \
| ${jq}/bin/jq -r '.choices[] | .message.content'
''

View File

@@ -49,7 +49,6 @@ in
${lib.concatStringsSep "\n" (lib.mapAttrsToList scriptCase cfg.scripts)}
*) ${pkgs.coreutils}/bin/cat ;;
esac \
| tr -d '\r\n' \
| ${pkgs.xclip}/bin/xclip -selection ${cfg.selection} -in
${pkgs.libnotify}/bin/notify-send --app-name="klem" "Result copied to clipboard."