Response Items: The Building Blocks

Working with the OpenAI Responses API

James Chapman

AI Curriculum Manager, DataCamp

The Journey

 

ch1_recap0.jpg

Working with the OpenAI Responses API

The Journey

 

ch1_recap3.jpg

Working with the OpenAI Responses API

The Journey

 

ch1_recap3.jpg

Working with the OpenAI Responses API

The Journey

 

ch1_recap3.jpg

tool_concept.png

Working with the OpenAI Responses API

Your Item Toolbox

for item in response.output:
    print(item)
ResponseReasoningItem(id='rs_0471305df20125be00692440df2ed88193bd532a15ee6ab7dc',
                      summary=[], type='reasoning', content=None, encrypted_content=None,
                      status=None)
ResponseOutputMessage(id='msg_0471305df20125be00692440df642481938921f6bd2c119688',
                      content=[ResponseOutputText(annotations=[], text='The OpenAI...',
                                                  type='output_text', logprobs=[])],
                      role='assistant', status='incomplete', type='message')
Working with the OpenAI Responses API

Items as Building Blocks

for item in response.output:

if item.type == "message":
if item.status == "incomplete":
print("Message cut-off!")
Message cut-off!
Working with the OpenAI Responses API

Items as Building Blocks

for item in response.outputs:

if item.type == "reasoning"
if item.summary: print(f"Reasoning Summary: {item.summary[0]}") else: print("No reasoning summary available.")
if item.type == "message": print(f"Assistant: {item.content[0].output_text}")
No reasoning summary available.

Assistant: The OpenAI...
Working with the OpenAI Responses API

Coming up...

 

Current Item Types

  • 'reasoning'
  • 'message'

 

for item in response.output:
    if item.type == "message":
        if item.status == "incomplete":
            print("Message cut-off!")

 

New Item Types

  • 'web_search_call'
  • 'function_call'
  • 'function_call_output'
Working with the OpenAI Responses API

Let's practice!

Working with the OpenAI Responses API

Preparing Video For Download...