Řetězení konverzací

Working with the OpenAI Responses API

James Chapman

AI Curriculum Manager, DataCamp

Řešení problému konverzace

convo_puzzle1.jpg

Working with the OpenAI Responses API

Řešení problému konverzace

convo_puzzle2.jpg

Working with the OpenAI Responses API

Historie konverzace

response1 = client.responses.create(
    model="gpt-5.4-mini",
    input="Hello, my name is James."
)


print(response1.id) print(response1.output_text)
resp_02c689cbc16a0b9900691b012ec0f88196a5...
Hi James - nice to meet you. How can I help?
response2 = client.responses.create(
    model="gpt-5.4-mini",
    input="What is my name?",
    previous_response_id=response1.id
)


print(response2.id) print(response2.output_text)
resp_02c689cbc16a0b9900691b01327e4c8196aa...
Your name is James.
Working with the OpenAI Responses API

Historie konverzace

response3 = client.responses.create(
    model="gpt-5.4-mini",
    input="Summarize the conversation so far.",
    previous_response_id=response2.id
)


print(response3.id) print(response3.output_text)
resp_02c689cbc16a0b9900691b0133cf9c81969b1e128919fe3760
You told me your name is James. I greeted you and later confirmed your name
when you asked.
Working with the OpenAI Responses API
sys_prompt = "You are a helpful Teacher who provides concise, personalized explanations."

latest_response_id = None
while True: user_input = input("You: ").strip() if user_input.lower() == "exit": break
response = client.responses.create( model="gpt-5.4-mini", instructions=sys_prompt, input=user_input, previous_response_id=latest_response_id )
print(f"\nAssistant: {response.output_text}\n") latest_response_id = response.id
Working with the OpenAI Responses API

response1.gif

Working with the OpenAI Responses API

response2.gif

Working with the OpenAI Responses API

Pojďme procvičovat!

Working with the OpenAI Responses API

Preparing Video For Download...