2.9 KiB
2.9 KiB
自定义属于自己的Agent
1. 创建自己的Agent的py文件
开发者在server/agent文件中创建一个自己的文件,并将其添加到tools.py中。
例如,您创建了一个custom_agent.py文件,其中包含一个work函数,那么您需要在tools.py中添加如下代码:
from custom_agent import work
Tool.from_function(
func=work,
name="该函数的名字",
description=""
)
2. 修改 custom_template.py文件
开发者需要根据自己选择的大模型设定适合该模型的Agent Prompt和自自定义返回格式。 在我们的代码中,提供了默认的两种方式,一种是适配于GPT的提示词:
template = """Answer the following questions as best you can, You have access to the following tools:
{tools}
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
Previous conversation history:
{history}
New question: {input}
{agent_scratchpad}"""
另一种是适配于GLM-130B的提示词:
template = """
尽可能地回答以下问题。你可以使用以下工具:{tools}
请按照以下格式进行:
Question: 需要你回答的输入问题
Thought: 你应该总是思考该做什么
Action: 需要使用的工具,应该是[{tool_names}]中的一个
Action Input: 传入工具的内容
Observation: 行动的结果
... (这个Thought/Action/Action Input/Observation可以重复N次)
Thought: 我现在知道最后的答案
Final Answer: 对原始输入问题的最终答案
现在开始!
之前的对话:
{history}
New question: {input}
Thought: {agent_scratchpad}"""
3. 局限性
- 在我们的实验中,小于70B级别的模型,若不经过微调,很难达到较好的效果。因此,我们建议开发者使用大于70B级别的模型进行微调,以达到更好的效果。
- 由于Agent的脆弱性,temperture参数的设置对于模型的效果有很大的影响。我们建议开发者在使用自定义Agent时,对于不同的模型,将其设置成0.1以下,以达到更好的效果。
- 即使使用了大于70B级别的模型,开发者也应该在Prompt上进行深度优化,以让模型能成功的选择工具并完成任务。
4. 我们已经支持的Agent
我们为开发者编写了三个运用大模型执行的Agent,分别是:
- 翻译工具,实现对输入的任意语言翻译。
- 数学工具,使用LLMMathChain 实现数学计算。
- 天气工具,使用自定义的LLMWetherChain实现天气查询,调用和风天气API。