agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Bug]: Is It possible to make type hints for `response.metadata`?

Open Morriaty-The-Murderer opened this issue 1 year ago • 3 comments

Describe the bug I'm trying the werewolf demo, the type of response.metadata.xxx is not stable. For prompt "eliminate": "whether to eliminate a player or not (true/false)", it sometimes returns bool true/false, sometimes returns str "true"/"false"

To Reproduce exactly the same as agentscope/examples/game_werewolf

Expected behavior expect definition like this:

class Prompt(TypedDict):
    thougt: str = "what you thought"
    eliminate: bool = "whether to eliminate a player or not"

Error messages None

Environment (please complete the following information):

  • AgentScope Version: 0.0.4
  • Python Version: 3.10
  • OS: CentOS

Additional context None

Morriaty-The-Murderer avatar May 20 '24 02:05 Morriaty-The-Murderer

Thanks for your suggestion. That's a good idea to add type checking here within the parser, and we will add this feature into parser.

How about this solution: If the content_hint parameter in MarkdownJsonDictParser receives a TypeDict object, it will

  1. construct string content hint according to the TypeDict object as follows
You should respond a json object in a json fenced code block as follows:
```json
{
    "thought": "a string that represents what you thought",
    "eliminate":"a bool value that represents whether to eliminate a player or not"
}
```

However, I'm not sure the best way to remind LLM the type of the value that it should generate. 3. parse the LLM response
4. check if the type of the values are correct and raise a special exception to remind LLM the wrong type of values.

DavdGao avatar May 21 '24 02:05 DavdGao

@DavdGao some suggestions

  1. construct as
You should respond a json object in a json fenced code block as follows:

{
    "thought": "some str",  // a string that represents what you thought
    "eliminate":true or false // a bool value that represents whether to eliminate a player or not
}

  1. add some post-hook like auto type conversion "123" -> 123, "true" -> True

Morriaty-The-Murderer avatar May 22 '24 07:05 Morriaty-The-Murderer

@DavdGao some suggestions

  1. construct as
You should respond a json object in a json fenced code block as follows:

{
    "thought": "some str",  // a string that represents what you thought
    "eliminate":true or false // a bool value that represents whether to eliminate a player or not
}
  1. add some post-hook like auto type conversion "123" -> 123, "true" -> True

Thank for the suggestions. We are woking on it.

DavdGao avatar May 22 '24 07:05 DavdGao

Update progress: The bug is being fixed in #261

In this PR, we support Pydantic class in content_hint parameter, so that we can specify more constraints and validate the generated dictionary during paring. Some simple fault tolerances are also supported, e.g. "123"==>123, "true" ==> true

You're welcome to review this PR if you're interested in it!

DavdGao avatar May 27 '24 12:05 DavdGao

Add support in #261

DavdGao avatar Jun 05 '24 11:06 DavdGao