Skip to content

Instantly share code, notes, and snippets.

@okmanideep
Created April 16, 2025 11:26
Show Gist options
  • Save okmanideep/487f09d074af3f52a361251f5eaa6c44 to your computer and use it in GitHub Desktop.
Save okmanideep/487f09d074af3f52a361251f5eaa6c44 to your computer and use it in GitHub Desktop.
GPT in Nushell with a glow up
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