Skip to content
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

Extract function name in get_schema_from_signature #878

Merged
merged 2 commits into from
May 8, 2024

Conversation

eitanturok
Copy link
Contributor

@eitanturok eitanturok commented May 8, 2024

Currently, get_schema_from_signature creates a json where "title": "Arguments". This PR changes this so that the "title" will instead be mapped to the function's name.

Here is an example. I have this code snippet:

from outlines.fsm.json_schema import get_schema_from_signature

def test_add(a: int, b: int | None = None):
    if b is None:
        return a
    return a + b

schema = get_schema_from_signature(test_add)
print(schema)

Before this PR, this outputted

{'properties': {'a': {'title': 'A', 'type': 'integer'}, 'b': {'anyOf': [{'type': 'integer'}, {'type': 'null'}], 'title': 'B'}}, 'required': ['a', 'b'], 'title': 'Arguments', 'type': 'object'}

and after this PR, this outputted

{'properties': {'a': {'title': 'A', 'type': 'integer'}, 'b': {'anyOf': [{'type': 'integer'}, {'type': 'null'}], 'title': 'B'}}, 'required': ['a', 'b'], 'title': 'test_add', 'type': 'object'}

(Scroll to see the 'title' key.)

@eitanturok
Copy link
Contributor Author

Initial discussion occurred in #863.

@leloykun
Copy link
Contributor

leloykun commented May 8, 2024

ah, I also raised a (now duplicate) PR 😅

#875

I'll close mine

@rlouf rlouf merged commit 97ec37d into dottxt-ai:main May 8, 2024
5 checks passed
@rlouf rlouf added structured generation Linked to structured generation JSON labels May 8, 2024
@eitanturok eitanturok deleted the patch-3 branch May 9, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON structured generation Linked to structured generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants