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

Including end-user IDs

You are developing a content moderation tool for a social media company that uses the OpenAI API to assess their content. To ensure the safety and compliance of the tool, you need to incorporate user identification in your API requests, so that investigations can be performed in case malicious content is found.

The uuid library has been preloaded. A message has also been preloaded containing text from a social media post.

Bu egzersiz

Developing AI Systems with the OpenAI API

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

Egzersiz talimatları

  • Use the uuid library with uuid4() to generate a unique ID.
  • Pass the unique ID to the chat completions endpoint to identify the user.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

client = OpenAI(api_key="")

# Generate a unique ID
unique_id = 

response = client.chat.completions.create(  
  model="gpt-4o-mini", 
  messages=messages,
# Pass a user identification key
  ____
)

print(response.choices[0].message.content)
Kodu Düzenle ve Çalıştır