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

Extracting Output Items and Their Contents

When working with OpenAI's Responses API, different item types contain different information. A response object has been created and stored in the variable response. Your task is to loop through the output items and extract specific information based on their type.

Bu egzersiz

Working with the OpenAI Responses API

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

Egzersiz talimatları

  • Loop through the items in response.output.
  • Check if the item's .type attribute equals 'reasoning', and if so, print 'Found reasoning item'.
  • Check if the item's .type attribute equals 'message', and if so, extract and print the text.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Loop through the output items
for item in ____:
    # Check for reasoning items
    if ____ == 'reasoning':
        print('Found reasoning item')
    
    # Check for message items and extract text
    if item.type == 'message':
        message_text = item.____[0].____
        print(message_text)
Kodu Düzenle ve Çalıştır