From 5f593c172a10f448f95f71bb40eb839aac327661 Mon Sep 17 00:00:00 2001 From: monysun Date: Fri, 26 Jul 2024 20:44:07 +0800 Subject: [PATCH] community: fix dashcope embeddings embed_query func post too much req to api (#24707) the fuc of embed_query of dashcope embeddings send a str param, and in the embed_with_retry func will send error content to api --- libs/community/langchain_community/embeddings/dashscope.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/embeddings/dashscope.py b/libs/community/langchain_community/embeddings/dashscope.py index 1bdf72ba7e..f5b3062c77 100644 --- a/libs/community/langchain_community/embeddings/dashscope.py +++ b/libs/community/langchain_community/embeddings/dashscope.py @@ -48,8 +48,11 @@ def embed_with_retry(embeddings: DashScopeEmbeddings, **kwargs: Any) -> Any: result = [] i = 0 input_data = kwargs["input"] - while i < len(input_data): - kwargs["input"] = input_data[i : i + 25] + input_len = len(input_data) if isinstance(input_data, list) else 1 + while i < input_len: + kwargs["input"] = ( + input_data[i : i + 25] if isinstance(input_data, list) else input_data + ) resp = embeddings.client.call(**kwargs) if resp.status_code == 200: result += resp.output["embeddings"]