async def stream_response(self, messages: list[dict]) -> Generator[str, None, None]:
        """Stream chat completions.

        If `stream` attribute is False, the generator will yield only one completion.
        Otherwise, it will yield chunk completions.

        Args:
            messages: A list of messages to use for the completion.
                message format: {"role": "user", "content": "Hello, world!"}
        """
        messages = self._prepare_messages(messages)
        data = await self._client.chat.completions.create(
            messages=messages,
            model=self.model,
            stream=self.stream,
            **self.create_kwargs,
        )

        if self.stream:
            async for chunk in data:
                if not isinstance(chunk, ChatCompletionChunk):
                    raise TypeError(f"Unexpected data type: {type(data)}")
                if chunk.choices[0].delta.content is not None:
                    yield chunk.choices[0].delta.content
        else:
            if not isinstance(data, ChatCompletion):
                raise TypeError(f"Unexpected data type: {type(data)}")
            yield data.choices[0].message.content
Stream chat completions.

        If `stream` attribute is False, the generator will yield only one completion.
        Otherwise, it will yield chunk completions.

        Args:
            messages: A list of messages to use for the completion.
                message format: {"role": "user", "content": "Hello, world!"}
        
lanarky/adapters/openai/resources.py