Skip to content

[BUG] openAI stream() method does not enforce "stream=True" in the upstream API call #210

Open
@thinkinginmath

Description

@thinkinginmath

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

v0.1.7

Python Version

3.11

Operating System

macos 12

Installation Method

pip

Steps to Reproduce

from source code review,

def stream(self, request: dict[str, Any]) -> Iterable[dict[str, Any]]:

@OverRide
def stream(self, request: dict[str, Any]) -> Iterable[dict[str, Any]]:
"""Send the request to the OpenAI model and get the streaming response.

    Args:
        request: The formatted request to send to the OpenAI model.

    Returns:
        An iterable of response events from the OpenAI model.
    """
    response = self.client.chat.completions.create(**request)

this does not work if the caller does not explicitly set stream=True, in the request, or set to False
The OpenAI API will not stream responses unless stream=True is set.

So it is an easy fix

Before passing the request dictionary to self.client.chat.completions.create(**request), override or set the stream key to True:

request["stream"] = True
response = self.client.chat.completions.create(**request)

Expected Behavior

see comment above for the fix

Actual Behavior

see comment above for the fix

Additional Context

No response

Possible Solution

see comment above for the fix

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions