Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/strands/models/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/llamaapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/llamacpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncIterable[StreamEvent]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
1 change: 1 addition & 0 deletions src/strands/models/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ async def stream(
messages: Messages,
tool_specs: Optional[list[ToolSpec]] = None,
system_prompt: Optional[str] = None,
*,
tool_choice: ToolChoice | None = None,
**kwargs: Any,
) -> AsyncGenerator[StreamEvent, None]:
Expand Down
28 changes: 27 additions & 1 deletion tests/strands/models/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,36 @@ async def test_stream(model, messages, tool_specs, system_prompt, alist):


@pytest.mark.asyncio
async def test_structured_output(model, alist):
async def test_structured_output(model, messages, system_prompt, alist):
response = model.structured_output(Person, prompt=messages, system_prompt=system_prompt)
events = await alist(response)

tru_output = events[-1]["output"]
exp_output = Person(name="test", age=20)
assert tru_output == exp_output


@pytest.mark.asyncio
async def test_stream_without_tool_choice_parameter(messages, alist):
"""Test that model implementations without tool_choice parameter are still valid."""
class LegacyModel(SAModel):
def update_config(self, **model_config):
return model_config

def get_config(self):
return

async def structured_output(self, output_model, prompt=None, system_prompt=None, **kwargs):
yield {"output": output_model(name="test", age=20)}

async def stream(self, messages, tool_specs=None, system_prompt=None):
yield {"messageStart": {"role": "assistant"}}
yield {"contentBlockDelta": {"delta": {"text": "Legacy model works"}}}
yield {"messageStop": {"stopReason": "end_turn"}}

model = LegacyModel()
response = model.stream(messages)
events = await alist(response)

assert len(events) == 3
assert events[1]["contentBlockDelta"]["delta"]["text"] == "Legacy model works"
Loading