AnswerDotAI / AnswerDotAI/toolslm

Support Annotated types for field descriptions in schema generation

Open
#69 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
68
Forks
14
Avg merge
1m
Merged PRs (30d)
1

Description

https://github.com/AnswerDotAI/toolslm/blob/b3b7f8b800536d5dbad56349f3e8a0b8abb66113/toolslm/funccall.py#L40

When using `lite_mk_func` with dataclasses, field descriptions are not populated from type hints. A fix solve.it help figured out is to support `typing.Annotated` to specify field descriptions:

```python
from typing import Annotated, Optional

@dataclass
class Adult:
"How adults are supposed to help in this game"
adult_role: Annotated[str, "facilitator | demonstrator | player | observer"]
adults_required: Annotated[int, "Number of adults needed"]
losing_gracefully: Annotated[Optional[bool], "Can adult elegantly lose? None if not competitive"]
```

But this would cause it to produces empty descriptions and incorrect types (`'type': 'object'` instead of `'string'`).

```
{'type': 'function',
'function': {'name': 'Adult',
'description': 'How do adults supposed to help in this game',
'parameters': {'type': 'object',
'properties': {'adult_role': {'type': 'object', 'description': ''},
'adults_required': {'type': 'object', 'description': ''},
'losing_gracefully': {'type': 'object', 'description': ''}},
'title': 'Adult',
'required': ['adult_role', 'adults_required', 'losing_gracefully']}}}
```

This requires modifying `_param` and `_process_property` in `funccall.py`.

With solve.it's help I explored the fix a bit here: https://share.solve.it.com/d/75ab5d185e67486d066af43420ea2eba

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.