BerriAI / litellm

Python SDK, Proxy Server (LLM Gateway) to call 100+ LLM APIs in OpenAI format - [Bedrock, Azure, OpenAI, VertexAI, Cohere, Anthropic, Sagemaker, HuggingFace, Replicate, Groq]
https://docs.litellm.ai/docs/
Other
13.45k stars 1.57k forks source link

[Bug]: Cohere streaming fails silently #428

Closed krrishdholakia closed 9 months ago

krrishdholakia commented 1 year ago

What happened?

import os
os.environ["COHERE_API_KEY"] = "bad-key"

from litellm import completion 

try:
  completion(model="command-nightly", messages=[{"role": "user", "content": "Hey"}], stream=True)
except Exception as e: 
  print(e)

Relevant log output

No response

Twitter / LinkedIn details

No response

krrishdholakia commented 1 year ago

Investigating this further. This is caused by our current implementation of streaming which try-excepts, and if it's an exception assumes the stream is exhausted and returned an empty response object.

However, this means that errors silently fail across all providers. Will need to actually find the finish reason raised and stop when that occurs.

If it's an exception have it enter our exception mapping logic.

krrishdholakia commented 1 year ago

Impacted providers:

krrishdholakia commented 1 year ago

Pushed in - 889679a0dd072760f80db043503d45b484062050