BaşlayınÜcretsiz Başlayın

Creating the get_response() function

Most of the exercises in this course will call the chat.completions endpoint of the OpenAI API with a user prompt. Here, you will create a get_response() function that receives a prompt as input and returns the response as an output, which in future exercises will be pre-loaded for you.

The OpenAI package, and OpenAI API Python client have been pre-loaded.

Bu egzersiz

Prompt Engineering with the OpenAI API

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a request to the chat.completions endpoint inside the get_response() function.
  • Try out the function with a prompt that asks the model to write a poem about ChatGPT.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

def get_response(prompt):
  # Create a request to the chat completions endpoint
  response = client.____.____.____(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": prompt}], 
    temperature = 0)
  return response.choices[0].message.content

# Test the function with your prompt
response = get_response("____")
print(response)
Kodu Düzenle ve Çalıştır