mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-23 08:33:09 +00:00
feat: Add instructions parameter in response object (#3741)
# Problem The current inline provider appends the user provided instructions to messages as a system prompt, but the returned response object does not contain the instructions field (as specified in the OpenAI responses spec). # What does this PR do? This pull request adds the instruction field to the response object definition and updates the inline provider. It also ensures that instructions from previous response is not carried over to the next response (as specified in the openAI spec). Closes #[3566](https://github.com/llamastack/llama-stack/issues/3566) ## Test Plan - Tested manually for change in model response w.r.t supplied instructions field. - Added unit test to check that the instructions from previous response is not carried over to the next response. - Added integration tests to check instructions parameter in the returned response object. - Added new recordings for the integration tests. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
1f38359d95
commit
add64e8e2a
56 changed files with 10032 additions and 5816 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue