Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
•
066e779
1
Parent(s):
073a231
为非Pro模式的川虎助理使用Google搜索
Browse files
modules/models/ChuanhuAgent.py
CHANGED
@@ -14,6 +14,7 @@ from langchain.tools import BaseTool, StructuredTool, Tool, tool
|
|
14 |
from langchain.callbacks.stdout import StdOutCallbackHandler
|
15 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
16 |
from langchain.callbacks.manager import BaseCallbackManager
|
|
|
17 |
|
18 |
from typing import Any, Dict, List, Optional, Union
|
19 |
|
@@ -38,6 +39,9 @@ import os
|
|
38 |
import gradio as gr
|
39 |
import logging
|
40 |
|
|
|
|
|
|
|
41 |
class WebBrowsingInput(BaseModel):
|
42 |
url: str = Field(description="URL of a webpage")
|
43 |
|
@@ -61,6 +65,14 @@ class ChuanhuAgent_Client(BaseLLMModel):
|
|
61 |
self.tools = load_tools(["google-search-results-json", "llm-math", "arxiv", "wikipedia", "wolfram-alpha"], llm=self.llm)
|
62 |
else:
|
63 |
self.tools = load_tools(["ddg-search", "llm-math", "arxiv", "wikipedia"], llm=self.llm)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
self.tools.append(
|
66 |
Tool.from_function(
|
@@ -80,6 +92,10 @@ class ChuanhuAgent_Client(BaseLLMModel):
|
|
80 |
)
|
81 |
)
|
82 |
|
|
|
|
|
|
|
|
|
83 |
def handle_file_upload(self, files, chatbot, language):
|
84 |
"""if the model accepts multi modal input, implement this function"""
|
85 |
status = gr.Markdown.update()
|
|
|
14 |
from langchain.callbacks.stdout import StdOutCallbackHandler
|
15 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
16 |
from langchain.callbacks.manager import BaseCallbackManager
|
17 |
+
from googlesearch import search
|
18 |
|
19 |
from typing import Any, Dict, List, Optional, Union
|
20 |
|
|
|
39 |
import gradio as gr
|
40 |
import logging
|
41 |
|
42 |
+
class GoogleSearchInput(BaseModel):
|
43 |
+
keywords: str = Field(description="keywords to search")
|
44 |
+
|
45 |
class WebBrowsingInput(BaseModel):
|
46 |
url: str = Field(description="URL of a webpage")
|
47 |
|
|
|
65 |
self.tools = load_tools(["google-search-results-json", "llm-math", "arxiv", "wikipedia", "wolfram-alpha"], llm=self.llm)
|
66 |
else:
|
67 |
self.tools = load_tools(["ddg-search", "llm-math", "arxiv", "wikipedia"], llm=self.llm)
|
68 |
+
self.tools.append(
|
69 |
+
Tool.from_function(
|
70 |
+
func=self.google_search_simple,
|
71 |
+
name="Google Search JSON",
|
72 |
+
description="useful when you need to search the web.",
|
73 |
+
args_schema=GoogleSearchInput
|
74 |
+
)
|
75 |
+
)
|
76 |
|
77 |
self.tools.append(
|
78 |
Tool.from_function(
|
|
|
92 |
)
|
93 |
)
|
94 |
|
95 |
+
def google_search_simple(self, query):
|
96 |
+
results = [{"title": i.title, "url": i.url, "description": i.description} for i in search(query, advanced=True)]
|
97 |
+
return str(results)
|
98 |
+
|
99 |
def handle_file_upload(self, files, chatbot, language):
|
100 |
"""if the model accepts multi modal input, implement this function"""
|
101 |
status = gr.Markdown.update()
|