Spaces:
Runtime error
Runtime error
Commit
·
860b20f
1
Parent(s):
ae678bc
create new tool list
Browse files
app.py
CHANGED
@@ -228,6 +228,18 @@ class DB_Search(BaseTool):
|
|
228 |
def _arun(self, query: str):
|
229 |
raise NotImplementedError("N/A")
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
def Text2Sound(text):
|
232 |
|
233 |
speech_config = speechsdk.SpeechConfig(subscription=os.getenv('SPEECH_KEY'), region=os.getenv('SPEECH_REGION'))
|
@@ -312,6 +324,14 @@ Text2Sound_tool = Tool(
|
|
312 |
description = "Useful when you need to convert text into sound file."
|
313 |
)
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
Wikipedia = WikipediaAPIWrapper()
|
316 |
Netsearch = DuckDuckGoSearchRun()
|
317 |
Python_REPL = PythonREPL()
|
@@ -334,6 +354,26 @@ python_tool = Tool(
|
|
334 |
description = "Useful when you need python to answer questions. You should input python code."
|
335 |
)
|
336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
# tools = [DB_Search(), wikipedia_tool, duckduckgo_tool, python_tool]
|
338 |
|
339 |
|
@@ -362,8 +402,12 @@ math_tool = Tool(
|
|
362 |
description ='Useful for when you need to answer questions about math.'
|
363 |
)
|
364 |
|
|
|
|
|
365 |
tools = [DB_Search(), duckduckgo_tool, wikipedia_tool, python_tool, math_tool, Text2Sound_tool]
|
366 |
|
|
|
|
|
367 |
# tools = load_tools(["Vector Database Search","Wikipedia Search","Python REPL","llm-math"], llm=llm)
|
368 |
|
369 |
embeddings = OpenAIEmbeddings(deployment="model_embedding", chunk_size=15)
|
@@ -442,7 +486,7 @@ prompt_openai = OpenAIMultiFunctionsAgent.create_prompt(
|
|
442 |
|
443 |
input_variables=["input", "chat_history", "agent_scratchpad"]
|
444 |
|
445 |
-
agent_ZEROSHOT_REACT = initialize_agent(
|
446 |
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
447 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
448 |
verbose = True,
|
@@ -466,13 +510,13 @@ llm_chain = LLMChain(llm=llm, prompt=prompt)
|
|
466 |
|
467 |
# llm_chain_openai = LLMChain(llm=llm, prompt=prompt_openai, verbose=True)
|
468 |
|
469 |
-
agent_core = ZeroShotAgent(llm_chain=llm_chain, tools=
|
470 |
|
471 |
agent_core_openai = OpenAIMultiFunctionsAgent(llm=llm, tools=tools, prompt=prompt_openai, verbose=True)
|
472 |
|
473 |
agent_ZEROSHOT_AGENT = AgentExecutor.from_agent_and_tools(
|
474 |
agent=agent_core,
|
475 |
-
tools=
|
476 |
verbose=True,
|
477 |
# memory=memory,
|
478 |
handle_parsing_errors = True,
|
|
|
228 |
def _arun(self, query: str):
|
229 |
raise NotImplementedError("N/A")
|
230 |
|
231 |
+
class DB_Search2(BaseTool):
|
232 |
+
name = "Vector Database Search"
|
233 |
+
description = "This is the internal database to search information firstly. If information is found, it is trustful."
|
234 |
+
def _run(self, query: str) -> str:
|
235 |
+
response, source = QAQuery_p(query)
|
236 |
+
# response = "test db_search feedback"
|
237 |
+
return response
|
238 |
+
|
239 |
+
def _arun(self, query: str):
|
240 |
+
raise NotImplementedError("N/A")
|
241 |
+
|
242 |
+
|
243 |
def Text2Sound(text):
|
244 |
|
245 |
speech_config = speechsdk.SpeechConfig(subscription=os.getenv('SPEECH_KEY'), region=os.getenv('SPEECH_REGION'))
|
|
|
324 |
description = "Useful when you need to convert text into sound file."
|
325 |
)
|
326 |
|
327 |
+
Text2Sound_tool2 = Tool(
|
328 |
+
name = "Text To Sound REST API",
|
329 |
+
# func = Text2Sound,
|
330 |
+
func = text_to_speech_2,
|
331 |
+
description = "Useful when you need to convert text into sound file."
|
332 |
+
)
|
333 |
+
|
334 |
+
|
335 |
Wikipedia = WikipediaAPIWrapper()
|
336 |
Netsearch = DuckDuckGoSearchRun()
|
337 |
Python_REPL = PythonREPL()
|
|
|
354 |
description = "Useful when you need python to answer questions. You should input python code."
|
355 |
)
|
356 |
|
357 |
+
wikipedia_tool2 = Tool(
|
358 |
+
name = "Wikipedia Search",
|
359 |
+
func = Wikipedia.run,
|
360 |
+
description = "Useful to search a topic, country or person when there is no availble information in vector database"
|
361 |
+
)
|
362 |
+
|
363 |
+
duckduckgo_tool2 = Tool(
|
364 |
+
name = "Duckduckgo Internet Search",
|
365 |
+
func = Netsearch.run,
|
366 |
+
description = "Useful to search information in internet when it is not available in other tools"
|
367 |
+
)
|
368 |
+
|
369 |
+
python_tool2 = Tool(
|
370 |
+
name = "Python REPL",
|
371 |
+
func = Python_REPL.run,
|
372 |
+
description = "Useful when you need python to answer questions. You should input python code."
|
373 |
+
)
|
374 |
+
|
375 |
+
|
376 |
+
|
377 |
# tools = [DB_Search(), wikipedia_tool, duckduckgo_tool, python_tool]
|
378 |
|
379 |
|
|
|
402 |
description ='Useful for when you need to answer questions about math.'
|
403 |
)
|
404 |
|
405 |
+
|
406 |
+
|
407 |
tools = [DB_Search(), duckduckgo_tool, wikipedia_tool, python_tool, math_tool, Text2Sound_tool]
|
408 |
|
409 |
+
tools2 = [DB_Search2(), duckduckgo_tool2, wikipedia_tool2, python_tool2, math_tool, Text2Sound_tool2]
|
410 |
+
|
411 |
# tools = load_tools(["Vector Database Search","Wikipedia Search","Python REPL","llm-math"], llm=llm)
|
412 |
|
413 |
embeddings = OpenAIEmbeddings(deployment="model_embedding", chunk_size=15)
|
|
|
486 |
|
487 |
input_variables=["input", "chat_history", "agent_scratchpad"]
|
488 |
|
489 |
+
agent_ZEROSHOT_REACT = initialize_agent(tools2, llm,
|
490 |
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
491 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
492 |
verbose = True,
|
|
|
510 |
|
511 |
# llm_chain_openai = LLMChain(llm=llm, prompt=prompt_openai, verbose=True)
|
512 |
|
513 |
+
agent_core = ZeroShotAgent(llm_chain=llm_chain, tools=tools2, verbose=True)
|
514 |
|
515 |
agent_core_openai = OpenAIMultiFunctionsAgent(llm=llm, tools=tools, prompt=prompt_openai, verbose=True)
|
516 |
|
517 |
agent_ZEROSHOT_AGENT = AgentExecutor.from_agent_and_tools(
|
518 |
agent=agent_core,
|
519 |
+
tools=tools2,
|
520 |
verbose=True,
|
521 |
# memory=memory,
|
522 |
handle_parsing_errors = True,
|