From 4be1ada55a98d3b88a7efc26eca647f9c5fd31df Mon Sep 17 00:00:00 2001 From: dorren Date: Wed, 12 Feb 2025 10:55:51 +0800 Subject: [PATCH] fix lint --- examples/multimodal_chatbot_online.py | 9 +++++---- lazyllm/components/utils/file_operate.py | 2 +- lazyllm/module/onlineChatModule/onlineChatModuleBase.py | 8 ++++---- lazyllm/module/onlineChatModule/qwenModule.py | 4 ++-- lazyllm/module/onlineChatModule/sensenovaModule.py | 2 +- lazyllm/tools/rag/doc_node.py | 2 +- tests/advanced_tests/standard_test/test_deploy.py | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/multimodal_chatbot_online.py b/examples/multimodal_chatbot_online.py index 6aa7ca26..2fb0c6c4 100644 --- a/examples/multimodal_chatbot_online.py +++ b/examples/multimodal_chatbot_online.py @@ -2,12 +2,13 @@ # Before running, set the environment variable: # -# 1. `export LAZYLLM_GLM_API_KEY=xxxx`: the API key of Zhipu AI, you need to set `source="glm"` and `model="glm-4v-flash"`. -# You can apply for the API key at https://open.bigmodel.cn/ +# 1. `export LAZYLLM_GLM_API_KEY=xxxx`: the API key of Zhipu AI, you need to set `source="glm"` and +# `model="glm-4v-flash"`. You can apply for the API key at https://open.bigmodel.cn/ # Also supports other API keys: # - LAZYLLM_OPENAI_API_KEY: the API key of OpenAI, set `source="openai"` and `model="gpt-4o-mini"`. # You can apply for the API key at https://openai.com/index/openai-api/ -# - LAZYLLM_KIMI_API_KEY: the API key of Moonshot AI, set `source="kimi"` and `model="moonshot-v1-8k-vision-preview"`. +# - LAZYLLM_KIMI_API_KEY: the API key of Moonshot AI, set `source="kimi"` and +# `model="moonshot-v1-8k-vision-preview"`. # You can apply for the API key at https://platform.moonshot.cn/console # - LAZYLLM_QWEN_API_KEY: the API key of Alibaba Cloud, set `source="qwen"` and `model="qwenvl-max"`. # You can apply for the API key at https://home.console.aliyun.com/ @@ -19,4 +20,4 @@ chat = lazyllm.OnlineChatModule(source="glm", model="glm-4v-flash") if __name__ == '__main__': - lazyllm.WebModule(chat, port=range(23466, 23470), files_target=chat).start().wait() \ No newline at end of file + lazyllm.WebModule(chat, port=range(23466, 23470), files_target=chat).start().wait() diff --git a/lazyllm/components/utils/file_operate.py b/lazyllm/components/utils/file_operate.py index 909c6c69..29bc9b7c 100644 --- a/lazyllm/components/utils/file_operate.py +++ b/lazyllm/components/utils/file_operate.py @@ -42,7 +42,7 @@ def delete_old_files(directory): LOG.info(f"Deleted: {dir_path}") except Exception as e: LOG.error(f"Error deleting directory {dir_path}: {e}") - + def image_to_base64(directory): try: with open(directory, 'rb') as f: diff --git a/lazyllm/module/onlineChatModule/onlineChatModuleBase.py b/lazyllm/module/onlineChatModule/onlineChatModuleBase.py index 9b278265..c8c8665b 100644 --- a/lazyllm/module/onlineChatModule/onlineChatModuleBase.py +++ b/lazyllm/module/onlineChatModule/onlineChatModuleBase.py @@ -273,7 +273,7 @@ def forward(self, __input: Union[Dict, str] = None, *, llm_chat_history: List[Li if len(self._model_optional_params) > 0: data.update(self._model_optional_params) - + if isinstance(__input, str) and __input.startswith(LAZYLLM_QUERY_PREFIX): for idx, message in enumerate(data["messages"]): content = message["content"] @@ -434,13 +434,13 @@ def _start_for_deployment(): raise ValueError(f"Deployment task {deployment_id} failed") lazyllm.LOG.info(f"deployment {deployment_id} finished") return Pipeline(_start_for_deployment) - + def _format_vl_chat_query(self, query: str): return [{"type": "text", "text": query}] - + def _format_vl_chat_image_url(self, image_url: str, mime: str) -> List[Dict[str, str]]: return [{"type": "image_url", "image_url": {"url": image_url}}] - + # for online vlm def _format_input_with_files(self, query_files: str) -> List[Dict[str, str]]: if isinstance(query_files, str): diff --git a/lazyllm/module/onlineChatModule/qwenModule.py b/lazyllm/module/onlineChatModule/qwenModule.py index bb6f0e6f..8d32809b 100644 --- a/lazyllm/module/onlineChatModule/qwenModule.py +++ b/lazyllm/module/onlineChatModule/qwenModule.py @@ -295,8 +295,8 @@ def _query_deployment(self, deployment_id) -> str: status = r.json()["output"]['status'] return status - + def _format_vl_chat_image_url(self, image_url, mime): assert mime is not None, "Qwen Module requires mime info." - image_url = f"data:{mime};base64,{image_url}" + image_url = f"data:{mime};base64,{image_url}" return [{"type": "image_url", "image_url": {"url": image_url}}] diff --git a/lazyllm/module/onlineChatModule/sensenovaModule.py b/lazyllm/module/onlineChatModule/sensenovaModule.py index e0e641a9..d92ca27a 100644 --- a/lazyllm/module/onlineChatModule/sensenovaModule.py +++ b/lazyllm/module/onlineChatModule/sensenovaModule.py @@ -242,7 +242,7 @@ def _query_deployment(self, deployment_id) -> str: status = r.json()["job"]['status'] return status - + def _format_vl_chat_image_url(self, image_url, mime): if image_url.startswith("http"): return [{"type": "image_url", "image_url": image_url}] diff --git a/lazyllm/tools/rag/doc_node.py b/lazyllm/tools/rag/doc_node.py index e4f37a5e..07d120b1 100644 --- a/lazyllm/tools/rag/doc_node.py +++ b/lazyllm/tools/rag/doc_node.py @@ -246,7 +246,7 @@ def do_embedding(self, embed: Dict[str, Callable]) -> None: self.embedding = {**self.embedding, **generate_embed} def get_content(self, metadata_mode=MetadataMode.LLM) -> str: - if metadata_mode==MetadataMode.LLM: + if metadata_mode == MetadataMode.LLM: return Image.open(self._image_path) elif metadata_mode == MetadataMode.EMBED: image_base64, mime = image_to_base64(self._image_path) diff --git a/tests/advanced_tests/standard_test/test_deploy.py b/tests/advanced_tests/standard_test/test_deploy.py index 0f4aa641..5014599d 100644 --- a/tests/advanced_tests/standard_test/test_deploy.py +++ b/tests/advanced_tests/standard_test/test_deploy.py @@ -106,11 +106,11 @@ def test_cross_modal_embedding(self): image_path = os.path.join(lazyllm.config['data_path'], "ci_data/ji.jpg") image_base64, mime = image_to_base64(image_path) image_base64 = f'data:{mime};base64,{image_base64}' - res = m(image_url, modality = 'image') + res = m(image_url, modality='image') assert len(json.loads(res)) == 1152 res = m([image_url], modality='image') assert len(json.loads(res)) == 1 - res = m([image_url, image_base64], modality = 'image') + res = m([image_url, image_base64], modality='image') assert len(json.loads(res)) == 2 def test_sd3(self):