diff --git a/requirements.txt b/requirements.txt index 9741efc..830552c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,76 +1,77 @@ # API requirements -langchain==0.0.344 -langchain-experimental>=0.0.42 +# On Windows system, install the cuda version manually from https://pytorch.org/ +torch>=2.1.2 +torchvision>=0.16.2 +torchaudio>=2.1.2 + +langchain>=0.0.352 +langchain-experimental>=0.0.47 pydantic==1.10.13 fschat>=0.2.33 -xformers>=0.0.22.post7 -sentence_transformers -transformers>=4.35.2 -torch==2.1.0 ##on Windows system, install the cuda version manually from https://pytorch.org/ -torchvision #on Windows system, install the cuda version manually from https://pytorch.org/ -torchaudio #on Windows system, install the cuda version manually from https://pytorch.org/ -openai>=1.3.7 -fastapi>=0.104 -sse_starlette +xformers>=0.0.23.post1 +openai>=1.6.0 +sentence_transformers>=2.2.2 +transformers>=4.36.2 +fastapi>=0.105 nltk>=3.8.1 uvicorn>=0.24.0.post1 starlette~=0.27.0 unstructured[all-docs]==0.11.0 python-magic-bin; sys_platform == 'win32' SQLAlchemy==2.0.19 -faiss-cpu # `conda install faiss-gpu -c conda-forge` if you want to accelerate with gpus +faiss-cpu>=1.7.4 accelerate>=0.24.1 spacy>=3.7.2 -PyMuPDF -rapidocr_onnxruntime +PyMuPDF>=1.23.8 +rapidocr_onnxruntime>=1.3.8 requests>=2.31.0 pathlib>=1.0.1 pytest>=7.4.3 -numexpr>=2.8.7 +numexpr>=2.8.8 strsimpy>=0.2.1 markdownify>=0.11.6 -tiktoken>=0.5.1 +tiktoken>=0.5.2 tqdm>=4.66.1 -websockets -numpy~=1.24.4 -pandas~=2.0.3 +websockets>=12.0 +numpy~=1.26.2 +pandas~=2.1.4 einops>=0.7.0 -transformers_stream_generator==0.0.4 -vllm==0.2.2; sys_platform == "linux" -httpx[brotli,http2,socks]>=0.25.2 +transformers_stream_generator>=0.0.4 +vllm>=0.2.6; sys_platform == "linux" # optional document loaders -# rapidocr_paddle[gpu] # gpu accelleration for ocr of pdf and image files -jq # for .json and .jsonl files. suggest `conda install jq` on windows -# html2text # for .enex files -# beautifulsoup4 # for .mhtml files -# pysrt # for .srt files + +rapidocr_paddle[gpu]>=1.3.0.post5 +jq>=1.6.0 +html2text +beautifulsoup4>=4.12.2 +pysrt>=1.1.2 # Online api libs dependencies -# zhipuai>=1.0.7 # zhipu -# dashscope>=1.10.0 # qwen -# volcengine>=1.0.106 # fangzhou - -# uncomment libs if you want to use corresponding vector store -# pymilvus==2.1.3 # requires milvus==2.1.3 -# psycopg2 +zhipuai>=1.0.7 +dashscope>=1.13.6 +volcengine>=1.0.119 +pymilvus>=2.3.4 +# psycopg2==2.9.9 # pgvector>=0.2.4 # Agent and Search Tools arxiv>=2.0.0 youtube-search>=2.1.2 -duckduckgo-search>=3.9.9 +duckduckgo-search>=4.1.0 metaphor-python>=0.1.23 # WebUI requirements -streamlit>=1.29.0 # do remember to add streamlit to environment variables if you use windows +streamlit>=1.29.0 streamlit-option-menu>=0.3.6 +streamlit-antd-components>=0.2.4 streamlit-chatbox>=1.1.11 streamlit-modal>=0.1.0 streamlit-aggrid>=0.3.4.post3 +httpx[brotli,http2,socks]>=0.25.2 watchdog>=3.0.0 diff --git a/requirements_api.txt b/requirements_api.txt index d576405..4f975cf 100644 --- a/requirements_api.txt +++ b/requirements_api.txt @@ -1,66 +1,64 @@ # API requirements -langchain==0.0.344 -langchain-experimental>=0.0.42 +torch>=2.1.2 +torchvision>=0.16.2 +torchaudio>=2.1.2 + +langchain>=0.0.352 +langchain-experimental>=0.0.47 pydantic==1.10.13 -fschat>=0.2.33 -xformers>=0.0.22.post7 -sentence_transformers -transformers>=4.35.2 -torch==2.1.0 ##on Windows system, install the cuda version manually from https://pytorch.org/ -torchvision #on Windows system, install the cuda version manually from https://pytorch.org/ -torchaudio #on Windows system, install the cuda version manually from https://pytorch.org/ -openai>=1.3.7 -fastapi>=0.104 -sse_starlette +fschat>=0.2.34 +xformers>=0.0.23.post1 +openai>=1.6.0 +sentence_transformers>=2.2.2 +transformers>=4.36.2 +fastapi>=0.105 nltk>=3.8.1 uvicorn>=0.24.0.post1 starlette~=0.27.0 unstructured[all-docs]==0.11.0 python-magic-bin; sys_platform == 'win32' SQLAlchemy==2.0.19 -faiss-cpu # `conda install faiss-gpu -c conda-forge` if you want to accelerate with gpus +faiss-cpu>=1.7.4 accelerate>=0.24.1 spacy>=3.7.2 -PyMuPDF -rapidocr_onnxruntime +PyMuPDF>=1.23.8 +rapidocr_onnxruntime>=1.3.8 requests>=2.31.0 pathlib>=1.0.1 pytest>=7.4.3 -numexpr>=2.8.7 +numexpr>=2.8.8 strsimpy>=0.2.1 markdownify>=0.11.6 -tiktoken>=0.5.1 +tiktoken>=0.5.2 tqdm>=4.66.1 -websockets -numpy~=1.24.4 -pandas~=2.0.3 +websockets>=12.0 +numpy~=1.26.2 +pandas~=2.1.4 einops>=0.7.0 -transformers_stream_generator==0.0.4 -vllm==0.2.2; sys_platform == "linux" -httpx[brotli,http2,socks]>=0.25.2 +transformers_stream_generator>=0.0.4 +vllm>=0.2.6; sys_platform == "linux" # optional document loaders -# rapidocr_paddle[gpu] # gpu accelleration for ocr of pdf and image files -jq # for .json and .jsonl files. suggest `conda install jq` on windows -# html2text # for .enex files -# beautifulsoup4 # for .mhtml files -# pysrt # for .srt files + +rapidocr_paddle[gpu]>=1.3.0.post5 +jq>=1.6.0 +html2text +beautifulsoup4>=4.12.2 +pysrt>=1.1.2 # Online api libs dependencies -# zhipuai>=1.0.7 # zhipu -# dashscope>=1.10.0 # qwen -# volcengine>=1.0.106 # fangzhou - -# uncomment libs if you want to use corresponding vector store -# pymilvus==2.1.3 # requires milvus==2.1.3 -# psycopg2 +zhipuai>=1.0.7,<=2.0.0 +dashscope>=1.13.6 +volcengine>=1.0.119 +pymilvus>=2.3.4 +# psycopg2==2.9.9 # pgvector>=0.2.4 # Agent and Search Tools arxiv>=2.0.0 youtube-search>=2.1.2 -duckduckgo-search>=3.9.9 +duckduckgo-search>=4.1.0 metaphor-python>=0.1.23 \ No newline at end of file diff --git a/requirements_lite.txt b/requirements_lite.txt index 49a7867..b8c1af5 100644 --- a/requirements_lite.txt +++ b/requirements_lite.txt @@ -3,15 +3,9 @@ langchain==0.0.344 langchain-experimental>=0.0.42 pydantic==1.10.13 -fschat>=0.2.33 -# xformers>=0.0.22.post7 -# sentence_transformers -# transformers>=4.35.2 -# torch==2.1.0 ##on Windows system, install the cuda version manually from https://pytorch.org/ -# torchvision #on Windows system, install the cuda version manually from https://pytorch.org/ -# torchaudio #on Windows system, install the cuda version manually from https://pytorch.org/ -openai>=1.3.7 -fastapi>=0.104 +fschat>=0.2.34 +openai>=1.6.0 +fastapi>=0.105 sse_starlette nltk>=3.8.1 uvicorn>=0.24.0.post1 @@ -20,25 +14,16 @@ unstructured[docx,csv]==0.11.0 # add pdf if need python-magic-bin; sys_platform == 'win32' SQLAlchemy==2.0.19 faiss-cpu # `conda install faiss-gpu -c conda-forge` if you want to accelerate with gpus -# accelerate>=0.24.1 -# spacy>=3.7.2 -# PyMuPDF -# rapidocr_onnxruntime requests>=2.31.0 pathlib>=1.0.1 pytest>=7.4.3 numexpr>=2.8.7 strsimpy>=0.2.1 markdownify>=0.11.6 -# tiktoken>=0.5.1 tqdm>=4.66.1 websockets numpy~=1.24.4 pandas~=2.0.3 -# einops>=0.7.0 -# transformers_stream_generator==0.0.4 -# vllm==0.2.2; sys_platform == "linux" -httpx[brotli,http2,socks]>=0.25.2 # optional document loaders # rapidocr_paddle[gpu] # gpu accelleration for ocr of pdf and image files @@ -49,7 +34,7 @@ jq # for .json and .jsonl files. suggest `conda install jq` on windows # Online api libs dependencies -zhipuai>=1.0.7 # zhipu +zhipuai>=1.0.7,<=2.0.0 # zhipu dashscope>=1.10.0 # qwen # volcengine>=1.0.106 # fangzhou diff --git a/server/knowledge_base/kb_cache/base.py b/server/knowledge_base/kb_cache/base.py index 2b1b316..dc3291d 100644 --- a/server/knowledge_base/kb_cache/base.py +++ b/server/knowledge_base/kb_cache/base.py @@ -2,7 +2,7 @@ from langchain.embeddings.base import Embeddings from langchain.vectorstores.faiss import FAISS import threading from configs import (EMBEDDING_MODEL, CHUNK_SIZE, - logger, log_verbose) + logger, log_verbose) from server.utils import embedding_device, get_model_path, list_online_embed_models from contextlib import contextmanager from collections import OrderedDict @@ -99,10 +99,10 @@ class CachePool: return cache def load_kb_embeddings( - self, - kb_name: str, - embed_device: str = embedding_device(), - default_embed_model: str = EMBEDDING_MODEL, + self, + kb_name: str, + embed_device: str = embedding_device(), + default_embed_model: str = EMBEDDING_MODEL, ) -> Embeddings: from server.db.repository.knowledge_base_repository import get_kb_detail from server.knowledge_base.kb_service.base import EmbeddingsFunAdapter @@ -129,7 +129,7 @@ class EmbeddingsPool(CachePool): self.atomic.release() if model == "text-embedding-ada-002": # openai text-embedding-ada-002 from langchain.embeddings.openai import OpenAIEmbeddings - embeddings = OpenAIEmbeddings(model_name=model, + embeddings = OpenAIEmbeddings(model=model, openai_api_key=get_model_path(model), chunk_size=CHUNK_SIZE) elif 'bge-' in model: @@ -145,12 +145,13 @@ class EmbeddingsPool(CachePool): query_instruction = "" embeddings = HuggingFaceBgeEmbeddings(model_name=get_model_path(model), model_kwargs={'device': device}, - query_instruction=query_instruction) + query_instruction=query_instruction) if model == "bge-large-zh-noinstruct": # bge large -noinstruct embedding embeddings.query_instruction = "" else: from langchain.embeddings.huggingface import HuggingFaceEmbeddings - embeddings = HuggingFaceEmbeddings(model_name=get_model_path(model), model_kwargs={'device': device}) + embeddings = HuggingFaceEmbeddings(model_name=get_model_path(model), + model_kwargs={'device': device}) item.obj = embeddings item.finish_loading() else: diff --git a/tests/agent/test_agent_function.py b/tests/agent/test_agent_function.py deleted file mode 100644 index 27e5ae0..0000000 --- a/tests/agent/test_agent_function.py +++ /dev/null @@ -1,40 +0,0 @@ -import sys -import os -sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) -from configs import LLM_MODELS, TEMPERATURE -from server.utils import get_ChatOpenAI -from langchain.chains import LLMChain -from langchain.agents import LLMSingleActionAgent, AgentExecutor -from server.agent.tools import tools, tool_names -from langchain.memory import ConversationBufferWindowMemory - -memory = ConversationBufferWindowMemory(k=5) -model = get_ChatOpenAI( - model_name=LLM_MODELS[0], - temperature=TEMPERATURE, - ) -from server.agent.custom_template import CustomOutputParser, prompt - -output_parser = CustomOutputParser() -llm_chain = LLMChain(llm=model, prompt=prompt) -agent = LLMSingleActionAgent( - llm_chain=llm_chain, - output_parser=output_parser, - stop=["\nObservation:"], - allowed_tools=tool_names -) - -agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, memory=memory, verbose=True) - -import pytest -@pytest.mark.parametrize("text_prompt", - ["北京市朝阳区未来24小时天气如何?", # 天气功能函数 - "计算 (2 + 2312312)/4 是多少?", # 计算功能函数 - "翻译这句话成中文:Life is the art of drawing sufficient conclusions form insufficient premises."] # 翻译功能函数 -) -def test_different_agent_function(text_prompt): - try: - text_answer = agent_executor.run(text_prompt) - assert text_answer is not None - except Exception as e: - pytest.fail(f"agent_function failed with {text_prompt}, error: {str(e)}")