add support for instructions parameter in response object

This commit is contained in:
Shabana Baig 2025-10-14 14:39:23 -04:00
parent 08cbb69ef7
commit f176e1a74b
10 changed files with 229 additions and 29 deletions

View file

@ -466,3 +466,53 @@ def test_guardrails_with_tools(compat_client, text_model_id):
# Response should be either a function call or a message
output_type = response.output[0].type
assert output_type in ["function_call", "message"]
def test_response_with_instructions(openai_client, client_with_models, text_model_id):
"""Test instructions parameter in the responses object."""
if isinstance(client_with_models, LlamaStackAsLibraryClient):
pytest.skip("OpenAI responses are not supported when testing with library client yet.")
client = openai_client
messages = [
{
"role": "user",
"content": "What is the capital of France?",
}
]
# First create a response without instructions parameter
response_w_o_instructions = client.responses.create(
model=text_model_id,
input=messages,
stream=False,
)
# Verify we have None in the instructions field
assert response_w_o_instructions.instructions is None
# Next create a response and pass instructions parameter
instructions = "You are a helpful assistant."
response_with_instructions = client.responses.create(
model=text_model_id,
instructions=instructions,
input=messages,
stream=False,
)
# Verify we have a valid instructions field
assert response_with_instructions.instructions == instructions
# Finally test instructions parameter with a previous response id
instructions2 = "You are a helpful assistant and speak in pirate language."
response_with_instructions2 = client.responses.create(
model=text_model_id,
instructions=instructions2,
input=messages,
previous_response_id=response_with_instructions.id,
stream=False,
)
# Verify instructions from previous response was not carried over to the next response
assert response_with_instructions2.instructions == instructions2