mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
16 lines
465 B
Nix
16 lines
465 B
Nix
{
|
|
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 $(${apiKeyCommand})" \
|
|
-d "$json" \
|
|
| ${jq}/bin/jq -r '.choices[] | .message.content'
|
|
''
|