Spaces:
Runtime error
Runtime error
Commit
·
98ad3a1
1
Parent(s):
d80c981
Add several new tools
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from typing import Any, Coroutine
|
2 |
import openai
|
3 |
import os
|
4 |
from langchain.vectorstores import Chroma
|
@@ -10,8 +10,11 @@ from langchain.chains import RetrievalQA
|
|
10 |
from langchain.vectorstores import Pinecone
|
11 |
from langchain.agents import initialize_agent
|
12 |
from langchain.agents import AgentType
|
13 |
-
from langchain.agents import
|
14 |
from langchain.tools import BaseTool
|
|
|
|
|
|
|
15 |
|
16 |
import pinecone
|
17 |
from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
|
@@ -20,7 +23,7 @@ import time
|
|
20 |
|
21 |
class DB_Search(BaseTool):
|
22 |
name = "Vector Database Search"
|
23 |
-
description = "This is the vector database to search
|
24 |
def _run(self, query: str) -> str:
|
25 |
response, source = QAQuery_p(query)
|
26 |
# response = "test db_search feedback"
|
@@ -29,9 +32,31 @@ class DB_Search(BaseTool):
|
|
29 |
def _arun(self, query: str):
|
30 |
raise NotImplementedError("N/A")
|
31 |
|
32 |
-
tools = [DB_Search()]
|
33 |
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
os.environ["OPENAI_API_TYPE"] = "azure"
|
37 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
|
|
1 |
+
# from typing import Any, Coroutine
|
2 |
import openai
|
3 |
import os
|
4 |
from langchain.vectorstores import Chroma
|
|
|
10 |
from langchain.vectorstores import Pinecone
|
11 |
from langchain.agents import initialize_agent
|
12 |
from langchain.agents import AgentType
|
13 |
+
from langchain.agents import Tool
|
14 |
from langchain.tools import BaseTool
|
15 |
+
from langchain.tools import DuckDuckGoSearchRun
|
16 |
+
from langchain.utilities import WikipediaAPIWrapper
|
17 |
+
from langchain.python import PythonREPL
|
18 |
|
19 |
import pinecone
|
20 |
from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
|
|
|
23 |
|
24 |
class DB_Search(BaseTool):
|
25 |
name = "Vector Database Search"
|
26 |
+
description = "This is the vector database to search information firstly"
|
27 |
def _run(self, query: str) -> str:
|
28 |
response, source = QAQuery_p(query)
|
29 |
# response = "test db_search feedback"
|
|
|
32 |
def _arun(self, query: str):
|
33 |
raise NotImplementedError("N/A")
|
34 |
|
|
|
35 |
|
36 |
|
37 |
+
Wikipedia = WikipediaAPIWrapper()
|
38 |
+
Netsearch = DuckDuckGoSearchRun()
|
39 |
+
Python_REPL = PythonREPL()
|
40 |
+
|
41 |
+
wikipedia_tool = Tool(
|
42 |
+
name = "Wikipedia Search",
|
43 |
+
func = Wikipedia.run(),
|
44 |
+
description = "Useful to search a topic, country or person when there is no availble information in vector database"
|
45 |
+
)
|
46 |
+
|
47 |
+
duckduckgo_tool = Tool(
|
48 |
+
name = "Duckduckgo Internet Search",
|
49 |
+
func = Python_REPL.run(),
|
50 |
+
description = "Useful to search information in internet when it is not available in other tools"
|
51 |
+
)
|
52 |
+
|
53 |
+
python_tool = Tool(
|
54 |
+
name = "Python REPL",
|
55 |
+
func = Netsearch.run(),
|
56 |
+
description = "Useful when you need python to answer questions. You should input python code."
|
57 |
+
)
|
58 |
+
|
59 |
+
tools = [DB_Search(), wikipedia_tool, duckduckgo_tool, python_tool]
|
60 |
|
61 |
os.environ["OPENAI_API_TYPE"] = "azure"
|
62 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|