fix: remove redundant instructions override in run_inference
The override would re-add `instructions` after the adapter had intentionally converted it to a developer message for empty contexts. Added a regression test.
This commit is contained in:
@@ -385,10 +385,6 @@ class OpenAIResponsesLLMService(LLMService):
|
||||
# Override for non-streaming
|
||||
params["stream"] = False
|
||||
|
||||
# Override instructions if caller provided one explicitly
|
||||
if system_instruction is not None:
|
||||
params["instructions"] = system_instruction
|
||||
|
||||
if max_tokens is not None:
|
||||
params["max_output_tokens"] = max_tokens
|
||||
|
||||
|
||||
@@ -902,3 +902,36 @@ async def test_openai_responses_run_inference_max_tokens_override():
|
||||
assert result == "Summary"
|
||||
call_kwargs = service._client.responses.create.call_args.kwargs
|
||||
assert call_kwargs["max_output_tokens"] == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_responses_run_inference_system_instruction_param_with_empty_context():
|
||||
"""Test that system_instruction param becomes a developer message when context is empty.
|
||||
|
||||
The Responses API rejects requests with instructions but no input items.
|
||||
When run_inference is called with an explicit system_instruction and an
|
||||
empty context, the instruction must become a developer message — not be
|
||||
sent as the instructions parameter.
|
||||
"""
|
||||
with patch.object(OpenAIResponsesLLMService, "_create_client"):
|
||||
service = OpenAIResponsesLLMService(
|
||||
settings=OpenAIResponsesLLMService.Settings(model="gpt-4.1"),
|
||||
)
|
||||
service._client = AsyncMock()
|
||||
|
||||
context = LLMContext(messages=[])
|
||||
|
||||
mock_response = MagicMock()
|
||||
mock_response.output_text = "Response"
|
||||
service._client.responses.create = AsyncMock(return_value=mock_response)
|
||||
|
||||
result = await service.run_inference(
|
||||
context, system_instruction="Summarize the conversation"
|
||||
)
|
||||
|
||||
assert result == "Response"
|
||||
call_kwargs = service._client.responses.create.call_args.kwargs
|
||||
assert call_kwargs["input"] == [
|
||||
{"role": "developer", "content": "Summarize the conversation"}
|
||||
]
|
||||
assert "instructions" not in call_kwargs
|
||||
|
||||
Reference in New Issue
Block a user