增加一些Langchain的Agent工具 (#1836)

* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

* 修改了部分Agent的工具

* 增加一些Langchain的自带工具

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
This commit is contained in:
zR 2023-10-23 13:22:10 +08:00 committed by GitHub
parent 303c9d94df
commit c983e9f559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 4 deletions

View File

@ -99,6 +99,8 @@ EMBEDDING_DEVICE = "auto"
# LLM 名称 # LLM 名称
LLM_MODEL = "chatglm2-6b" LLM_MODEL = "chatglm2-6b"
# AgentLM模型的名称 (可以不指定指定之后就锁定进入Agent之后的Chain的模型不指定就是LLM_MODEL)
Agent_MODEL = None
# LLM 运行设备。设为"auto"会自动检测,也可手动设定为"cuda","mps","cpu"其中之一。 # LLM 运行设备。设为"auto"会自动检测,也可手动设定为"cuda","mps","cpu"其中之一。
LLM_DEVICE = "auto" LLM_DEVICE = "auto"

View File

@ -7,4 +7,5 @@ from .translator import translate
from .weather import weathercheck from .weather import weathercheck
from .shell import shell from .shell import shell
from .search_internet import search_internet from .search_internet import search_internet
from .wolfram import wolfram
from .youtube import youtube_search

View File

@ -1,3 +1,4 @@
# LangChain 的 Shell 工具
from langchain.tools import ShellTool from langchain.tools import ShellTool
def shell(query: str): def shell(query: str):
tool = ShellTool() tool = ShellTool()

View File

@ -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

View File

@ -0,0 +1,5 @@
# Langchain 自带的 YouTube 搜索工具封装
from langchain.tools import YouTubeSearchTool
def youtube_search(query: str):
tool = YouTubeSearchTool()
return tool.run(tool_input=query)

View File

@ -5,7 +5,7 @@ from server.agent.tools import *
# Tool.from_function( # Tool.from_function(
# func=calculate, # func=calculate,
# name="计算器工具", # name="计算器工具",
# description="进行简单的数学运算" # description="进行简单的数学运算, 只是简单的, 使用Wolfram数学工具进行更复杂的运算",
# ), # ),
# Tool.from_function( # Tool.from_function(
# func=translate, # func=translate,
@ -32,14 +32,23 @@ from server.agent.tools import *
# name="互联网查询工具", # name="互联网查询工具",
# description="如果你无法访问互联网这个工具可以帮助你访问Bing互联网来解答问题", # description="如果你无法访问互联网这个工具可以帮助你访问Bing互联网来解答问题",
# ), # ),
# Tool.from_function(
# func=wolfram,
# name="Wolfram数学工具",
# description="高级的数学运算工具,能够完成非常复杂的数学问题"
# ),
# Tool.from_function(
# func=youtube_search,
# name="Youtube搜索工具",
# description="使用这个工具在Youtube上搜索视频"
# ] # ]
## 请注意如果你是为了使用AgentLM在这里你应该使用英文版本下面的内容是英文版本。 ## 请注意如果你是为了使用AgentLM在这里你应该使用英文版本下面的内容是英文版本。
tools = [ tools = [
Tool.from_function( Tool.from_function(
func=calculate, func=calculate,
name="Calculator Tool", name="Simple Calculator Tool",
description="Perform simple mathematical operations" description="Perform simple mathematical operations, Just simple, Use Wolfram Math Tool for more complex operations"
), ),
Tool.from_function( Tool.from_function(
func=translate, func=translate,
@ -66,6 +75,16 @@ tools = [
name="Internet Tool", name="Internet Tool",
description="If you can't access the internet, this tool can help you access Bing to answer questions" 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] tool_names = [tool.name for tool in tools]