增加一些Langchain的Agent工具 (#1836)
* 支持了agentlm * 支持了agentlm和相关提示词 * 修改了Agent的一些功能,加入了Embed方面的一个优化 * 修改了部分Agent的工具 * 增加一些Langchain的自带工具 --------- Co-authored-by: zR <zRzRzRzRzRzRzR>
This commit is contained in:
parent
303c9d94df
commit
c983e9f559
|
|
@ -99,6 +99,8 @@ EMBEDDING_DEVICE = "auto"
|
|||
|
||||
# LLM 名称
|
||||
LLM_MODEL = "chatglm2-6b"
|
||||
# AgentLM模型的名称 (可以不指定,指定之后就锁定进入Agent之后的Chain的模型,不指定就是LLM_MODEL)
|
||||
Agent_MODEL = None
|
||||
|
||||
# LLM 运行设备。设为"auto"会自动检测,也可手动设定为"cuda","mps","cpu"其中之一。
|
||||
LLM_DEVICE = "auto"
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ from .translator import translate
|
|||
from .weather import weathercheck
|
||||
from .shell import shell
|
||||
from .search_internet import search_internet
|
||||
|
||||
from .wolfram import wolfram
|
||||
from .youtube import youtube_search
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# LangChain 的 Shell 工具
|
||||
from langchain.tools import ShellTool
|
||||
def shell(query: str):
|
||||
tool = ShellTool()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
# Langchain 自带的 Wolfram Alpha API 封装
|
||||
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
|
||||
wolfram_alpha_appid = "your key"
|
||||
def wolfram(query: str):
|
||||
wolfram = WolframAlphaAPIWrapper(wolfram_alpha_appid=wolfram_alpha_appid)
|
||||
ans = wolfram.run(query)
|
||||
return ans
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# Langchain 自带的 YouTube 搜索工具封装
|
||||
from langchain.tools import YouTubeSearchTool
|
||||
def youtube_search(query: str):
|
||||
tool = YouTubeSearchTool()
|
||||
return tool.run(tool_input=query)
|
||||
|
|
@ -5,7 +5,7 @@ from server.agent.tools import *
|
|||
# Tool.from_function(
|
||||
# func=calculate,
|
||||
# name="计算器工具",
|
||||
# description="进行简单的数学运算"
|
||||
# description="进行简单的数学运算, 只是简单的, 使用Wolfram数学工具进行更复杂的运算",
|
||||
# ),
|
||||
# Tool.from_function(
|
||||
# func=translate,
|
||||
|
|
@ -32,14 +32,23 @@ from server.agent.tools import *
|
|||
# name="互联网查询工具",
|
||||
# description="如果你无法访问互联网,这个工具可以帮助你访问Bing互联网来解答问题",
|
||||
# ),
|
||||
# Tool.from_function(
|
||||
# func=wolfram,
|
||||
# name="Wolfram数学工具",
|
||||
# description="高级的数学运算工具,能够完成非常复杂的数学问题"
|
||||
# ),
|
||||
# Tool.from_function(
|
||||
# func=youtube_search,
|
||||
# name="Youtube搜索工具",
|
||||
# description="使用这个工具在Youtube上搜索视频"
|
||||
# ]
|
||||
|
||||
## 请注意,如果你是为了使用AgentLM,在这里,你应该使用英文版本,下面的内容是英文版本。
|
||||
tools = [
|
||||
Tool.from_function(
|
||||
func=calculate,
|
||||
name="Calculator Tool",
|
||||
description="Perform simple mathematical operations"
|
||||
name="Simple Calculator Tool",
|
||||
description="Perform simple mathematical operations, Just simple, Use Wolfram Math Tool for more complex operations"
|
||||
),
|
||||
Tool.from_function(
|
||||
func=translate,
|
||||
|
|
@ -66,6 +75,16 @@ tools = [
|
|||
name="Internet Tool",
|
||||
description="If you can't access the internet, this tool can help you access Bing to answer questions"
|
||||
),
|
||||
Tool.from_function(
|
||||
func=wolfram,
|
||||
name="Wolfram Math Tool",
|
||||
description="Use this tool to perform more complex mathematical operations"
|
||||
),
|
||||
Tool.from_function(
|
||||
func=youtube_search,
|
||||
name="Youtube Search Tool",
|
||||
description="Use this tool to search for videos on Youtube"
|
||||
)
|
||||
]
|
||||
|
||||
tool_names = [tool.name for tool in tools]
|
||||
Loading…
Reference in New Issue