Skip to content

Support for additional properties #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
comfuture opened this issue Dec 1, 2024 · 0 comments · May be fixed by #21
Open

Support for additional properties #19

comfuture opened this issue Dec 1, 2024 · 0 comments · May be fixed by #21
Assignees

Comments

@comfuture
Copy link
Owner

comfuture commented Dec 1, 2024

Currently, the function schema utility does not support useful additional properties such as maximum, minimum, and max_length in the generated JSON schemas for Python functions. This feature enhancement would provide greater flexibility and precision in schema definitions.

Additional Context

Before implementing this enhancement, it is necessary to review how to specify additional properties in Annotations to ensure a consistent and user-friendly approach.

Suggestion 1. Consider dict argument as additional properties

user_id: Annotated[str, Doc("Username of service"), {"min_length": 5, "pattern": "a-za-z0-9_{4,}"}]

Pros: easy
Cons: Break if any tool that was using dict in them for any other purpose

Suggestion 2. Pydantic-like approach

num_images: Annotated[int, Doc("Number of images to generate"), FieldInfo(gte=1, lte=4)]

Pros: Familiar with who are using Pydantic already.
Cons: Make things complex.

Suggestion 3. Magic keyword

from function_schema import FieldInfo as F


def create_image(
    prompt: Annotated[
        str,
        Doc(
            "Detailed prompt for generate image that contains"
            " camera angle, style, emotional moods, and color tones"
        ),
        F.length > 20,
    ],
    num_images: Annotated[int, Doc("Number of images to generate"), 1 <= F <= 4] = 1,
    user_id: Annotated[
        Optional[str],
        Doc("Username for audit"),
        F.length < 20,
        F.pattern("a-za-z0-9_{4,}"),
    ] = None,
): ...

Pros:

Consistency: Provides a consistent way to specify additional properties across different functions and modules.
Readability: Enhances code readability by clearly specifying constraints and properties directly in the function signature.
Validation: Facilitates automatic validation of input parameters based on the specified properties.
Documentation: Serves as in-line documentation, making it easier for developers to understand the expected constraints and properties of function parameters.

Cons:

Complexity: Increases the complexity of the function signature, which may make it harder to read and understand for newcomers.
Learning Curve: Requires developers to learn and understand the specific syntax and usage of the magic keywords.
Error Handling: May introduce subtle bugs if the magic keywords are not used correctly or if there are conflicts with existing annotations.
Performance: Potentially impacts performance due to the additional processing required to interpret and validate the magic keywords.

@comfuture comfuture linked a pull request Dec 1, 2024 that will close this issue
@comfuture comfuture self-assigned this Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant