0
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?

More than 1 year has passed since last update.

APIをたたいてみる①ツールを使ってリクエストを投げる

Last updated at Posted at 2023-11-01

概要

APIを気軽にたたきたいが、何をどうすればたたけるかを軽く検証する。

Azure OpenAI のAPIをたたいてみる

既に準備済のAzure OpenAI のAPIをたたきます。

とりあえずURLだけでたたいてみます。

image.png

このように雑にアクセスすると404が返ってきます。

必須な情報として、APIキーとPOSTするメッセージ情報があります。

これらをリクエストのボディー部分ではなくヘッダー部分に入れなければなりません。

TalendAPITester を使ってみる

image.png

TalendAPITesterはAPIをたたけるツールです。

POSTを選択し、URL等を指定していきます。

Azure OpenAI の公式より、リクエストに必要な情報を調べます。

curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=2023-05-15 \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_API_KEY" \
  -d '{"messages":[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},{"role": "user", "content": "Do other Azure AI services support this too?"}]}'

-Hはヘッダーの意味です。
ヘッダーに
Content-Type : application/json

api-key : Azureで指定されたAPIキーとなる文字列
を入れていきます。
また -d はボディーという意味です。
ボディーにJSON形式で送りたいデータを入力しましょう。

image.png

この状態で右上のSENDを押してみましょう。

image.png

ダメ見たいですね。
公式ページを見るとモデルのバージョン指定がいるようです。

image.png

実行してみたらいい感じでした。

image.png

まとめ

TalendAPITester はめっちゃ使いやすい。
Swaggerもいい感じなので使い分けは必要かも

APIをたたくイメージがつかめた。

追記 : JSON形式のダミーを返すWebサイトを見つけました。

image.png

軽く何かテストしたいときとかに便利ですね

0
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
0
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?