You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add genson integration for json generation (#1390)
This PR aims at integrating support of the `genson` package (in
`generate.json`) to be able to use dynamic json schema generation as
proposed in #1383.
Copy file name to clipboardExpand all lines: docs/reference/generation/json.md
+73
Original file line number
Diff line number
Diff line change
@@ -103,3 +103,76 @@ print(add(**result))
103
103
```
104
104
105
105
A great advantage of passing functions directly to specify the structure is that the structure of the LLM will change with the function's definition. No need to change the code at several places!
106
+
107
+
108
+
## From a dynamic JSON schema builder - GenSON
109
+
110
+
Outlines integrated [GenSON](https://github.com/wolverdude/GenSON) builders to be able to dynamicly declare JSON schemas. It can be used as follow:
Anytime you are updating the schema through the builder, you need to redifine the outline generator to include these changes. From the the previous example:
res = generator("Return a json of a youg boy whose hobby is coding")
159
+
print(res)
160
+
# {"name": "Ben", "age": 10, "hobby": "coding"}
161
+
```
162
+
163
+
!!! Note
164
+
165
+
Beware of [GenSON](https://github.com/wolverdude/GenSON)'s behavior regarding dynamic amending of schemas through their builder. Here is an example of how you could lose `required` informations and generate json with missing fields:
0 commit comments