mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-28 05:54:55 +00:00
partners/mistralai: Fix KeyError in Vertex AI stream (#28624)
- **Description:** Streaming response from Mistral model using Vertex AI raises KeyError when trying to access `choices` key, that the last chunk doesn't have. The fix is to access the key safely using `get()`. - **Issue:** https://github.com/langchain-ai/langchain/issues/27886 - **Dependencies:** - **Twitter handle:**
This commit is contained in:
parent
bdb4cf7cc0
commit
9fcd203556
@ -595,7 +595,7 @@ class ChatMistralAI(BaseChatModel):
|
||||
for chunk in self.completion_with_retry(
|
||||
messages=message_dicts, run_manager=run_manager, **params
|
||||
):
|
||||
if len(chunk["choices"]) == 0:
|
||||
if len(chunk.get("choices", [])) == 0:
|
||||
continue
|
||||
new_chunk = _convert_chunk_to_message_chunk(chunk, default_chunk_class)
|
||||
# make future chunks same type as first chunk
|
||||
@ -621,7 +621,7 @@ class ChatMistralAI(BaseChatModel):
|
||||
async for chunk in await acompletion_with_retry(
|
||||
self, messages=message_dicts, run_manager=run_manager, **params
|
||||
):
|
||||
if len(chunk["choices"]) == 0:
|
||||
if len(chunk.get("choices", [])) == 0:
|
||||
continue
|
||||
new_chunk = _convert_chunk_to_message_chunk(chunk, default_chunk_class)
|
||||
# make future chunks same type as first chunk
|
||||
|
Loading…
Reference in New Issue
Block a user