MulaiMulai sekarang secara gratis

Building an OpenAI API request

Throughout the course, you'll write Python code to interact with the OpenAI API. Entering your own API key is not necessary to create requests and complete the exercises in this course.

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

Latihan ini adalah bagian dari kursus

Working with the OpenAI API

Lihat Kursus

Petunjuk latihan

  • Create an OpenAI API client (keep <OPENAI_API_TOKEN> unchanged).
  • create a request to the Chat Completions endpoint.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create the OpenAI client
client = ____(api_key="")

# Create a request to the Chat Completions endpoint
response = client.chat.completions.____(
  model="gpt-4o-mini",
  messages=[
    {"role": "user", 
     "content": "Write a polite reply accepting an AI Engineer job offer."}]
)

print(response.choices[0].message.content)
Edit dan Jalankan Kode