ComenzarEmpieza gratis

Using Items for Custom Handling

You're building a chatbot that needs to provide detailed logging for debugging purposes. The chatbot uses a reasoning-enabled model, and you want to create custom output messages that clearly distinguish between reasoning summaries and assistant responses. You have a response object from a previous API call that contains multiple output items.

Este ejercicio forma parte del curso

Working with the OpenAI Responses API

Ver curso

Instrucciones del ejercicio

  • Loop through each item in response.output.
  • Check if the item type is 'reasoning' and print a formatted message showing the reasoning summary if it exists.
  • Check if the item type is 'message' and print a formatted message with the assistant's text output.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Loop through each item in the response output
for item in response.____:
    # Check if the item is a reasoning item
    if item.____ == '____':
        if item.____:
            print(f"Reasoning: {item.____[0]}")
        else:
            print("No reasoning summary found.")   
    
    # Check if the item is a message item
    if item.____ == 'message':
        print(f"Assistant: {item.____[0].text}")
Editar y ejecutar código