[Bug]: Is It possible to make type hints for `response.metadata`?
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
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
- 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 some suggestions
- 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
}
- add some post-hook like auto type conversion
"123" -> 123,"true" -> True
@DavdGao some suggestions
- 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 }
- add some post-hook like auto type conversion
"123" -> 123,"true" -> True
Thank for the suggestions. We are woking on it.
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!
Add support in #261