Skip to content

Instantly share code, notes, and snippets.

@dfinke
Last active September 20, 2024 02:02
Show Gist options
  • Save dfinke/75c0b31605b39b43f06568abaf581f8e to your computer and use it in GitHub Desktop.
Save dfinke/75c0b31605b39b43f06568abaf581f8e to your computer and use it in GitHub Desktop.
PowerShell script for querying AI models via GitHub API and retrieving chat completions
$prompt = "capital of france?"
$model = "gpt-4o-mini"
# $model = "o1-preview"
$headers = @{
    "Content-Type"  = "application/json"
    "Authorization" = "Bearer $($env:GITHUB_TOKEN)"
}
$body = @{
    "messages" = @(@{"role" = "user"; "content" = $prompt })    
    "model"    = $model
}
$result = Invoke-RestMethod -Method Post -Uri "https://models.inference.ai.azure.com/chat/completions" -Headers $headers -Body ($body | ConvertTo-Json)
$result.choices[0].message.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment