1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure OpenAI ServiceのAPIをPowerShellで実行する

Posted at

この記事の目的

いつも間違えるのでメモとして記載する


実行するAPI

Azure OpenAI Service REST API である Chat completions APIを実行する

Azure OpenAI StudioのChat playground で実行されているAPI
image.png


実行方法

PowerShell の Invoke-RestMethod を使用して実行する


実行例

$key = "<api key>"
$AOAIresource = "<Resource 名>"
$model = "<モデル名>"
$apiversion = "<REST APIのバージョン>"
$url = "https://$AOAIresource.openai.azure.com/openai/deployments/$model/chat/completions?api-version=$apiversion"
$headers = @{}
$headers["Content-Type"]  = "application/json"
$headers["api-key"] = "$key"
$body = '{
  "messages": [{"role":"system","content":"You are an AI assistant that helps people find information."},{"role":"user","content":"test"}],
  "max_tokens": 800,
  "temperature": 0.7,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "top_p": 0.95,
  "stop": null
}'


Invoke-RestMethod -Uri $url -Method POST -Headers $headers -Body $body

key などの取得方法はこちらを参照

APIのバージョンはREST APIのリファレンスを参照

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?