Created
April 16, 2025 11:26
-
-
Save okmanideep/487f09d074af3f52a361251f5eaa6c44 to your computer and use it in GitHub Desktop.
GPT in Nushell with a glow up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gpt [query?: string] { | |
let q = if ($query == null) { | |
input '> ' | |
} else { | |
$query | |
} | |
let api_key = $env.OPEN_AI_API_KEY | |
let model = "gpt-4o-mini" | |
let body = { "model": $model, "messages": [ | |
{ "role": "developer", "content": "You are helpful assistant. Be as brief as possible. Simple text output suitable for a terminal" }, | |
{ "role": "user", "content": $q }, | |
] } | to json | |
http post https://api.openai.com/v1/chat/completions --headers [ | |
"Authorization" $"Bearer ($api_key)" | |
"Content-Type" "application/json" | |
] $body | get choices.0.message.content | glow -s dark | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment