Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问我自定义的本地工具报这个错误咋回事 for field_name, field_info in cls.model_fields.items(): AttributeError: type object 'BihaiAddTimeIn' has no attribute 'model_fields' #318

Open
yst-one opened this issue Feb 21, 2024 · 5 comments
Assignees

Comments

@yst-one
Copy link

yst-one commented Feb 21, 2024

No description provided.

@yst-one
Copy link
Author

yst-one commented Feb 21, 2024

File "C:\Users\Administrator\one-bot.venv\lib\site-packages\erniebot_agent\tools\schema.py", line 313, in to_openapi_dict
for field_name, field_info in cls.model_fields.items():
AttributeError: type object 'BihaiAddTimeIn' has no attribute 'model_fields'
image

@itagan
Copy link

itagan commented Feb 29, 2024

以这个演示demo参考为例,需要稍微改改,避免无法运行。,https://ernie-bot-agent.readthedocs.io/zh-cn/latest/cookbooks/agent/local_tool/#12

@itagan
Copy link

itagan commented Feb 29, 2024

添加环境环境变量

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())

@itagan
Copy link

itagan commented Feb 29, 2024

倒未发现报错~

@sijunhe sijunhe assigned Bobholamovic and unassigned sijunhe Mar 4, 2024
@Bobholamovic
Copy link
Member

这个可能要辛苦 @wj-Mcat 看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants