From 8d8d85379f751b3dac69334f3f231b2ad6e8ca2b Mon Sep 17 00:00:00 2001 From: Rave Harpaz Date: Wed, 30 Oct 2024 19:35:25 -0700 Subject: [PATCH] community: OCI Generative AI tool calling bug fix (#26910) - [x] **PR title**: "community: OCI Generative AI tool calling bug fix - [x] **PR message**: - **Description:** bug fix for streaming chat responses with tool calls. Update to PR 24693 - **Issue:** chat response content is repeated when streaming - **Dependencies:** NA - **Twitter handle:** NA - [x] **Add tests and docs**: NA - [x] **Lint and test**: make format, make lint and make test we run successfully --------- Co-authored-by: Arthur Cheng Co-authored-by: Erick Friis --- .../langchain_community/chat_models/oci_generative_ai.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chat_models/oci_generative_ai.py b/libs/community/langchain_community/chat_models/oci_generative_ai.py index a900e488ffa..8600dd5e923 100644 --- a/libs/community/langchain_community/chat_models/oci_generative_ai.py +++ b/libs/community/langchain_community/chat_models/oci_generative_ai.py @@ -158,7 +158,10 @@ class CohereProvider(Provider): def chat_stream_to_text(self, event_data: Dict) -> str: if "text" in event_data: - return event_data["text"] + if "finishedReason" in event_data or "toolCalls" in event_data: + return "" + else: + return event_data["text"] else: return ""