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

Update JSON API and example notebook #699

Merged

Conversation

riedgar-ms
Copy link
Collaborator

@riedgar-ms riedgar-ms commented Mar 15, 2024

Add the new JSON schema functionality to the example notebook for guaranteeing valid syntax. Also, rename the json_schema argument in the guidance.json() function to be just schema.

@slundberg
Copy link
Collaborator

Thanks @riedgar-ms ! Looks great. The only change I would suggest is changing from guidance.library import json as gen_json to from guidance import json as gen_json since we expose all the library functions at the top level.

One other note unrelated to this PR, why do we have json_schema instead of schema for json_schema=character_schema_obj? It seems like it is obviously a json schema since we are generating json and schema matches other libraries like jsonschema

@riedgar-ms
Copy link
Collaborator Author

No particular reason on the argument naming, beyond "That's what came to mind first." I have updated (tag @hudson-ai for info).

We probably should review the arguments across all public functions, and make sure we're consistent about which have to be named when present.

@riedgar-ms riedgar-ms changed the title Update JSON example notebook Update JSON API and example notebook Mar 17, 2024
@hudson-ai
Copy link
Collaborator

hudson-ai commented Mar 17, 2024

Wonderful! Thank you @riedgar-ms for looping me in :)

May be a separate PR, but it may be worth adding some extra info around effective prompting (in art_of_prompt_design?). Note in particular that quest_items are now just "."...

E.g. showing the LM what schema it will use ahead of time and even adding examples to the schema, e.g.

{
    "type": "object",
    "properties": {
        "description" : { "type" : "string" },
        "name" : { "type" : "string" },
        "age" : { "type" : "integer" },
        "armour" : { "type" : "string", "enum" : ["leather", "chainmail", "plate"] },
        "weapon" : { "type" : "string", "enum" : ["sword", "axe", "mace", "spear", "bow", "crossbow"] },
        "class" : { "type" : "string" },
        "mantra" : { "type" : "string" },
        "strength" : { "type" : "integer" },
        "quest_items" : {
            "type" : "array",
            "items": { "type": "string" },
            "examples": ["Triforce", "Master Sword"],
        }
    }
}

(although maybe not these examples, as Nintendo is very protective of its IP)

I'd also put forward that generating JSON is a popular enough use-case that an example deserves to be in the README, and maybe you guys could consider a version-bump and PyPI release in the near future ;)

@riedgar-ms
Copy link
Collaborator Author

@hudson-ai Something like that would probably be good in expanded documentation (I have a few ideas for what to do with the notebooks, since the fact that they're not run regularly is a big problem).

@slundberg does this look better to you?

@riedgar-ms
Copy link
Collaborator Author

Ping @slundberg

@riedgar-ms
Copy link
Collaborator Author

@slundberg does this address your concerns?

@riedgar-ms
Copy link
Collaborator Author

@slundberg ?

@codecov-commenter
Copy link

codecov-commenter commented Mar 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.61%. Comparing base (8f5b3bd) to head (3dfb1aa).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #699      +/-   ##
==========================================
- Coverage   69.19%   65.61%   -3.58%     
==========================================
  Files          53       53              
  Lines        3967     3967              
==========================================
- Hits         2745     2603     -142     
- Misses       1222     1364     +142     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@riedgar-ms
Copy link
Collaborator Author

@slundberg does this address your concerns?

@riedgar-ms
Copy link
Collaborator Author

@slundberg ?

@riedgar-ms
Copy link
Collaborator Author

Is the API now more in line with your preferences @slundberg ?

@Harsha-Nori
Copy link
Collaborator

API seems fine to me. Seems like a nice set of updates and examples - thanks! Merging.

@Harsha-Nori Harsha-Nori merged commit f8544be into guidance-ai:main Apr 3, 2024
80 checks passed
@riedgar-ms riedgar-ms deleted the riedgar-ms/json-notebook-schema-update branch April 3, 2024 10:08
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.

5 participants