Spaces:
Paused
Paused
netman19731
commited on
Commit
•
9c6ef48
1
Parent(s):
f85479f
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,25 @@
|
|
1 |
-
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
|
|
4 |
from http import HTTPStatus
|
5 |
import json
|
6 |
-
from langchain.llms import Tongyi
|
|
|
7 |
from langchain import hub
|
8 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
9 |
from langchain.tools import tool
|
10 |
-
from
|
|
|
|
|
|
|
11 |
from pinecone import Pinecone, ServerlessSpec
|
12 |
-
from langchain.vectorstores import Pinecone as Pinecone_VectorStore
|
|
|
13 |
from langchain.tools.retriever import create_retriever_tool
|
14 |
from langchain.agents import AgentExecutor,create_react_agent
|
15 |
-
|
16 |
os.environ['TAVILY_API_KEY'] = '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'
|
17 |
@tool
|
18 |
def tqyb(query: str) -> str:
|
@@ -26,14 +33,23 @@ def tqyb(query: str) -> str:
|
|
26 |
else:
|
27 |
return f"请求失败,状态码:{response.status_code}"
|
28 |
|
|
|
29 |
|
30 |
-
|
|
|
|
|
31 |
prompt = hub.pull("hwchase17/react")
|
32 |
search = TavilySearchResults(max_results=1)
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
pc = Pinecone(api_key='3538cd3c-eca8-4c61-9463-759f5ea65b10')
|
36 |
-
index = pc.Index("
|
37 |
vectorstore = Pinecone_VectorStore(index, embeddings.embed_query, "text")
|
38 |
db=vectorstore.as_retriever()
|
39 |
retriever_tool = create_retriever_tool(
|
@@ -49,9 +65,8 @@ agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
|
49 |
async def predict(question):
|
50 |
que={"input":question}
|
51 |
res=agent_executor.invoke(que)
|
52 |
-
print(res)
|
53 |
if res:
|
54 |
-
return(res)
|
55 |
else:print("不好意思,出了一个小问题,请联系我的微信:13603634456")
|
56 |
|
57 |
|
@@ -60,5 +75,3 @@ gr.Interface(
|
|
60 |
outputs="textbox",
|
61 |
title="定制版AI专家BOT",
|
62 |
description="这是一个定制版的AI专家BOT,你可以通过输入问题,让AI为你回答。\n目前提供三个示例工具:\n1.天气预报(函数调用API)\n2.双城区情检索(增强型检索RAG)\n3.搜索引擎").launch()
|
63 |
-
|
64 |
-
|
|
|
1 |
+
#有2个embedding库,HuggingFaceHubEmbeddings和HuggingFaceBgeEmbeddings,分别是云端和本地的,
|
2 |
+
#对应pinecone有2个index,分别是myindex01和myindex
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
+
import dashscope
|
6 |
from http import HTTPStatus
|
7 |
import json
|
8 |
+
# from langchain.llms import Tongyi
|
9 |
+
from langchain_community.llms import Tongyi,ChatGLM ,OpenAI
|
10 |
from langchain import hub
|
11 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
12 |
from langchain.tools import tool
|
13 |
+
# from langchain_community.embeddings import TensorflowHubEmbeddings
|
14 |
+
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
15 |
+
from langchain_community.embeddings import HuggingFaceHubEmbeddings
|
16 |
+
from langchain_community.llms import HuggingFaceHub
|
17 |
from pinecone import Pinecone, ServerlessSpec
|
18 |
+
# from langchain.vectorstores import Pinecone as Pinecone_VectorStore
|
19 |
+
from langchain_community.vectorstores import Pinecone as Pinecone_VectorStore
|
20 |
from langchain.tools.retriever import create_retriever_tool
|
21 |
from langchain.agents import AgentExecutor,create_react_agent
|
22 |
+
import os
|
23 |
os.environ['TAVILY_API_KEY'] = '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'
|
24 |
@tool
|
25 |
def tqyb(query: str) -> str:
|
|
|
33 |
else:
|
34 |
return f"请求失败,状态码:{response.status_code}"
|
35 |
|
36 |
+
os.environ['OPENAI_API_KEY']="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"
|
37 |
|
38 |
+
|
39 |
+
llm = HuggingFaceHub(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", model_kwargs={"temperature": 0.5, "max_length": 64})
|
40 |
+
# llm = Tongyi(dashscope_api_key="sk-78c45d761ed04af2b965b43cd522108b",model="qwen-72b-chat")
|
41 |
prompt = hub.pull("hwchase17/react")
|
42 |
search = TavilySearchResults(max_results=1)
|
43 |
|
44 |
+
model_name = "BAAI/bge-small-en"
|
45 |
+
model_kwargs = {"device": "cpu"}
|
46 |
+
encode_kwargs = {"normalize_embeddings": True}
|
47 |
+
# embeddings = HuggingFaceBgeEmbeddings(
|
48 |
+
# model_name=model_name, model_kwargs=model_kwargs, encode_kwargs=encode_kwargs
|
49 |
+
# )
|
50 |
+
embeddings = HuggingFaceHubEmbeddings()
|
51 |
pc = Pinecone(api_key='3538cd3c-eca8-4c61-9463-759f5ea65b10')
|
52 |
+
index = pc.Index("myindex01")
|
53 |
vectorstore = Pinecone_VectorStore(index, embeddings.embed_query, "text")
|
54 |
db=vectorstore.as_retriever()
|
55 |
retriever_tool = create_retriever_tool(
|
|
|
65 |
async def predict(question):
|
66 |
que={"input":question}
|
67 |
res=agent_executor.invoke(que)
|
|
|
68 |
if res:
|
69 |
+
return(res["output"])
|
70 |
else:print("不好意思,出了一个小问题,请联系我的微信:13603634456")
|
71 |
|
72 |
|
|
|
75 |
outputs="textbox",
|
76 |
title="定制版AI专家BOT",
|
77 |
description="这是一个定制版的AI专家BOT,你可以通过输入问题,让AI为你回答。\n目前提供三个示例工具:\n1.天气预报(函数调用API)\n2.双城区情检索(增强型检索RAG)\n3.搜索引擎").launch()
|
|
|
|