LoginSignup
0
0

More than 1 year has passed since last update.

Httpie: ChatGPT API の使い方

Last updated at Posted at 2023-04-08

こちらのページを Httpie で書いてみました。
Curl: ChatGPT API の使い方

スクリプト

http_fuji_a.sh
API_KEY="sk-****************'
http https://api.openai.com/v1/chat/completions \
  'Authorization: Bearer '$API_KEY \
	model="gpt-3.5-turbo" \
    messages:='[{"role": "user", "content": "富士山の高さは"}]' > out01.json
#
jq .choices[0].message out01.json

入力ファイルを使った場合

http_fuji_b.sh
API_KEY="sk-****************'
http https://api.openai.com/v1/chat/completions \
  'Authorization: Bearer '$API_KEY \
  @in01.json > out01.json
#
jq .choices[0].message out01.json
in01.json
{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "富士山の高さは"}]
}

実行結果

./http_fuji_a.sh
{
  "role": "assistant",
  "content": "富士山の高さは3,776.24メートルです。"
}
./http_fuji_b.sh
{
  "role": "assistant",
  "content": "3,776.24メートルです。"
}

何度も同じ質問を繰り返すとこんな答えが返ってきます。

{
  "role": "assistant",
  "content": "3776メートルです。ただし、気象庁が公表する高度は、富士山の標高基準面からの高さである3,776.24メートルになります。"
}

確認したバージョン

$ http --version
3.2.1
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