问题描述
Gemini api使用agent代理调用进行维基百科搜索时遇到报错:TypeError: WikipediaQueryRun._run() got an unexpected keyword argument 'search'
分析
> Entering new AgentExecutor chain...
Question: what book did he write?
Thought: I should search for Tom M. Mitchell on wikipedia
Action:
{
"action": "wikipedia",
"action_input": {
"search": "Tom M. Mitchell"
}
}
WikipediaQueryRun接收string类型的"action_input"但是模型生成的 "action_input"为字典类型导致出错
解决步骤
找到anaconda3/lib/python3.1/site-packages/langchain/agents/chat/prompt.py,内容如下,在"action_input": $INPUT
后面加上///string,not dict
The $JSON_BLOB should only contain a SINGLE action,
do NOT return a list of multiple actions. Here is an example of a valid $JSON_BLOB:
{{{{
"action": $TOOL_NAME,
"action_input": $INPUT ///string,not dict
}}}}
这一段是代理发送给模型的prompt,因此为了防止模型生成错误格式的"action_input",我们在后面加上///string,not dict
就可以提醒模型生成正确格式的内容