修复 Langchain 更新之后OpenAI在线embed无法正常使用问题
This commit is contained in:
parent
4e5bc8b399
commit
2e1442a5c1
|
|
@ -1,76 +1,77 @@
|
||||||
# API requirements
|
# API requirements
|
||||||
|
|
||||||
langchain==0.0.344
|
# On Windows system, install the cuda version manually from https://pytorch.org/
|
||||||
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
|
pydantic==1.10.13
|
||||||
fschat>=0.2.33
|
fschat>=0.2.33
|
||||||
xformers>=0.0.22.post7
|
xformers>=0.0.23.post1
|
||||||
sentence_transformers
|
openai>=1.6.0
|
||||||
transformers>=4.35.2
|
sentence_transformers>=2.2.2
|
||||||
torch==2.1.0 ##on Windows system, install the cuda version manually from https://pytorch.org/
|
transformers>=4.36.2
|
||||||
torchvision #on Windows system, install the cuda version manually from https://pytorch.org/
|
fastapi>=0.105
|
||||||
torchaudio #on Windows system, install the cuda version manually from https://pytorch.org/
|
|
||||||
openai>=1.3.7
|
|
||||||
fastapi>=0.104
|
|
||||||
sse_starlette
|
|
||||||
nltk>=3.8.1
|
nltk>=3.8.1
|
||||||
uvicorn>=0.24.0.post1
|
uvicorn>=0.24.0.post1
|
||||||
starlette~=0.27.0
|
starlette~=0.27.0
|
||||||
unstructured[all-docs]==0.11.0
|
unstructured[all-docs]==0.11.0
|
||||||
python-magic-bin; sys_platform == 'win32'
|
python-magic-bin; sys_platform == 'win32'
|
||||||
SQLAlchemy==2.0.19
|
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
|
accelerate>=0.24.1
|
||||||
spacy>=3.7.2
|
spacy>=3.7.2
|
||||||
PyMuPDF
|
PyMuPDF>=1.23.8
|
||||||
rapidocr_onnxruntime
|
rapidocr_onnxruntime>=1.3.8
|
||||||
requests>=2.31.0
|
requests>=2.31.0
|
||||||
pathlib>=1.0.1
|
pathlib>=1.0.1
|
||||||
pytest>=7.4.3
|
pytest>=7.4.3
|
||||||
numexpr>=2.8.7
|
numexpr>=2.8.8
|
||||||
strsimpy>=0.2.1
|
strsimpy>=0.2.1
|
||||||
markdownify>=0.11.6
|
markdownify>=0.11.6
|
||||||
tiktoken>=0.5.1
|
tiktoken>=0.5.2
|
||||||
tqdm>=4.66.1
|
tqdm>=4.66.1
|
||||||
websockets
|
websockets>=12.0
|
||||||
numpy~=1.24.4
|
numpy~=1.26.2
|
||||||
pandas~=2.0.3
|
pandas~=2.1.4
|
||||||
einops>=0.7.0
|
einops>=0.7.0
|
||||||
transformers_stream_generator==0.0.4
|
transformers_stream_generator>=0.0.4
|
||||||
vllm==0.2.2; sys_platform == "linux"
|
vllm>=0.2.6; sys_platform == "linux"
|
||||||
httpx[brotli,http2,socks]>=0.25.2
|
|
||||||
|
|
||||||
# optional document loaders
|
# 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
|
rapidocr_paddle[gpu]>=1.3.0.post5
|
||||||
# html2text # for .enex files
|
jq>=1.6.0
|
||||||
# beautifulsoup4 # for .mhtml files
|
html2text
|
||||||
# pysrt # for .srt files
|
beautifulsoup4>=4.12.2
|
||||||
|
pysrt>=1.1.2
|
||||||
|
|
||||||
# Online api libs dependencies
|
# Online api libs dependencies
|
||||||
|
|
||||||
# zhipuai>=1.0.7 # zhipu
|
zhipuai>=1.0.7
|
||||||
# dashscope>=1.10.0 # qwen
|
dashscope>=1.13.6
|
||||||
# volcengine>=1.0.106 # fangzhou
|
volcengine>=1.0.119
|
||||||
|
pymilvus>=2.3.4
|
||||||
# uncomment libs if you want to use corresponding vector store
|
# psycopg2==2.9.9
|
||||||
# pymilvus==2.1.3 # requires milvus==2.1.3
|
|
||||||
# psycopg2
|
|
||||||
# pgvector>=0.2.4
|
# pgvector>=0.2.4
|
||||||
|
|
||||||
# Agent and Search Tools
|
# Agent and Search Tools
|
||||||
|
|
||||||
arxiv>=2.0.0
|
arxiv>=2.0.0
|
||||||
youtube-search>=2.1.2
|
youtube-search>=2.1.2
|
||||||
duckduckgo-search>=3.9.9
|
duckduckgo-search>=4.1.0
|
||||||
metaphor-python>=0.1.23
|
metaphor-python>=0.1.23
|
||||||
|
|
||||||
# WebUI requirements
|
# 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-option-menu>=0.3.6
|
||||||
|
streamlit-antd-components>=0.2.4
|
||||||
streamlit-chatbox>=1.1.11
|
streamlit-chatbox>=1.1.11
|
||||||
streamlit-modal>=0.1.0
|
streamlit-modal>=0.1.0
|
||||||
streamlit-aggrid>=0.3.4.post3
|
streamlit-aggrid>=0.3.4.post3
|
||||||
|
httpx[brotli,http2,socks]>=0.25.2
|
||||||
watchdog>=3.0.0
|
watchdog>=3.0.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,64 @@
|
||||||
# API requirements
|
# API requirements
|
||||||
|
|
||||||
langchain==0.0.344
|
torch>=2.1.2
|
||||||
langchain-experimental>=0.0.42
|
torchvision>=0.16.2
|
||||||
|
torchaudio>=2.1.2
|
||||||
|
|
||||||
|
langchain>=0.0.352
|
||||||
|
langchain-experimental>=0.0.47
|
||||||
pydantic==1.10.13
|
pydantic==1.10.13
|
||||||
fschat>=0.2.33
|
fschat>=0.2.34
|
||||||
xformers>=0.0.22.post7
|
xformers>=0.0.23.post1
|
||||||
sentence_transformers
|
openai>=1.6.0
|
||||||
transformers>=4.35.2
|
sentence_transformers>=2.2.2
|
||||||
torch==2.1.0 ##on Windows system, install the cuda version manually from https://pytorch.org/
|
transformers>=4.36.2
|
||||||
torchvision #on Windows system, install the cuda version manually from https://pytorch.org/
|
fastapi>=0.105
|
||||||
torchaudio #on Windows system, install the cuda version manually from https://pytorch.org/
|
|
||||||
openai>=1.3.7
|
|
||||||
fastapi>=0.104
|
|
||||||
sse_starlette
|
|
||||||
nltk>=3.8.1
|
nltk>=3.8.1
|
||||||
uvicorn>=0.24.0.post1
|
uvicorn>=0.24.0.post1
|
||||||
starlette~=0.27.0
|
starlette~=0.27.0
|
||||||
unstructured[all-docs]==0.11.0
|
unstructured[all-docs]==0.11.0
|
||||||
python-magic-bin; sys_platform == 'win32'
|
python-magic-bin; sys_platform == 'win32'
|
||||||
SQLAlchemy==2.0.19
|
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
|
accelerate>=0.24.1
|
||||||
spacy>=3.7.2
|
spacy>=3.7.2
|
||||||
PyMuPDF
|
PyMuPDF>=1.23.8
|
||||||
rapidocr_onnxruntime
|
rapidocr_onnxruntime>=1.3.8
|
||||||
requests>=2.31.0
|
requests>=2.31.0
|
||||||
pathlib>=1.0.1
|
pathlib>=1.0.1
|
||||||
pytest>=7.4.3
|
pytest>=7.4.3
|
||||||
numexpr>=2.8.7
|
numexpr>=2.8.8
|
||||||
strsimpy>=0.2.1
|
strsimpy>=0.2.1
|
||||||
markdownify>=0.11.6
|
markdownify>=0.11.6
|
||||||
tiktoken>=0.5.1
|
tiktoken>=0.5.2
|
||||||
tqdm>=4.66.1
|
tqdm>=4.66.1
|
||||||
websockets
|
websockets>=12.0
|
||||||
numpy~=1.24.4
|
numpy~=1.26.2
|
||||||
pandas~=2.0.3
|
pandas~=2.1.4
|
||||||
einops>=0.7.0
|
einops>=0.7.0
|
||||||
transformers_stream_generator==0.0.4
|
transformers_stream_generator>=0.0.4
|
||||||
vllm==0.2.2; sys_platform == "linux"
|
vllm>=0.2.6; sys_platform == "linux"
|
||||||
httpx[brotli,http2,socks]>=0.25.2
|
|
||||||
|
|
||||||
# optional document loaders
|
# 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
|
rapidocr_paddle[gpu]>=1.3.0.post5
|
||||||
# html2text # for .enex files
|
jq>=1.6.0
|
||||||
# beautifulsoup4 # for .mhtml files
|
html2text
|
||||||
# pysrt # for .srt files
|
beautifulsoup4>=4.12.2
|
||||||
|
pysrt>=1.1.2
|
||||||
|
|
||||||
# Online api libs dependencies
|
# Online api libs dependencies
|
||||||
|
|
||||||
# zhipuai>=1.0.7 # zhipu
|
zhipuai>=1.0.7,<=2.0.0
|
||||||
# dashscope>=1.10.0 # qwen
|
dashscope>=1.13.6
|
||||||
# volcengine>=1.0.106 # fangzhou
|
volcengine>=1.0.119
|
||||||
|
pymilvus>=2.3.4
|
||||||
# uncomment libs if you want to use corresponding vector store
|
# psycopg2==2.9.9
|
||||||
# pymilvus==2.1.3 # requires milvus==2.1.3
|
|
||||||
# psycopg2
|
|
||||||
# pgvector>=0.2.4
|
# pgvector>=0.2.4
|
||||||
|
|
||||||
# Agent and Search Tools
|
# Agent and Search Tools
|
||||||
|
|
||||||
arxiv>=2.0.0
|
arxiv>=2.0.0
|
||||||
youtube-search>=2.1.2
|
youtube-search>=2.1.2
|
||||||
duckduckgo-search>=3.9.9
|
duckduckgo-search>=4.1.0
|
||||||
metaphor-python>=0.1.23
|
metaphor-python>=0.1.23
|
||||||
|
|
@ -3,15 +3,9 @@
|
||||||
langchain==0.0.344
|
langchain==0.0.344
|
||||||
langchain-experimental>=0.0.42
|
langchain-experimental>=0.0.42
|
||||||
pydantic==1.10.13
|
pydantic==1.10.13
|
||||||
fschat>=0.2.33
|
fschat>=0.2.34
|
||||||
# xformers>=0.0.22.post7
|
openai>=1.6.0
|
||||||
# sentence_transformers
|
fastapi>=0.105
|
||||||
# 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
|
sse_starlette
|
||||||
nltk>=3.8.1
|
nltk>=3.8.1
|
||||||
uvicorn>=0.24.0.post1
|
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'
|
python-magic-bin; sys_platform == 'win32'
|
||||||
SQLAlchemy==2.0.19
|
SQLAlchemy==2.0.19
|
||||||
faiss-cpu # `conda install faiss-gpu -c conda-forge` if you want to accelerate with gpus
|
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
|
requests>=2.31.0
|
||||||
pathlib>=1.0.1
|
pathlib>=1.0.1
|
||||||
pytest>=7.4.3
|
pytest>=7.4.3
|
||||||
numexpr>=2.8.7
|
numexpr>=2.8.7
|
||||||
strsimpy>=0.2.1
|
strsimpy>=0.2.1
|
||||||
markdownify>=0.11.6
|
markdownify>=0.11.6
|
||||||
# tiktoken>=0.5.1
|
|
||||||
tqdm>=4.66.1
|
tqdm>=4.66.1
|
||||||
websockets
|
websockets
|
||||||
numpy~=1.24.4
|
numpy~=1.24.4
|
||||||
pandas~=2.0.3
|
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
|
# optional document loaders
|
||||||
# rapidocr_paddle[gpu] # gpu accelleration for ocr of pdf and image files
|
# 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
|
# Online api libs dependencies
|
||||||
|
|
||||||
zhipuai>=1.0.7 # zhipu
|
zhipuai>=1.0.7,<=2.0.0 # zhipu
|
||||||
dashscope>=1.10.0 # qwen
|
dashscope>=1.10.0 # qwen
|
||||||
# volcengine>=1.0.106 # fangzhou
|
# volcengine>=1.0.106 # fangzhou
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from langchain.embeddings.base import Embeddings
|
||||||
from langchain.vectorstores.faiss import FAISS
|
from langchain.vectorstores.faiss import FAISS
|
||||||
import threading
|
import threading
|
||||||
from configs import (EMBEDDING_MODEL, CHUNK_SIZE,
|
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 server.utils import embedding_device, get_model_path, list_online_embed_models
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
@ -99,10 +99,10 @@ class CachePool:
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
def load_kb_embeddings(
|
def load_kb_embeddings(
|
||||||
self,
|
self,
|
||||||
kb_name: str,
|
kb_name: str,
|
||||||
embed_device: str = embedding_device(),
|
embed_device: str = embedding_device(),
|
||||||
default_embed_model: str = EMBEDDING_MODEL,
|
default_embed_model: str = EMBEDDING_MODEL,
|
||||||
) -> Embeddings:
|
) -> Embeddings:
|
||||||
from server.db.repository.knowledge_base_repository import get_kb_detail
|
from server.db.repository.knowledge_base_repository import get_kb_detail
|
||||||
from server.knowledge_base.kb_service.base import EmbeddingsFunAdapter
|
from server.knowledge_base.kb_service.base import EmbeddingsFunAdapter
|
||||||
|
|
@ -129,7 +129,7 @@ class EmbeddingsPool(CachePool):
|
||||||
self.atomic.release()
|
self.atomic.release()
|
||||||
if model == "text-embedding-ada-002": # openai text-embedding-ada-002
|
if model == "text-embedding-ada-002": # openai text-embedding-ada-002
|
||||||
from langchain.embeddings.openai import OpenAIEmbeddings
|
from langchain.embeddings.openai import OpenAIEmbeddings
|
||||||
embeddings = OpenAIEmbeddings(model_name=model,
|
embeddings = OpenAIEmbeddings(model=model,
|
||||||
openai_api_key=get_model_path(model),
|
openai_api_key=get_model_path(model),
|
||||||
chunk_size=CHUNK_SIZE)
|
chunk_size=CHUNK_SIZE)
|
||||||
elif 'bge-' in model:
|
elif 'bge-' in model:
|
||||||
|
|
@ -150,7 +150,8 @@ class EmbeddingsPool(CachePool):
|
||||||
embeddings.query_instruction = ""
|
embeddings.query_instruction = ""
|
||||||
else:
|
else:
|
||||||
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
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.obj = embeddings
|
||||||
item.finish_loading()
|
item.finish_loading()
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -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)}")
|
|
||||||
Loading…
Reference in New Issue