Skip to content

Instantly share code, notes, and snippets.

@loxal
Last active August 30, 2025 19:18
Show Gist options
  • Save loxal/e1a291738b750335c5ed69e8a7b8a06b to your computer and use it in GitHub Desktop.
Save loxal/e1a291738b750335c5ed69e8a7b8a06b to your computer and use it in GitHub Desktop.
Grok Nushell Prompt via `? Who are you?`
# Sample prompt for the custom Nushell command below: `? Who are you?` with a rather deterministic response like "I am Grok, an AI built by xAI."
def ? [...user_prompt_phrase: string, --model (-m): string = "grok-code-fast-1"] {
let antrophic_ai_endpoint = "https://api.x.ai/v1/chat/completions"
let user_prompt = ($user_prompt_phrase | str join " ")
let body = {
model: $model,
messages: [
{ role: "system", content: "You answer as short as possible, with one word if possible. The response is intended to be rendered in a Nushell terminal." },
{ role: "user", content: $user_prompt }
],
temperature: 0.0,
stream: false
}
let ai_response = (http post --content-type application/json --headers {Authorization: $"Bearer ($env.XAI_API_KEY)"} $antrophic_ai_endpoint $body)
$ai_response | get choices.0.message.content
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment