From 6fb91fb2b6fbbeded372bf3783baca582a4cd167 Mon Sep 17 00:00:00 2001 From: alisalim17 Date: Mon, 29 Apr 2024 14:51:19 +0400 Subject: [PATCH 1/2] fix: cohere streaming --- libs/superagent/app/agents/llm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/superagent/app/agents/llm.py b/libs/superagent/app/agents/llm.py index 4a8e1269b..f26a74999 100644 --- a/libs/superagent/app/agents/llm.py +++ b/libs/superagent/app/agents/llm.py @@ -161,6 +161,7 @@ def __init__( NOT_TOOLS_STREAMING_SUPPORTED_PROVIDERS = [ LLMProvider.GROQ, LLMProvider.BEDROCK, + LLMProvider.COHERE_CHAT, ] intermediate_steps = [] @@ -236,7 +237,10 @@ async def _completion(self, **kwargs) -> Any: await self.streaming_callback.on_llm_start() # TODO: Remove this when Groq and Bedrock supports streaming with tools - if self.llm_data.llm.provider in self.NOT_TOOLS_STREAMING_SUPPORTED_PROVIDERS: + if ( + self.llm_data.llm.provider in self.NOT_TOOLS_STREAMING_SUPPORTED_PROVIDERS + and len(self.tools) > 0 + ): logger.info( f"Disabling streaming for {self.llm_data.llm.provider}, as tools are used" ) @@ -251,6 +255,7 @@ async def _completion(self, **kwargs) -> Any: for chunk in res: new_message = chunk.choices[0].delta.dict() + print("new_message", new_message) # clean up tool calls if new_message.get("tool_calls"): new_message["role"] = "assistant" @@ -277,6 +282,7 @@ async def _completion(self, **kwargs) -> Any: output = self._cleanup_output(output) + print("self._stream_directly", self._stream_directly) if not self._stream_directly: await self._stream_by_lines(output) @@ -310,6 +316,7 @@ async def ainvoke(self, input, *_, **kwargs): stream=self.enable_streaming, **self.llm_data.params.dict(exclude_unset=True), ) + print("output", output) return { "intermediate_steps": self.intermediate_steps, From 67609c9f2fb85effbbb7c65884cc068a6b96863a Mon Sep 17 00:00:00 2001 From: alisalim17 Date: Wed, 1 May 2024 12:20:51 +0400 Subject: [PATCH 2/2] bump litellm version to 1.35.33 --- libs/superagent/app/agents/llm.py | 3 --- libs/superagent/poetry.lock | 8 ++++---- libs/superagent/pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libs/superagent/app/agents/llm.py b/libs/superagent/app/agents/llm.py index f26a74999..c266734a5 100644 --- a/libs/superagent/app/agents/llm.py +++ b/libs/superagent/app/agents/llm.py @@ -255,7 +255,6 @@ async def _completion(self, **kwargs) -> Any: for chunk in res: new_message = chunk.choices[0].delta.dict() - print("new_message", new_message) # clean up tool calls if new_message.get("tool_calls"): new_message["role"] = "assistant" @@ -282,7 +281,6 @@ async def _completion(self, **kwargs) -> Any: output = self._cleanup_output(output) - print("self._stream_directly", self._stream_directly) if not self._stream_directly: await self._stream_by_lines(output) @@ -316,7 +314,6 @@ async def ainvoke(self, input, *_, **kwargs): stream=self.enable_streaming, **self.llm_data.params.dict(exclude_unset=True), ) - print("output", output) return { "intermediate_steps": self.intermediate_steps, diff --git a/libs/superagent/poetry.lock b/libs/superagent/poetry.lock index 9857cdffe..6f789a451 100644 --- a/libs/superagent/poetry.lock +++ b/libs/superagent/poetry.lock @@ -2311,13 +2311,13 @@ requests = ">=2,<3" [[package]] name = "litellm" -version = "1.35.21" +version = "1.35.33" description = "Library to easily interface with LLM API providers" optional = false python-versions = "!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*,>=3.8" files = [ - {file = "litellm-1.35.21-py3-none-any.whl", hash = "sha256:907230b7ff57c853e32d04274c2bb01f75e77d49220bd3d4d8fa02cfe6d3492a"}, - {file = "litellm-1.35.21.tar.gz", hash = "sha256:be0f9452fa357996e194c88eebc94f742be2fa623afd137a91b1e60ce5c3821f"}, + {file = "litellm-1.35.33-py3-none-any.whl", hash = "sha256:7dbbc282ea797febb4ace58bdd1fc42d0f20ea21a2ba576ebc2d933b337d8683"}, + {file = "litellm-1.35.33.tar.gz", hash = "sha256:0082f6a44ff7ce9d2c1bc5182292c3f58f69c8be99fccb824e750c009f78d112"}, ] [package.dependencies] @@ -6025,4 +6025,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.1, <3.12" -content-hash = "9049d2eda40cf7a7809de8eeac32efac0753e9006d50b8ef98aca4ef75f0e703" +content-hash = "b6a533b2c2d45f65aa2261eac2ff7865d621abba00e965371a626d3aab3575c3" diff --git a/libs/superagent/pyproject.toml b/libs/superagent/pyproject.toml index 7ea34bbb4..ee4a54f1b 100644 --- a/libs/superagent/pyproject.toml +++ b/libs/superagent/pyproject.toml @@ -50,7 +50,7 @@ openai = "^1.1.1" langchain-experimental = "^0.0.37" pydub = "^0.25.1" algoliasearch = "^3.0.0" -litellm = "1.35.21" +litellm = "1.35.33" weaviate-client = "^3.25.3" qdrant-client = "^1.6.9" vecs = "^0.4.2"