始める無料で始める

Digging into the response

One key skill in working with APIs is extracting the right data from a structured response. Now, you'll practice retrieving the necessary text from an OpenAI API response.

The OpenAI class has already been imported for you from the openai library.

この演習はコースの一部です

Working with DeepSeek in Python

コースを見る

演習の手順

  • Extract the content from the response, which is nested inside the message attribute.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[{"role": "user", "content": "Quick, one-sentence productivity tip."}]
)

# Extract the content from the response
print(response.choices[0].____.____)
コードを編集して実行