From 7ad0cca3ba758ce7039763a11be77b2d3fd92e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=8D=9A=E5=8D=88?= Date: Tue, 29 Jul 2025 16:07:34 +0800 Subject: [PATCH 1/2] Update metadata registration using @fitable --- .../callable_registers.py | 29 - .../langchain_network_tool.py | 124 +- .../fel_langchain_network_tools/tools.json | 1485 +++++++++++++++++ 3 files changed, 1533 insertions(+), 105 deletions(-) delete mode 100644 framework/fel/python/plugins/fel_langchain_network_tools/callable_registers.py create mode 100644 framework/fel/python/plugins/fel_langchain_network_tools/tools.json diff --git a/framework/fel/python/plugins/fel_langchain_network_tools/callable_registers.py b/framework/fel/python/plugins/fel_langchain_network_tools/callable_registers.py deleted file mode 100644 index 0cde3122..00000000 --- a/framework/fel/python/plugins/fel_langchain_network_tools/callable_registers.py +++ /dev/null @@ -1,29 +0,0 @@ -# -- encoding: utf-8 -- -# Copyright (c) 2024 Huawei Technologies Co., Ltd. All Rights Reserved. -# This file is a part of the ModelEngine Project. -# Licensed under the MIT License. See License.txt in the project root for license information. -# ====================================================================================================================== -import functools -from inspect import signature -from typing import Callable, Any, Tuple, List - -from fitframework import fit_logger -from fitframework.core.repo.fitable_register import register_fitable - - -def __invoke_tool(input_args: dict, tool_func: Callable[..., Any], **kwargs) -> Any: - return tool_func(**input_args, **kwargs) - - -def register_callable_tool(tool: Tuple[Callable[..., Any], List[str], str], module: str, generic_id: str): - func = tool[0] - fitable_id = f"{func.__name__}" - - tool_invoke = functools.partial(__invoke_tool, tool_func=func) - tool_invoke.__module__ = module - tool_invoke.__annotations__ = { - 'input_args': dict, - 'return': signature(func).return_annotation - } - register_fitable(generic_id, fitable_id, False, [], tool_invoke) - fit_logger.info("register: generic_id = %s, fitable_id = %s", generic_id, fitable_id, stacklevel=2) diff --git a/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py b/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py index f1867a5a..ef33200c 100644 --- a/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py +++ b/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py @@ -21,109 +21,111 @@ from langchain_community.utilities.wikidata import WikidataAPIWrapper from langchain_core.documents import Document -from .callable_registers import register_callable_tool +from fitframework.api.decorators import fitable - -def langchain_network(**kwargs) -> str: +def langchain_network() -> str: time.sleep(5) return "" - -def arxiv(arxiv_id: str, **kwargs) -> List[str]: +@fitable("langchain.tool.arxiv", "default") +def arxiv(arxiv_id: str) -> List[str]: retriever = ArxivRetriever(load_max_docs=2) docs: List[Document] = retriever.get_relevant_documents(query=arxiv_id) return [doc.page_content for doc in docs] - -def bing_search(query: str, bing_subscription_key: str, bing_search_url: str, **kwargs) -> str: +@fitable("langchain.tool.bing_search", "default") +def bing_search(query: str, bing_subscription_key: str, bing_search_url: str) -> str: os.environ["BING_SUBSCRIPTION_KEY"] = bing_subscription_key os.environ["BING_SEARCH_URL"] = bing_search_url search = BingSearchAPIWrapper() return search.run(query) - -def brave_search(query: str, count: int, api_key: str, **kwargs) -> str: +@fitable("langchain.tool.brave_search", "default") +def brave_search(query: str, count: int, api_key: str) -> str: brave_search_ = BraveSearch.from_api_key(api_key=api_key, search_kwargs={"count": count}) return brave_search_.run(query) - -def duck_duck_go_search(query: str, **kwargs) -> str: +@fitable("langchain.tool.duck_duck_go_search", "default") +def duck_duck_go_search(query: str) -> str: search = DuckDuckGoSearchRun() return search.invoke(query) - -def google_jobs(query: str, serapi_api_key: str, **kwargs) -> str: +@fitable("langchain.tool.google_jobs", "default") +def google_jobs(query: str, serapi_api_key: str) -> str: os.environ["SERPAPI_API_KEY"] = serapi_api_key google_job_tool = GoogleJobsQueryRun(api_wrapper=GoogleJobsAPIWrapper()) return google_job_tool.run(query) - -def google_places(query: str, gplaces_api_key: str, **kwargs) -> str: +@fitable("langchain.tool.google_places", "default") +def google_places(query: str, gplaces_api_key: str) -> str: os.environ["GPLACES_API_KEY"] = gplaces_api_key places = GooglePlacesTool() return places.run(query) - -def google_scholar(query: str, serp_api_key: str, **kwargs) -> str: +@fitable("langchain.tool.google_scholar", "default") +def google_scholar(query: str, serp_api_key: str) -> str: os.environ["SERP_API_KEY"] = serp_api_key google_job_tool = GoogleScholarQueryRun(api_wrapper=GoogleScholarAPIWrapper()) return google_job_tool.run(query) - -def google_search(query: str, google_api_key: str, google_cse_id: str, k: int, siterestrict: bool, **kwargs) -> str: +@fitable("langchain.tool.google_search", "default") +def google_search(query: str, google_api_key: str, google_cse_id: str, k: int, siterestrict: bool) -> str: wrapper = GoogleSearchAPIWrapper(google_api_key=google_api_key, google_cse_id=google_cse_id, k=k, siterestrict=siterestrict) search = GoogleSearchRun(api_wrapper=wrapper) return search.run(query) - -def google_serper(query: str, k: int, gl: str, hl: str, serper_api_key: str, **kwargs) -> str: +@fitable("langchain.tool.google_serper", "default") +def google_serper(query: str, k: int, gl: str, hl: str, serper_api_key: str) -> str: os.environ["SERPER_API_KEY"] = serper_api_key search = GoogleSerperAPIWrapper(k=k, gl=gl, hl=hl) return search.run(query) - -def golden_query(query: str, golden_api_key: str, **kwargs) -> str: +@fitable("langchain.tool.golden_query", "default") +def golden_query(query: str, golden_api_key: str) -> str: os.environ["GOLDEN_API_KEY"] = golden_api_key golden_query_api = GoldenQueryAPIWrapper() return golden_query_api.run(query) - +@fitable("langchain.tool.pub_med", "default") def pub_med(query: str) -> str: pub_med_tool: PubmedQueryRun = PubmedQueryRun() return pub_med_tool.invoke(query) - +@fitable("langchain.tool.mojeek_query", "default") def mojeek_query(query: str, api_key: str) -> str: search = MojeekSearch.config(api_key=api_key) return search.run(query) - +@fitable("langchain.tool.reddit_search", "default") def reddit_search(query: str, sort: str, time_filter: str, subreddit: str, limit: str, client_id: str, client_secret: str, user_agent: str) -> str: - search = RedditSearchRun( - api_wrapper=RedditSearchAPIWrapper( - reddit_client_id=client_id, - reddit_client_secret=client_secret, - reddit_user_agent=user_agent, + try: + search = RedditSearchRun( + api_wrapper=RedditSearchAPIWrapper( + reddit_client_id=client_id, + reddit_client_secret=client_secret, + reddit_user_agent=user_agent, + ) ) - ) - search_params = RedditSearchSchema(query=query, sort=sort, time_filter=time_filter, subreddit=subreddit, - limit=limit) - result = search.run(tool_input=search_params.dict()) - return result - - + search_params = RedditSearchSchema(query=query, sort=sort, time_filter=time_filter, subreddit=subreddit, + limit=limit) + result = search.run(tool_input=search_params.dict()) + return result + except Exception as e: + return f"Error: {str(e)}" + +@fitable("langchain.tool.searxng_search", "default") def searxng_search(query: str, searx_host: str) -> str: search = SearxSearchWrapper(searx_host=searx_host) return search.run(query) - +@fitable("langchain.tool.serp_api", "default") def serp_api(query: str, serpapi_api_key: str) -> str: search = SerpAPIWrapper(serpapi_api_key=serpapi_api_key) return search.run(query) - +@fitable("langchain.tool.twilio", "default") def twilio(body: str, to: str, account_sid: str, auth_token: str, from_number: str) -> str: twilio_api = TwilioAPIWrapper( account_sid=account_sid, @@ -132,52 +134,22 @@ def twilio(body: str, to: str, account_sid: str, auth_token: str, from_number: s ) return twilio_api.run(body, to) - +@fitable("langchain.tool.wikidata", "default") def wikidata(query: str) -> str: wikidata_query = WikidataQueryRun(api_wrapper=WikidataAPIWrapper()) return wikidata_query.run(query) - -def wikipedia(query: str, **kwargs) -> str: +@fitable("langchain.tool.wikipedia", "default") +def wikipedia(query: str) -> str: wikipedia_query_run = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper()) return wikipedia_query_run.run(query) - +@fitable("langchain.tool.wolfram_alpha", "default") def wolfram_alpha(query: str, wolfram_alpha_appid: str) -> str: wolfram = WolframAlphaAPIWrapper(wolfram_alpha_appid=wolfram_alpha_appid) return wolfram.run(query) - -def youtube_search(query: str, **kwargs) -> str: +@fitable("langchain.tool.youtube_search", "default") +def youtube_search(query: str) -> str: youtube_search_tool = YouTubeSearchTool() return youtube_search_tool.run(query) - - -# Tuple 结构: (tool_func, config_args, return_description) -network_toolkit: List[Tuple[Callable[..., Any], List[str], str]] = [ - (langchain_network, ["input"], "Youtube search."), - (arxiv, ["arxiv_id"], "ArXiv search."), - (bing_search, ["query", "bing_subscription_key", "bing_search_url"], "Bing search."), - (brave_search, ["query", "count", "api_key"], "Brave search."), - (duck_duck_go_search, ["query"], "DuckDuckGo Search."), - (google_jobs, ["query", "serapi_api_key"], "Google Jobs."), - (google_places, ["query", "gplaces_api_key"], "Google Places."), - (google_scholar, ["query", "serp_api_key"], "Google Scholar."), - (google_search, ["query", "google_api_key", "google_cse_id", "k", "siterestrict"], "Google Search."), - (google_serper, ["query", "serper_api_key", "k", "gl", "hl"], "Google Serper."), - (golden_query, ["query", "golden_api_key"], "Golden Query."), - (pub_med, ["query"], "PubMed."), - (mojeek_query, ["query", "api_key"], "Mojeek Search."), - (reddit_search, ["query", "sort", "time_filter", "subreddit", "limit", "client_id", "client_secret", "user_agent"], - "Reddit Search."), - (searxng_search, ["query", "searx_host"], "SearxNG Search."), - (serp_api, ["query", "serpapi_api_key"], "SerpAPI."), - (twilio, ["body", "to", "account_sid", "auth_token", "from_number"], "Twilio."), - (wikidata, ["query"], "Wikidata."), - (wikipedia, ["query"], "Wikipedia."), - (wolfram_alpha, ["query", "wolfram_alpha_appid"], "Wolfram Alpha."), - (youtube_search, ["query"], "Youtube Search."), -] - -for tool in network_toolkit: - register_callable_tool(tool, langchain_network.__module__, "langchain.tool") diff --git a/framework/fel/python/plugins/fel_langchain_network_tools/tools.json b/framework/fel/python/plugins/fel_langchain_network_tools/tools.json new file mode 100644 index 00000000..d0110a71 --- /dev/null +++ b/framework/fel/python/plugins/fel_langchain_network_tools/tools.json @@ -0,0 +1,1485 @@ +{ + "version" : "1.0.0", + "definitionGroups" : [ { + "name" : "langchain_network_tools", + "summary" : "", + "description" : "", + "extensions" : { }, + "definitions" : [ { + "schema" : { + "name" : "RedditSearchTool", + "description" : "用于在指定子版块中搜索帖子。需先配置 Reddit API 的 ID、密钥和 User-Agent,输入关键词、时间范围与排序规则,即可检索匹配的帖子并返回结果。", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "sort" : { + "defaultValue" : "", + "description" : "检索排序顺序,如时间热度", + "name" : "sort", + "type" : "string", + "example" : "" + }, + "time_filter" : { + "defaultValue" : "", + "description" : "检索内容时间范围,日/月/年", + "name" : "time_filter", + "type" : "string", + "example" : "" + }, + "subreddit" : { + "defaultValue" : "", + "description" : "检索的Reddit的子版块名称", + "name" : "subreddit", + "type" : "string", + "example" : "" + }, + "limit" : { + "defaultValue" : "", + "description" : "限制返回搜索结果的条数", + "name" : "limit", + "type" : "string", + "example" : "" + }, + "client_id" : { + "defaultValue" : "", + "description" : "Reddit API分配的客户端ID", + "name" : "client_id", + "type" : "string", + "example" : "" + }, + "client_secret" : { + "defaultValue" : "", + "description" : "Reddit分配的客户端密钥", + "name" : "client_secret", + "type" : "string", + "example" : "" + }, + "user_agent" : { + "defaultValue" : "", + "description" : "标识调用方的 User-Agent", + "name" : "user_agent", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "sort", "time_filter", "subreddit", "limit", "client_id", "client_secret", "user_agent" ] + }, + "order" : [ "query", "sort", "time_filter", "subreddit", "limit", "client_id", "client_secret", "user_agent" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "ArXivTool", + "description" : "用于从ArXiv拉取检索的论文。使用时需输入论文唯一id或者关键字,函数会在arXiv中进行检索,最终会返回相关内容的两篇文献的正文片段", + "parameters" : { + "type" : "object", + "properties" : { + "arxiv_id" : { + "defaultValue" : "", + "description" : "检索关键词或者论文唯一id", + "name" : "arxiv_id", + "type" : "string", + "example" : "" + } + }, + "required" : [ "arxiv_id" ] + }, + "order" : [ "arxiv_id" ], + "return" : { + "type" : "array", + "items" : { + "type" : "string" + }, + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "BingSearchTool", + "description" : "用于检索Bing搜索引擎中的内容。使用时输入检索关键词以及Azure官网配置的key和url,返回结果汇总摘要文本", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "bing_subscription_key" : { + "defaultValue" : "", + "description" : "在Azure获取的Key", + "name" : "bing_subscription_key", + "type" : "string", + "example" : "" + }, + "bing_search_url" : { + "defaultValue" : "", + "description" : "在Azure获取的Endpoint", + "name" : "bing_search_url", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "bing_subscription_key", "bing_search_url" ] + }, + "order" : [ "query", "bing_subscription_key", "bing_search_url" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "BraveSearchTool", + "description" : "通过API进行检索。使用时传入检索关键词、检索结果的数量以及注册的API,返回由多条搜索结果组成的纯文本", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "count" : { + "defaultValue" : "", + "description" : "检索结果的数量", + "name" : "count", + "type" : "integer", + "example" : "" + }, + "api_key" : { + "defaultValue" : "", + "description" : "从Brave开发者中心注册的API", + "name" : "api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "count", "api_key" ] + }, + "order" : [ "query", "count", "api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "DuckDuckGoSearchTool", + "description" : "DuckDuckGo搜索引擎执行关键词搜索,返回即可搜索结果文本。", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query" ] + }, + "order" : [ "query" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "GoogleJobsTool", + "description" : "通过注册获取的API在Google Jobs进行搜索使用时要传入职位关键词以及API,函数执行检索后返回职位信息", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "serapi_api_key" : { + "defaultValue" : "", + "description" : "由SeraAPI提供的Google Job API ", + "name" : "serapi_api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "serapi_api_key" ] + }, + "order" : [ "query", "serapi_api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "GooglePlaceTool", + "description" : "用于Google的地址查询服务,使用时传入地址关键词,以及注册调用的API,通过检索函数返回地点检索结果。", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "gplace_api_key" : { + "defaultValue" : "", + "description" : "获取的API", + "name" : "gplace_api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "gplace_api_key" ] + }, + "order" : [ "query", "gplace_api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "GoogleScholarTool", + "description" : "用于查询学术论文,辅助综述写作等。使用时输入检索的学术论文标题或内容关键词,输出相关的纯文本式的文献信息", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "serp_api_key" : { + "defaultValue" : "", + "description" : "获取的API", + "name" : "serp_api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "serp_api_key" ] + }, + "order" : [ "query", "serp_api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "GoogleSearchTool", + "description" : "以google自定义API执行关键词搜索,cse,k,以及siterestrict四个参数设定API,最后输入关键词返回相关的标题以及Google链接等", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "google_api_key" : { + "defaultValue" : "", + "description" : "指定调用到的检索服务API接口", + "name" : "google_api_key", + "type" : "string", + "example" : "" + }, + "google_cse_id" : { + "defaultValue" : "", + "description" : "通过CSE定制的搜索范围", + "name" : "google_cse_id", + "type" : "string", + "example" : "" + }, + "k" : { + "defaultValue" : "", + "description" : "限制检索结果的最大数量", + "name" : "k", + "type" : "integer", + "example" : "" + }, + "siterestrict" : { + "defaultValue" : "", + "description" : "是否启用cse规定的域名限制", + "name" : "siterestrict", + "type" : "boolean", + "example" : "" + } + }, + "required" : [ "query", "google_api_key", "google_cse_id", "k", "siterestrict" ] + }, + "order" : [ "query", "google_api_key", "google_cse_id", "k", "siterestrict" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "GoogleSerperTool", + "description" : "用于通过Serper代理访问全局的Google搜索。使用时需要输入检索关键字以及检索信息条数,代理服务的地区、语言,通过Serper代理方申请的API,输出搜索到的标题网址等。", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "k" : { + "defaultValue" : "", + "description" : "检索结果的数量", + "name" : "k", + "type" : "integer", + "example" : "" + }, + "gl" : { + "defaultValue" : "", + "description" : "搜索地址", + "name" : "gl", + "type" : "string", + "example" : "" + }, + "hl" : { + "defaultValue" : "", + "description" : "检索语言", + "name" : "hl", + "type" : "string", + "example" : "" + }, + "serper_api_key" : { + "defaultValue" : "", + "description" : "官网申请的API", + "name" : "serper_api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "k", "gl", "hl", "serper_api_key" ] + }, + "order" : [ "query", "k", "gl", "hl", "serper_api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "GoldenQueryTool", + "description" : "通过调用Golden平台的语义搜索API进行搜索。使用时用户需要输入检索的关键字以及在官网申请的API,返回有关回答", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "golden_api_key" : { + "defaultValue" : "", + "description" : "用于指定调用的搜索服务API", + "name" : "golden_api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "golden_api_key" ] + }, + "order" : [ "query", "golden_api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "PubmedTool", + "description" : "用于医疗信息领域的检索。使用时输入关键字,输出检索得到的结构化的文献信息", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query" ] + }, + "order" : [ "query" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "MojeekTool", + "description" : "通过调用Mojeek搜索引擎API,配合关键词进行检索,使用时要从Mojeek官网获取私人地API key并同关键词一起作为参数传入该函数,最后得到搜索内容的原始输出", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "api_key" : { + "defaultValue" : "", + "description" : "指定调用的搜索服务API", + "name" : "api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "api_key" ] + }, + "order" : [ "query", "api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "SearxNGTool", + "description" : "通过自建搜索聚合器,在各大网站进行搜索后拉取到自建网站。使用时给出自建网站的位置,以及检索关键字,返回检索结果", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "searx_host" : { + "defaultValue" : "", + "description" : "自建IP/域名/端口", + "name" : "searx_host", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "searx_host" ] + }, + "order" : [ "query", "searx_host" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "SerpAPITool", + "description" : "通过第三方引擎到各个搜索引擎去获取检索信息,使用时输入检索关键字以及官网注册得到的API通过商业代理检索,最后输出检索信息", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "serpapi_api_key" : { + "defaultValue" : "", + "description" : "官网申请得到的API", + "name" : "serpapi_api_key", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "serpapi_api_key" ] + }, + "order" : [ "query", "serpapi_api_key" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "TwilioTool", + "description" : "发送短信,通过输入的参数信息调用Twilio去发送信息到指定号码,返回已发送信息的sid证明信息已经发送", + "parameters" : { + "type" : "object", + "properties" : { + "body" : { + "defaultValue" : "", + "description" : "发送的消息文本", + "name" : "body", + "type" : "string", + "example" : "" + }, + "to" : { + "defaultValue" : "", + "description" : "对方的电话号码", + "name" : "to", + "type" : "string", + "example" : "" + }, + "account_sid" : { + "defaultValue" : "", + "description" : "用户的官网SID", + "name" : "account_sid", + "type" : "string", + "example" : "" + }, + "auth_token" : { + "defaultValue" : "", + "description" : "账户对应的API访问密钥", + "name" : "auth_token", + "type" : "string", + "example" : "" + }, + "from_number" : { + "defaultValue" : "", + "description" : "用户的电话号码", + "name" : "from_number", + "type" : "string", + "example" : "" + } + }, + "required" : [ "body", "to", "account_sid", "auth_token", "from_number" ] + }, + "order" : [ "body", "to", "account_sid", "auth_token", "from_number" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "WikidataTool", + "description" : "基于维基百科进行检索服务,主要用于查询事实内容,使用时输入检索关键词,输出一个或者多个事实条例。", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query" ] + }, + "order" : [ "query" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "WikipediaTool", + "description" : "基于维基百科进行检索服务,使用时传入要搜索的关键词即可查询相关的背景内容", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query" ] + }, + "order" : [ "query" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "WolframAlphaTool", + "description" : "用于复杂计算,金融统计等计算型任务。使用时输入查询内容,转化为数学推理等形式,输出含有计算过程等的数据计算。", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + }, + "wolfram_alpha_appid" : { + "defaultValue" : "", + "description" : "官网申请注册的appid", + "name" : "wolfram_alpha_appid", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query", "wolfram_alpha_appid" ] + }, + "order" : [ "query", "wolfram_alpha_appid" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + }, { + "schema" : { + "name" : "YouTubeSearchTool", + "description" : "用于检索Youtube中的视频链接等,使用时输入关键字,返回相关视频的链接", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "defaultValue" : "", + "description" : "检索关键词", + "name" : "query", + "type" : "string", + "example" : "" + } + }, + "required" : [ "query" ] + }, + "order" : [ "query" ], + "return" : { + "type" : "string", + "convertor" : "" + } + } + } ] + } ], + "toolGroups" : [ { + "name" : "langchain_network_tools_impl", + "summary" : "", + "description" : "", + "extensions" : { }, + "definitionGroupName" : "langchain_network_tools", + "tools" : [ { + "namespace" : "reddit_search", + "schema" : { + "name" : "RedditSearchTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "sort" : { + "name" : "sort", + "type" : "string" + }, + "time_filter" : { + "name" : "time_filter", + "type" : "string" + }, + "subreddit" : { + "name" : "subreddit", + "type" : "string" + }, + "limit" : { + "name" : "limit", + "type" : "string" + }, + "client_id" : { + "name" : "client_id", + "type" : "string" + }, + "client_secret" : { + "name" : "client_secret", + "type" : "string" + }, + "user_agent" : { + "name" : "user_agent", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "sort", "time_filter", "subreddit", "limit", "client_id", "client_secret", "user_agent" ], + "return" : { + "name" : "", + "description" : "返回匹配 Reddit 帖子的摘要信息,包含帖子的标题、链接等内容。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.reddit_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "RedditSearchTool" + }, { + "namespace" : "arxiv", + "schema" : { + "name" : "ArXivTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "arxiv_id" : { + "name" : "arxiv_id", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "arxiv_id" ], + "return" : { + "name" : "", + "description" : "返回与输入关键词或 ID 匹配的两篇 Arxiv 论文正文片段。", + "type" : "array", + "items" : { + "type" : "string" + }, + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.arxiv", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "ArXivTool" + }, { + "namespace" : "bing_search", + "schema" : { + "name" : "BingSearchTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "bing_subscription_key" : { + "name" : "bing_subscription_key", + "type" : "string" + }, + "bing_search_url" : { + "name" : "bing_search_url", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "bing_subscription_key", "bing_search_url" ], + "return" : { + "name" : "", + "description" : "返回 Bing 搜索结果的摘要文本,聚合主要内容。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.bing_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "BingSearchTool" + }, { + "namespace" : "brave_search", + "schema" : { + "name" : "BraveSearchTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "count" : { + "name" : "count", + "type" : "integer" + }, + "api_key" : { + "name" : "api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "count", "api_key" ], + "return" : { + "name" : "", + "description" : "返回多条 Brave 搜索结果拼接后的纯文本内容。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.brave_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "BraveSearchTool" + }, { + "namespace" : "duck_duck_go_search", + "schema" : { + "name" : "DuckDuckGoSearchTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query" ], + "return" : { + "name" : "", + "description" : "返回 DuckDuckGo 搜索结果摘要文本。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.duck_duck_go_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "DuckDuckGoSearchTool" + }, { + "namespace" : "google_jobs", + "schema" : { + "name" : "GoogleJobsTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "serapi_api_key" : { + "name" : "serapi_api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "serapi_api_key" ], + "return" : { + "name" : "", + "description" : "返回匹配的职位招聘信息,如职位标题、公司名、地址等。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.google_jobs", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "GoogleJobsTool" + }, { + "namespace" : "google_places", + "schema" : { + "name" : "GooglePlaceTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "gplace_api_key" : { + "name" : "gplace_api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "gplace_api_key" ], + "return" : { + "name" : "", + "description" : "返回与地址关键词相关的 Google 地点搜索结果。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.google_places", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "GooglePlaceTool" + }, { + "namespace" : "google_scholar", + "schema" : { + "name" : "GoogleScholarTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "serp_api_key" : { + "name" : "serp_api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "serp_api_key" ], + "return" : { + "name" : "", + "description" : "返回与关键词相关的 Google Scholar 学术论文引用信息。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.google_scholar", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "GoogleScholarTool" + }, { + "namespace" : "google_search", + "schema" : { + "name" : "GoogleSearchTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "google_api_key" : { + "name" : "google_api_key", + "type" : "string" + }, + "google_cse_id" : { + "name" : "google_cse_id", + "type" : "string" + }, + "k" : { + "name" : "k", + "type" : "integer" + }, + "siterestrict" : { + "name" : "siterestrict", + "type" : "boolean" + } + }, + "required" : [ ] + }, + "order" : [ "query", "google_api_key", "google_cse_id", "k", "siterestrict" ], + "return" : { + "name" : "", + "description" : "返回关键词对应的 Google 搜索标题与链接结果。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.google_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "GoogleSearchTool" + }, { + "namespace" : "google_serper", + "schema" : { + "name" : "GoogleSerperTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "k" : { + "name" : "k", + "type" : "integer" + }, + "gl" : { + "name" : "gl", + "type" : "string" + }, + "hl" : { + "name" : "hl", + "type" : "string" + }, + "serper_api_key" : { + "name" : "serper_api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "k", "gl", "hl", "serper_api_key" ], + "return" : { + "name" : "", + "description" : "返回由 Serper 提供的 Google 搜索结果摘要,包括标题和网址。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.google_serper", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "GoogleSerperTool" + }, { + "namespace" : "golden_query", + "schema" : { + "name" : "GoldenQueryTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "golden_api_key" : { + "name" : "golden_api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "golden_api_key" ], + "return" : { + "name" : "", + "description" : "返回由 Golden API 查询得到的结构化实体信息或回答内容。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.golden_query", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "GoldenQueryTool" + }, { + "namespace" : "pub_med", + "schema" : { + "name" : "PubmedTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query" ], + "return" : { + "name" : "", + "description" : "返回与医学关键词相关的 PubMed 文献结构化摘要。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.pub_med", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "PubmedTool" + }, { + "namespace" : "mojeek_query", + "schema" : { + "name" : "MojeekTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "api_key" : { + "name" : "api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "api_key" ], + "return" : { + "name" : "", + "description" : "返回 Mojeek 搜索结果的原始输出文本。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.mojeek_query", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "MojeekTool" + }, { + "namespace" : "searxng_search", + "schema" : { + "name" : "SearxNGTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "searx_host" : { + "name" : "searx_host", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "searx_host" ], + "return" : { + "name" : "", + "description" : "返回 SearxNG 聚合搜索引擎拉取的多站点搜索摘要。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.searxng_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "SearxNGTool" + }, { + "namespace" : "serp_api", + "schema" : { + "name" : "SerpAPITool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "serpapi_api_key" : { + "name" : "serpapi_api_key", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "serpapi_api_key" ], + "return" : { + "name" : "", + "description" : "返回由 SerpAPI 聚合的多平台搜索结果信息。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.serp_api", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "SerpAPITool" + }, { + "namespace" : "twilio", + "schema" : { + "name" : "TwilioTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "body" : { + "name" : "body", + "type" : "string" + }, + "to" : { + "name" : "to", + "type" : "string" + }, + "account_sid" : { + "name" : "account_sid", + "type" : "string" + }, + "auth_token" : { + "name" : "auth_token", + "type" : "string" + }, + "from_number" : { + "name" : "from_number", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "body", "to", "account_sid", "auth_token", "from_number" ], + "return" : { + "name" : "", + "description" : "返回已发送短信的消息 SID,用于确认 Twilio 成功发送信息。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.twilio", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "TwilioTool" + }, { + "namespace" : "wikidata", + "schema" : { + "name" : "WikidataTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query" ], + "return" : { + "name" : "", + "description" : "返回维基数据中与关键词相关的事实内容条目。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.wikidata", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "WikidataTool" + }, { + "namespace" : "wikipedia", + "schema" : { + "name" : "WikipediaTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query" ], + "return" : { + "name" : "", + "description" : "返回与关键词相关的维基百科条目的背景信息摘要。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.wikipedia", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "WikipediaTool" + }, { + "namespace" : "wolfram_alpha", + "schema" : { + "name" : "WolframAlphaTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + }, + "wolfram_alpha_appid" : { + "name" : "wolfram_alpha_appid", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query", "wolfram_alpha_appid" ], + "return" : { + "name" : "", + "description" : "返回 Wolfram Alpha 对计算性问题的解析与结果,包括数学推导与数据分析。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.wolfram_alpha", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "WolframAlphaTool" + }, { + "namespace" : "youtube_search", + "schema" : { + "name" : "YouTubeSearchTool", + "description" : "", + "parameters" : { + "type" : "object", + "properties" : { + "query" : { + "name" : "query", + "type" : "string" + } + }, + "required" : [ ] + }, + "order" : [ "query" ], + "return" : { + "name" : "", + "description" : "返回与关键词相关的 YouTube 视频链接与标题信息。", + "type" : "string", + "convertor" : "" + } + }, + "runnables" : { + "FIT" : { + "genericableId" : "langchain.tool.youtube_search", + "fitableId" : "default" + } + }, + "extensions" : { + "tags" : [ "Langchain" ] + }, + "definitionName" : "YouTubeSearchTool" + } ] + } ] +} \ No newline at end of file From bfeb63a9335cdba5d1406d54d979d574df822084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=8D=9A=E5=8D=88?= Date: Mon, 11 Aug 2025 11:42:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langchain_network_tool.py | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py b/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py index ef33200c..cdc054b8 100644 --- a/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py +++ b/framework/fel/python/plugins/fel_langchain_network_tools/langchain_network_tool.py @@ -100,20 +100,17 @@ def mojeek_query(query: str, api_key: str) -> str: @fitable("langchain.tool.reddit_search", "default") def reddit_search(query: str, sort: str, time_filter: str, subreddit: str, limit: str, client_id: str, client_secret: str, user_agent: str) -> str: - try: - search = RedditSearchRun( - api_wrapper=RedditSearchAPIWrapper( - reddit_client_id=client_id, - reddit_client_secret=client_secret, - reddit_user_agent=user_agent, - ) + search = RedditSearchRun( + api_wrapper=RedditSearchAPIWrapper( + reddit_client_id=client_id, + reddit_client_secret=client_secret, + reddit_user_agent=user_agent, ) - search_params = RedditSearchSchema(query=query, sort=sort, time_filter=time_filter, subreddit=subreddit, - limit=limit) - result = search.run(tool_input=search_params.dict()) - return result - except Exception as e: - return f"Error: {str(e)}" + ) + search_params = RedditSearchSchema(query=query, sort=sort, time_filter=time_filter, subreddit=subreddit, + limit=limit) + result = search.run(tool_input=search_params.dict()) + return result @fitable("langchain.tool.searxng_search", "default") def searxng_search(query: str, searx_host: str) -> str: