You are extending a single-file Python chat client for a model deployed in Microsoft Foundry. The file already creates an authenticated client object with OpenAI(...) and stores the deployment name in deployment_name.
The client must meet these requirements:
- The system instruction
You are a computing history tutor. Keep answers brief.must apply to every request. - The second prompt,
Which programming language did she help create?, must be answered in the context of the first prompt,Who was Grace Hopper?. - The app manages the conversation history itself, in a Python list named
messagesthat is passed asinputon every call. The messages must stay in the order in which the conversation happened. - Both replies must be printed.
Which actions should you add to the client? Place the required actions in the correct order and leave out any actions that are not needed.
You didn't answer this one.
messages with a system message ({"role": "system", "content": "You are a computing history tutor. Keep answers brief."}) followed by the first user message ({"role": "user", "content": "Who was Grace Hopper?"}).response = client.responses.create(model=deployment_name, input=messages) and print response.output_text.messages.append({"role": "assistant", "content": response.output_text}).messages.append({"role": "user", "content": "Which programming language did she help create?"}).response = client.responses.create(model=deployment_name, input=messages) again and print response.output_text.Chat apps keep context by sending the earlier conversation along with each new prompt, so the second request must include the system message, the first question, the model's first reply and the new question together. The list is created first and sent in the first call. The reply can be appended only after that call returns, and the second question is appended after it to preserve conversation order. The second call then sends the complete messages list as input to the deployed model.
- Step 1: Create
messageswith a system message ({"role": "system", "content": "You are a computing history tutor. Keep answers brief."}) followed by the first user message ({"role": "user", "content": "Who was Grace Hopper?"}). Every request is sent from this list, so it must exist before any call. Placing the system message first means it is part of every request that sends the list. - Step 2: Call
response = client.responses.create(model=deployment_name, input=messages)and printresponse.output_text. The first request sends the list built in the previous step. - Step 3: Append the reply to the history with
messages.append({"role": "assistant", "content": response.output_text}). The reply text exists only after the first request returns. - Step 4: Append the second prompt with
messages.append({"role": "user", "content": "Which programming language did she help create?"}). Requirement 3 keeps the list in conversation order, so the second prompt must follow the model's first reply in the list. - Step 5: Call
response = client.responses.create(model=deployment_name, input=messages)again and printresponse.output_text. The second request must carry the full history, including the prompt added in the previous step, so that the model can tell that 'she' means Grace Hopper. - Not needed: For the second call, pass only the second user message as
inputinstead ofmessages. This breaks requirement 2. Without the earlier prompt and reply in the input, the model has no conversation context to work out who 'she' is. - Not needed: Remove the system message from
messagesafter the first call to reduce the number of tokens sent. This breaks requirement 1, because the system instruction would no longer be part of the second request.