请问我自定义的本地工具报这个错误咋回事 for field_name, field_info in cls.model_fields.items(): AttributeError: type object 'BihaiAddTimeIn' has no attribute 'model_fields'
yst-one opened this issue · 5 comments
以这个演示demo参考为例,需要稍微改改,避免无法运行。,https://ernie-bot-agent.readthedocs.io/zh-cn/latest/cookbooks/agent/local_tool/#12
添加环境环境变量
from future import annotations
import os
from erniebot_agent.memory import WholeMemory
from erniebot_agent.chat_models import ERNIEBot
from erniebot_agent.agents.function_agent import FunctionAgent
from erniebot_agent.tools.schema import ToolParameterView
from erniebot_agent.tools.base import Tool
from pydantic import Field
from typing import Any, Dict, Type, List
import asyncio
os.environ["EB_AGENT_ACCESS_TOKEN"] = ""
class AddWordInput(ToolParameterView):
word: str = Field(description="待添加的单词")
class AddWordOutput(ToolParameterView):
result: str = Field(description="表示是否成功将单词成功添加到词库当中")
class AddWordTool(Tool):
description: str = "添加单词到词库当中"
input_type: Type[ToolParameterView] = AddWordInput
ouptut_type: Type[ToolParameterView] = AddWordOutput
def __init__(self) -> None:
self.word_books = {}
super().__init__()
async def __call__(self, word: str) -> Dict[str, Any]:
if word in self.word_books:
return {"result": f"<{word}>单词已经存在,无需添加"}
self.word_books[word] = True
words = "\n".join(list(self.word_books.keys()))
return {"result": f"<{word}>单词已添加成功, 当前单词本中有如下单词:{words}"}
async def main():
agent = FunctionAgent(ERNIEBot("ernie-3.5"),
tools=[AddWordTool()], memory=WholeMemory())
result = await agent.run("将单词:“red”添加到词库当中")
print(result)
asyncio.run(main())
倒未发现报错~
这个可能要辛苦 @wj-Mcat 看看