From dc33cdce5a27ad1d3b110097585868331ce9f3ac Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Tue, 26 Sep 2023 11:43:57 +0800 Subject: [PATCH] remove unused imports in Python (#145) --- .../src/main/python/plugin_call/prompt_construct.py | 7 +++---- chat/core/src/main/python/plugin_call/run.py | 6 +----- .../main/python/preset_retrieval/preset_query_db.py | 5 ++--- chat/core/src/main/python/preset_retrieval/run.py | 13 +++---------- chat/core/src/main/python/sql/constructor.py | 12 ++---------- .../core/src/main/python/sql/examples_reload_run.py | 5 +++-- chat/core/src/main/python/sql/prompt_maker.py | 2 +- chat/core/src/main/python/sql/run.py | 4 +--- chat/core/src/main/python/supersonic_llmparser.py | 5 ++--- chat/core/src/main/python/util/chromadb_instance.py | 3 +-- chat/core/src/main/python/util/text2vec.py | 5 ++--- 11 files changed, 21 insertions(+), 46 deletions(-) diff --git a/chat/core/src/main/python/plugin_call/prompt_construct.py b/chat/core/src/main/python/plugin_call/prompt_construct.py index 87a4d6163..00376b9da 100644 --- a/chat/core/src/main/python/plugin_call/prompt_construct.py +++ b/chat/core/src/main/python/plugin_call/prompt_construct.py @@ -1,10 +1,9 @@ # -*- coding:utf-8 -*- -import os -import sys import json -import time +import os import re -from typing import Any, List, Mapping, Optional, Union +import sys +from typing import Any, List, Mapping, Union sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) diff --git a/chat/core/src/main/python/plugin_call/run.py b/chat/core/src/main/python/plugin_call/run.py index 769abf438..7021e7bb5 100644 --- a/chat/core/src/main/python/plugin_call/run.py +++ b/chat/core/src/main/python/plugin_call/run.py @@ -1,11 +1,8 @@ # -*- coding:utf-8 -*- -from typing import Any, List, Mapping, Optional, Union -import logging -import json -import time import os import sys +from typing import Any, List, Mapping, Union sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) @@ -14,7 +11,6 @@ from plugin_call.prompt_construct import ( construct_plugin_pool_prompt, construct_task_prompt, plugin_selection_output_parse, - plugins_config_format_convert, ) from util.llm_instance import llm diff --git a/chat/core/src/main/python/preset_retrieval/preset_query_db.py b/chat/core/src/main/python/preset_retrieval/preset_query_db.py index 8a7c1c554..70abcb5c1 100644 --- a/chat/core/src/main/python/preset_retrieval/preset_query_db.py +++ b/chat/core/src/main/python/preset_retrieval/preset_query_db.py @@ -2,10 +2,9 @@ import os import sys import uuid -import numpy as np -from typing import Any, List, Mapping, Optional, Union +from typing import Any, List, Mapping -from chromadb.api import Collection, Documents, Embeddings +from chromadb.api import Collection sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) diff --git a/chat/core/src/main/python/preset_retrieval/run.py b/chat/core/src/main/python/preset_retrieval/run.py index e0d7ce0d0..87fe4fa91 100644 --- a/chat/core/src/main/python/preset_retrieval/run.py +++ b/chat/core/src/main/python/preset_retrieval/run.py @@ -2,30 +2,23 @@ import os import sys -import uuid -from typing import Any, List, Mapping, Optional, Union +from typing import List sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) - -from chromadb.api import Collection, Documents, Embeddings - -from langchain.llms import OpenAI +from chromadb.api import Collection from preset_query_db import ( - get_ids, - add2preset_query_collection, query2preset_query_collection, parse_retrieval_preset_query, preset_query_retrieval_format, - empty_preset_query_collection, preset_query_collection_size, ) from util.text2vec import Text2VecEmbeddingFunction -from run_config import CHROMA_DB_PERSIST_PATH, PRESET_QUERY_COLLECTION_NAME +from run_config import PRESET_QUERY_COLLECTION_NAME from util.chromadb_instance import client diff --git a/chat/core/src/main/python/sql/constructor.py b/chat/core/src/main/python/sql/constructor.py index 0fb84ce5c..d2dcc1bc4 100644 --- a/chat/core/src/main/python/sql/constructor.py +++ b/chat/core/src/main/python/sql/constructor.py @@ -1,24 +1,16 @@ # -*- coding:utf-8 -*- -from typing import Any, List, Mapping, Optional, Union import os import sys -import time +from typing import List, Mapping sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from langchain.prompts.few_shot import FewShotPromptTemplate -from langchain.prompts import PromptTemplate from langchain.vectorstores import Chroma -from langchain.embeddings import OpenAIEmbeddings, HuggingFaceEmbeddings from langchain.prompts.example_selector import SemanticSimilarityExampleSelector -import chromadb -from chromadb.config import Settings -from chromadb.api import Collection, Documents, Embeddings - from few_shot_example.sql_exampler import examplars as sql_examplars -from util.text2vec import Text2VecEmbeddingFunction, hg_embedding +from util.text2vec import hg_embedding from util.chromadb_instance import client as chromadb_client, empty_chroma_collection_2 from run_config import TEXT2DSL_COLLECTION_NAME, TEXT2DSL_FEW_SHOTS_EXAMPLE_NUM diff --git a/chat/core/src/main/python/sql/examples_reload_run.py b/chat/core/src/main/python/sql/examples_reload_run.py index 6a0efec2b..c2b614614 100644 --- a/chat/core/src/main/python/sql/examples_reload_run.py +++ b/chat/core/src/main/python/sql/examples_reload_run.py @@ -1,9 +1,10 @@ # -*- coding:utf-8 -*- -from typing import Any, List, Mapping, Optional, Union +import json import os import sys +from typing import List, Mapping + import requests -import json sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) diff --git a/chat/core/src/main/python/sql/prompt_maker.py b/chat/core/src/main/python/sql/prompt_maker.py index 925cd026e..892ab7aa4 100644 --- a/chat/core/src/main/python/sql/prompt_maker.py +++ b/chat/core/src/main/python/sql/prompt_maker.py @@ -1,7 +1,7 @@ # -*- coding:utf-8 -*- -from typing import Any, List, Mapping, Optional, Union import os import sys +from typing import List, Mapping sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) diff --git a/chat/core/src/main/python/sql/run.py b/chat/core/src/main/python/sql/run.py index ddd4be8f3..82ca3058a 100644 --- a/chat/core/src/main/python/sql/run.py +++ b/chat/core/src/main/python/sql/run.py @@ -1,8 +1,6 @@ -from typing import List, Union, Mapping -import logging -import json import os import sys +from typing import List, Union, Mapping sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) diff --git a/chat/core/src/main/python/supersonic_llmparser.py b/chat/core/src/main/python/supersonic_llmparser.py index 0eb984cb4..42cfe1ce6 100644 --- a/chat/core/src/main/python/supersonic_llmparser.py +++ b/chat/core/src/main/python/supersonic_llmparser.py @@ -1,13 +1,13 @@ # -*- coding:utf-8 -*- import os -import logging import sys + import uvicorn sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from typing import Any, List, Mapping, Optional, Union +from typing import Any, List, Mapping from fastapi import FastAPI, HTTPException @@ -19,7 +19,6 @@ from preset_retrieval.run import ( ) from preset_retrieval.preset_query_db import ( add2preset_query_collection, - update_preset_query_collection, empty_preset_query_collection, delete_preset_query_by_ids, update_preset_query_collection, diff --git a/chat/core/src/main/python/util/chromadb_instance.py b/chat/core/src/main/python/util/chromadb_instance.py index 0ee4920e8..35dd4fa7b 100644 --- a/chat/core/src/main/python/util/chromadb_instance.py +++ b/chat/core/src/main/python/util/chromadb_instance.py @@ -1,8 +1,7 @@ # -*- coding:utf-8 -*- -from typing import Any, List, Mapping, Optional, Union import chromadb -from chromadb.api import Collection, Documents, Embeddings +from chromadb.api import Collection from chromadb.config import Settings from run_config import CHROMA_DB_PERSIST_PATH diff --git a/chat/core/src/main/python/util/text2vec.py b/chat/core/src/main/python/util/text2vec.py index ea5f06202..8c56c561f 100644 --- a/chat/core/src/main/python/util/text2vec.py +++ b/chat/core/src/main/python/util/text2vec.py @@ -1,9 +1,8 @@ # -*- coding:utf-8 -*- -import os -from typing import Any, List, Mapping, Optional, Union +from typing import List -from langchain.embeddings import HuggingFaceEmbeddings from chromadb.api.types import Documents, EmbeddingFunction, Embeddings +from langchain.embeddings import HuggingFaceEmbeddings from run_config import HF_TEXT2VEC_MODEL_NAME