2121from langchain_community .utilities .wikidata import WikidataAPIWrapper
2222from langchain_core .documents import Document
2323
24- from . callable_registers import register_callable_tool
24+ from fitframework . api . decorators import fitable
2525
26-
27- def langchain_network (** kwargs ) -> str :
26+ def langchain_network () -> str :
2827 time .sleep (5 )
2928 return ""
3029
31-
32- def arxiv (arxiv_id : str , ** kwargs ) -> List [str ]:
30+ @ fitable ( "langchain.tool.arxiv" , "default" )
31+ def arxiv (arxiv_id : str ) -> List [str ]:
3332 retriever = ArxivRetriever (load_max_docs = 2 )
3433 docs : List [Document ] = retriever .get_relevant_documents (query = arxiv_id )
3534 return [doc .page_content for doc in docs ]
3635
37-
38- def bing_search (query : str , bing_subscription_key : str , bing_search_url : str , ** kwargs ) -> str :
36+ @ fitable ( "langchain.tool.bing_search" , "default" )
37+ def bing_search (query : str , bing_subscription_key : str , bing_search_url : str ) -> str :
3938 os .environ ["BING_SUBSCRIPTION_KEY" ] = bing_subscription_key
4039 os .environ ["BING_SEARCH_URL" ] = bing_search_url
4140 search = BingSearchAPIWrapper ()
4241 return search .run (query )
4342
44-
45- def brave_search (query : str , count : int , api_key : str , ** kwargs ) -> str :
43+ @ fitable ( "langchain.tool.brave_search" , "default" )
44+ def brave_search (query : str , count : int , api_key : str ) -> str :
4645 brave_search_ = BraveSearch .from_api_key (api_key = api_key , search_kwargs = {"count" : count })
4746 return brave_search_ .run (query )
4847
49-
50- def duck_duck_go_search (query : str , ** kwargs ) -> str :
48+ @ fitable ( "langchain.tool.duck_duck_go_search" , "default" )
49+ def duck_duck_go_search (query : str ) -> str :
5150 search = DuckDuckGoSearchRun ()
5251 return search .invoke (query )
5352
54-
55- def google_jobs (query : str , serapi_api_key : str , ** kwargs ) -> str :
53+ @ fitable ( "langchain.tool.google_jobs" , "default" )
54+ def google_jobs (query : str , serapi_api_key : str ) -> str :
5655 os .environ ["SERPAPI_API_KEY" ] = serapi_api_key
5756 google_job_tool = GoogleJobsQueryRun (api_wrapper = GoogleJobsAPIWrapper ())
5857 return google_job_tool .run (query )
5958
60-
61- def google_places (query : str , gplaces_api_key : str , ** kwargs ) -> str :
59+ @ fitable ( "langchain.tool.google_places" , "default" )
60+ def google_places (query : str , gplaces_api_key : str ) -> str :
6261 os .environ ["GPLACES_API_KEY" ] = gplaces_api_key
6362 places = GooglePlacesTool ()
6463 return places .run (query )
6564
66-
67- def google_scholar (query : str , serp_api_key : str , ** kwargs ) -> str :
65+ @ fitable ( "langchain.tool.google_scholar" , "default" )
66+ def google_scholar (query : str , serp_api_key : str ) -> str :
6867 os .environ ["SERP_API_KEY" ] = serp_api_key
6968 google_job_tool = GoogleScholarQueryRun (api_wrapper = GoogleScholarAPIWrapper ())
7069 return google_job_tool .run (query )
7170
72-
73- def google_search (query : str , google_api_key : str , google_cse_id : str , k : int , siterestrict : bool , ** kwargs ) -> str :
71+ @ fitable ( "langchain.tool.google_search" , "default" )
72+ def google_search (query : str , google_api_key : str , google_cse_id : str , k : int , siterestrict : bool ) -> str :
7473 wrapper = GoogleSearchAPIWrapper (google_api_key = google_api_key , google_cse_id = google_cse_id , k = k ,
7574 siterestrict = siterestrict )
7675 search = GoogleSearchRun (api_wrapper = wrapper )
7776 return search .run (query )
7877
79-
80- def google_serper (query : str , k : int , gl : str , hl : str , serper_api_key : str , ** kwargs ) -> str :
78+ @ fitable ( "langchain.tool.google_serper" , "default" )
79+ def google_serper (query : str , k : int , gl : str , hl : str , serper_api_key : str ) -> str :
8180 os .environ ["SERPER_API_KEY" ] = serper_api_key
8281 search = GoogleSerperAPIWrapper (k = k , gl = gl , hl = hl )
8382 return search .run (query )
8483
85-
86- def golden_query (query : str , golden_api_key : str , ** kwargs ) -> str :
84+ @ fitable ( "langchain.tool.golden_query" , "default" )
85+ def golden_query (query : str , golden_api_key : str ) -> str :
8786 os .environ ["GOLDEN_API_KEY" ] = golden_api_key
8887 golden_query_api = GoldenQueryAPIWrapper ()
8988 return golden_query_api .run (query )
9089
91-
90+ @ fitable ( "langchain.tool.pub_med" , "default" )
9291def pub_med (query : str ) -> str :
9392 pub_med_tool : PubmedQueryRun = PubmedQueryRun ()
9493 return pub_med_tool .invoke (query )
9594
96-
95+ @ fitable ( "langchain.tool.mojeek_query" , "default" )
9796def mojeek_query (query : str , api_key : str ) -> str :
9897 search = MojeekSearch .config (api_key = api_key )
9998 return search .run (query )
10099
101-
100+ @ fitable ( "langchain.tool.reddit_search" , "default" )
102101def reddit_search (query : str , sort : str , time_filter : str , subreddit : str , limit : str , client_id : str ,
103102 client_secret : str , user_agent : str ) -> str :
104103 search = RedditSearchRun (
@@ -113,17 +112,17 @@ def reddit_search(query: str, sort: str, time_filter: str, subreddit: str, limit
113112 result = search .run (tool_input = search_params .dict ())
114113 return result
115114
116-
115+ @ fitable ( "langchain.tool.searxng_search" , "default" )
117116def searxng_search (query : str , searx_host : str ) -> str :
118117 search = SearxSearchWrapper (searx_host = searx_host )
119118 return search .run (query )
120119
121-
120+ @ fitable ( "langchain.tool.serp_api" , "default" )
122121def serp_api (query : str , serpapi_api_key : str ) -> str :
123122 search = SerpAPIWrapper (serpapi_api_key = serpapi_api_key )
124123 return search .run (query )
125124
126-
125+ @ fitable ( "langchain.tool.twilio" , "default" )
127126def twilio (body : str , to : str , account_sid : str , auth_token : str , from_number : str ) -> str :
128127 twilio_api = TwilioAPIWrapper (
129128 account_sid = account_sid ,
@@ -132,52 +131,22 @@ def twilio(body: str, to: str, account_sid: str, auth_token: str, from_number: s
132131 )
133132 return twilio_api .run (body , to )
134133
135-
134+ @ fitable ( "langchain.tool.wikidata" , "default" )
136135def wikidata (query : str ) -> str :
137136 wikidata_query = WikidataQueryRun (api_wrapper = WikidataAPIWrapper ())
138137 return wikidata_query .run (query )
139138
140-
141- def wikipedia (query : str , ** kwargs ) -> str :
139+ @ fitable ( "langchain.tool.wikipedia" , "default" )
140+ def wikipedia (query : str ) -> str :
142141 wikipedia_query_run = WikipediaQueryRun (api_wrapper = WikipediaAPIWrapper ())
143142 return wikipedia_query_run .run (query )
144143
145-
144+ @ fitable ( "langchain.tool.wolfram_alpha" , "default" )
146145def wolfram_alpha (query : str , wolfram_alpha_appid : str ) -> str :
147146 wolfram = WolframAlphaAPIWrapper (wolfram_alpha_appid = wolfram_alpha_appid )
148147 return wolfram .run (query )
149148
150-
151- def youtube_search (query : str , ** kwargs ) -> str :
149+ @ fitable ( "langchain.tool.youtube_search" , "default" )
150+ def youtube_search (query : str ) -> str :
152151 youtube_search_tool = YouTubeSearchTool ()
153152 return youtube_search_tool .run (query )
154-
155-
156- # Tuple 结构: (tool_func, config_args, return_description)
157- network_toolkit : List [Tuple [Callable [..., Any ], List [str ], str ]] = [
158- (langchain_network , ["input" ], "Youtube search." ),
159- (arxiv , ["arxiv_id" ], "ArXiv search." ),
160- (bing_search , ["query" , "bing_subscription_key" , "bing_search_url" ], "Bing search." ),
161- (brave_search , ["query" , "count" , "api_key" ], "Brave search." ),
162- (duck_duck_go_search , ["query" ], "DuckDuckGo Search." ),
163- (google_jobs , ["query" , "serapi_api_key" ], "Google Jobs." ),
164- (google_places , ["query" , "gplaces_api_key" ], "Google Places." ),
165- (google_scholar , ["query" , "serp_api_key" ], "Google Scholar." ),
166- (google_search , ["query" , "google_api_key" , "google_cse_id" , "k" , "siterestrict" ], "Google Search." ),
167- (google_serper , ["query" , "serper_api_key" , "k" , "gl" , "hl" ], "Google Serper." ),
168- (golden_query , ["query" , "golden_api_key" ], "Golden Query." ),
169- (pub_med , ["query" ], "PubMed." ),
170- (mojeek_query , ["query" , "api_key" ], "Mojeek Search." ),
171- (reddit_search , ["query" , "sort" , "time_filter" , "subreddit" , "limit" , "client_id" , "client_secret" , "user_agent" ],
172- "Reddit Search." ),
173- (searxng_search , ["query" , "searx_host" ], "SearxNG Search." ),
174- (serp_api , ["query" , "serpapi_api_key" ], "SerpAPI." ),
175- (twilio , ["body" , "to" , "account_sid" , "auth_token" , "from_number" ], "Twilio." ),
176- (wikidata , ["query" ], "Wikidata." ),
177- (wikipedia , ["query" ], "Wikipedia." ),
178- (wolfram_alpha , ["query" , "wolfram_alpha_appid" ], "Wolfram Alpha." ),
179- (youtube_search , ["query" ], "Youtube Search." ),
180- ]
181-
182- for tool in network_toolkit :
183- register_callable_tool (tool , langchain_network .__module__ , "langchain.tool" )
0 commit comments