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

RemoteProtocolError after streaming from Azure Deployement #646

Open
BrokenDuck opened this issue Jan 29, 2025 · 0 comments
Open

RemoteProtocolError after streaming from Azure Deployement #646

BrokenDuck opened this issue Jan 29, 2025 · 0 comments

Comments

@BrokenDuck
Copy link

SDK Version: 5.13.11

** Bug Summary **

When streaming from a Command R or Command R+ endpoint deployed on Azure, after all the content-delta chunks of the streaming response are received, httpx errors with RemoteProtocolError.

** Buggy code **

import cohere

co = cohere.ClientV2(api_key=os.getenv('COMMAND_R_API_KEY'), base_url=os.getenv('COMMAND_R_URL'))

res = co.chat_stream(
    model="command-r-plus-08-2024",
    messages=[{"role": "user", "content": "What is an LLM?"}],
)

for event in res:
    if event:
        if event.type == "content-delta":
            print(event.delta.message.content.text, end="")

** Detailed description **

During the code execution all the content chunks are returned properly and printed out. Afterwards, httpx return a RemoteProtocolError. I am using server deployments on Azure AI Foundry.

** Full stack trace **

---------------------------------------------------------------------------
RemoteProtocolError                       Traceback (most recent call last)
File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_transports/default.py:101, in map_httpcore_exceptions()
    100 try:
--> 101     yield
    102 except Exception as exc:

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_transports/default.py:127, in ResponseStream.__iter__(self)
    126 with map_httpcore_exceptions():
--> 127     for part in self._httpcore_stream:
    128         yield part

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py:407, in PoolByteStream.__iter__(self)
    406 self.close()
--> 407 raise exc from None

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py:403, in PoolByteStream.__iter__(self)
    402 try:
--> 403     for part in self._stream:
    404         yield part

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_sync/http11.py:342, in HTTP11ConnectionByteStream.__iter__(self)
    341     self.close()
--> 342 raise exc

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_sync/http11.py:334, in HTTP11ConnectionByteStream.__iter__(self)
    333 with Trace("receive_response_body", logger, self._request, kwargs):
--> 334     for chunk in self._connection._receive_response_body(**kwargs):
    335         yield chunk

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_sync/http11.py:203, in HTTP11Connection._receive_response_body(self, request)
    202 while True:
--> 203     event = self._receive_event(timeout=timeout)
    204     if isinstance(event, h11.Data):

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_sync/http11.py:213, in HTTP11Connection._receive_event(self, timeout)
    212 while True:
--> 213     with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):
    214         event = self._h11_state.next_event()

File ~/.pyenv/versions/3.12.8/lib/python3.12/contextlib.py:158, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    157 try:
--> 158     self.gen.throw(value)
    159 except StopIteration as exc:
    160     # Suppress StopIteration *unless* it's the same exception that
    161     # was passed to throw().  This prevents a StopIteration
    162     # raised inside the "with" statement from being suppressed.

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpcore/_exceptions.py:14, in map_exceptions(map)
     13     if isinstance(exc, from_exc):
---> 14         raise to_exc(exc) from exc
     15 raise

RemoteProtocolError: peer closed connection without sending complete message body (incomplete chunked read)

The above exception was the direct cause of the following exception:

RemoteProtocolError                       Traceback (most recent call last)
Cell In[5], line 10
      3 co = cohere.ClientV2(api_key=os.getenv('COMMAND_R_API_KEY'), base_url=os.getenv('COMMAND_R_URL'))
      5 res = co.chat_stream(
      6     model="command-r-plus-08-2024",
      7     messages=[{"role": "user", "content": "What is an LLM?"}],
      8 )
---> 10 for event in res:
     11     if event:
     12         if event.type == "content-delta":

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/cohere/v2/client.py:252, in V2Client.chat_stream(self, model, messages, tools, strict_tools, documents, citation_options, response_format, safety_mode, max_tokens, stop_sequences, temperature, seed, frequency_penalty, presence_penalty, k, p, return_prompt, logprobs, tool_choice, request_options)
    250 if 200 <= _response.status_code < 300:
    251     _event_source = httpx_sse.EventSource(_response)
--> 252     for _sse in _event_source.iter_sse():
    253         try:
    254             yield typing.cast(
    255                 StreamedChatResponseV2,
    256                 construct_type(
   (...)
    259                 ),
    260             )

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx_sse/_api.py:30, in EventSource.iter_sse(self)
     28 self._check_content_type()
     29 decoder = SSEDecoder()
---> 30 for line in self._response.iter_lines():
     31     line = line.rstrip("\n")
     32     sse = decoder.decode(line)

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_models.py:929, in Response.iter_lines(self)
    927 decoder = LineDecoder()
    928 with request_context(request=self._request):
--> 929     for text in self.iter_text():
    930         for line in decoder.decode(text):
    931             yield line

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_models.py:916, in Response.iter_text(self, chunk_size)
    914 chunker = TextChunker(chunk_size=chunk_size)
    915 with request_context(request=self._request):
--> 916     for byte_content in self.iter_bytes():
    917         text_content = decoder.decode(byte_content)
    918         for chunk in chunker.decode(text_content):

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_models.py:897, in Response.iter_bytes(self, chunk_size)
    895 chunker = ByteChunker(chunk_size=chunk_size)
    896 with request_context(request=self._request):
--> 897     for raw_bytes in self.iter_raw():
    898         decoded = decoder.decode(raw_bytes)
    899         for chunk in chunker.decode(decoded):

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_models.py:951, in Response.iter_raw(self, chunk_size)
    948 chunker = ByteChunker(chunk_size=chunk_size)
    950 with request_context(request=self._request):
--> 951     for raw_stream_bytes in self.stream:
    952         self._num_bytes_downloaded += len(raw_stream_bytes)
    953         for chunk in chunker.decode(raw_stream_bytes):

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_client.py:153, in BoundSyncStream.__iter__(self)
    152 def __iter__(self) -> typing.Iterator[bytes]:
--> 153     for chunk in self._stream:
    154         yield chunk

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_transports/default.py:126, in ResponseStream.__iter__(self)
    125 def __iter__(self) -> typing.Iterator[bytes]:
--> 126     with map_httpcore_exceptions():
    127         for part in self._httpcore_stream:
    128             yield part

File ~/.pyenv/versions/3.12.8/lib/python3.12/contextlib.py:158, in _GeneratorContextManager.__exit__(self, typ, value, traceback)
    156     value = typ()
    157 try:
--> 158     self.gen.throw(value)
    159 except StopIteration as exc:
    160     # Suppress StopIteration *unless* it's the same exception that
    161     # was passed to throw().  This prevents a StopIteration
    162     # raised inside the "with" statement from being suppressed.
    163     return exc is not value

File ~/.pyenv/versions/FullStack-RAG-Env/lib/python3.12/site-packages/httpx/_transports/default.py:118, in map_httpcore_exceptions()
    115     raise
    117 message = str(exc)
--> 118 raise mapped_exc(message) from exc

RemoteProtocolError: peer closed connection without sending complete message body (incomplete chunked read)
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

No branches or pull requests

1 participant