Skip to content

Support Annotated types for field descriptions in schema generation #69

@boboletus

Description

@boboletus

def _param(

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions