Giter VIP home page Giter VIP logo

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

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

from ernie-sdk.

Comments (5)

yst-one avatar yst-one commented on May 22, 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

from ernie-sdk.

itagan avatar itagan commented on May 22, 2024

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

from ernie-sdk.

itagan avatar itagan commented on May 22, 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())

from ernie-sdk.

itagan avatar itagan commented on May 22, 2024

倒未发现报错~

from ernie-sdk.

Bobholamovic avatar Bobholamovic commented on May 22, 2024

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

from ernie-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.