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

Allow Non-Strict mode in generate.json #1159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lapp0
Copy link
Contributor

@lapp0 lapp0 commented Sep 17, 2024

Fixes #985

Problem

For generate.json(), Sometimes models exhaust their available token length and generate a sequence which isn't valid JSON or doesn't comply with the provided schema.

Solution

Implement strict mode, which defaults to True (same behavior as main)

If generate.json(..., strict=False) is called, an error dict will be returned rather than an error being raised.

{
    'error': 'Unterminated string starting at: line 1 column 13 (char 12)', 
    'error_type': 'JSONDecodeError', 
    'output': '{"this output obviously is not valid JSON',
}

@lapp0 lapp0 changed the title Create optional generate.json(..., strict=False) Allow Non-Strict mode in generate.json Sep 17, 2024
@lapp0 lapp0 marked this pull request as ready for review September 17, 2024 20:16
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 this pull request may close these issues.

Add a non_strict mode to deal with JSONDecodeError errors
1 participant