1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 18:21:07 +01:00
Files
niveum/packages/gpt.nix

16 lines
465 B
Nix
Raw Normal View History

{
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" \
2023-06-21 10:41:06 +02:00
-H "Authorization: Bearer $(${apiKeyCommand})" \
-d "$json" \
| ${jq}/bin/jq -r '.choices[] | .message.content'
''