feat: add OpenAI Responses API model implementation#975
feat: add OpenAI Responses API model implementation#975notgitika wants to merge 6 commits intostrands-agents:mainfrom
Conversation
| """ | ||
| match event["chunk_type"]: | ||
| case "message_start": | ||
| return {"messageStart": {"role": "assistant"}} |
There was a problem hiding this comment.
reach out to @zastrowm , but I believe we can make this more readable by now returning the typed StreamEvents rather than the dictionaries
There was a problem hiding this comment.
I was looking into this briefly but did not implement this. I will talk to him about this and maybe we can implement this in the next iteration.
|
Hey Team, this is one of the feature my customer request and concerned as blocker from adopting Strands Agent. They mentioned Strands currently only support deprecated chatcompletion API and not responses API. When can we expect this to be merged? and will this also enable streaming structured output? |
dbschmigelski
left a comment
There was a problem hiding this comment.
A major version bump is proposed in #1370.
Adding a comment here that we would need to consider when the user has v1 installed compared to v2.
For example
import pydantic
from packaging import version
# Detect the version once at the module level
PYDANTIC_V2 = version.parse(pydantic.VERSION) >= version.parse("2.0.0")
if PYDANTIC_V2:
from pydantic import ConfigDict
def get_model_fields(model):
return model.model_fields
else:
def get_model_fields(model):
return model.__fields__
7c05e84 to
8eea5d9
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| )() | ||
|
|
||
| yield self._format_chunk({"chunk_type": "content_start", "data_type": "tool", "data": mock_tool_call}) | ||
| yield self._format_chunk({"chunk_type": "content_delta", "data_type": "tool", "data": mock_tool_call}) |
There was a problem hiding this comment.
Here we are only ever emitting one delta per tool? Is this correct? Wouldn't we expect multiple?
There was a problem hiding this comment.
this is intentional. the repsonses API streams chunks via response.function_call_arguments.delta which we accumulate, then use the final arguments from response.function_call_arguments.done as a complete json. added this as a small comment there as well.
please lmk if this is not an accepted design and if I should explore something else.
notowen333
left a comment
There was a problem hiding this comment.
Some refactoring is required to make this maintainable. Otherwise LGTM
…-responses-model # Conflicts: # tests_integ/models/test_model_openai.py
6a70455 to
83e2982
Compare
4d41aef to
37e719f
Compare
Description
This PR implements OpenAI Responses API as a separate model provider supporting streaming, structured output and tool calling.
Note: this commit does not include the extra capabilities that the Responses API supports such as the built-in tools and the stateful conversation runs.
Related Issues
#253
Documentation PR
TODO; coming next: will be adding a section for the Responses API within the existing openai model page
Type of Change
New feature
Testing
Added a unit test file similar to the existing
test_openai.pymodel provider. Reusing the integ tests in the same filetest_model_openai.pyusingpytest.parameterizewithOpenAIResponsesmodel so that I could test that the funcitonality is the same between the two models.I ran everything in the CONTRIBUTING.md file.
hatch run integ-test================== 81 passed, 68 skipped, 49 warnings in 106.56s (0:01:46) ==========
hatch run test-integ tests_integ/models/test_model_openai.py -v============= 18 passed, 2 skipped in 13.44s =============
pre-commit run --all-fileshatch run prepare--> yes, all tests passChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.