Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Latest openai library breaks some unit tests #7358

Closed
vblagoje opened this issue Mar 14, 2024 · 0 comments · Fixed by #7364
Closed

bug: Latest openai library breaks some unit tests #7358

vblagoje opened this issue Mar 14, 2024 · 0 comments · Fixed by #7364
Assignees

Comments

@vblagoje
Copy link
Member

vblagoje commented Mar 14, 2024

As our CI picked up the latest release of openai https://pypi.org/project/openai/1.14.0/ we experienced CI test failures.

The errors seem to stem from changes in non-public API of openai library. The stack trace of one the errors is:

==================================== ERRORS ====================================
___ ERROR at setup of TestOpenAIChatGenerator.test_run_with_params_streaming ___

    @pytest.fixture
    def mock_chat_completion_chunk():
        """
        Mock the OpenAI API completion chunk response and reuse it for tests
        """
    
        class MockStream(Stream[ChatCompletionChunk]):
            def __init__(self, mock_chunk: ChatCompletionChunk, *args, **kwargs):
                super().__init__(*args, **kwargs)
                self.mock_chunk = mock_chunk
    
            def __stream__(self) -> Iterator[ChatCompletionChunk]:
                # Yielding only one ChatCompletionChunk object
                yield self.mock_chunk
    
        with patch("openai.resources.chat.completions.Completions.create") as mock_chat_completion_create:
            completion = ChatCompletionChunk(
                id="foo",
                model="gpt-4",
                object="chat.completion.chunk",
                choices=[
                    Choice(
                        finish_reason="stop", logprobs=None, index=0, delta=ChoiceDelta(content="Hello", role="assistant")
                    )
                ],
                created=int(datetime.now().timestamp()),
                usage={"prompt_tokens": 57, "completion_tokens": 40, "total_tokens": 97},
            )
>           mock_chat_completion_create.return_value = MockStream(completion, cast_to=None, response=None, client=None)

test/components/generators/conftest.py:57: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/components/generators/conftest.py:37: in __init__
    super().__init__(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <conftest.mock_chat_completion_chunk.<locals>.MockStream object at 0x7be0a80fe610>

    def __init__(
        self,
        *,
        cast_to: type[_T],
        response: httpx.Response,
        client: OpenAI,
    ) -> None:
        self.response = response
        self._cast_to = cast_to
        self._client = client
>       self._decoder = client._make_sse_decoder()
E       AttributeError: 'NoneType' object has no attribute '_make_sse_decoder'

../../../.local/share/hatch/env/virtual/haystack-ai/4LlKeELt/test/lib/python3.8/site-packages/openai/_streaming.py:39: AttributeError

More details available on this CI run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants