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

Improve parser support #146

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open

Improve parser support #146

wants to merge 42 commits into from

Conversation

cpfiffer
Copy link
Collaborator

@cpfiffer cpfiffer commented May 5, 2024

Please see #143, and #68 which this will eventually address.

This adds support for a typed JSON from arbitrary structs, such as

# Simple flat structure where each field is a primitive type
struct SimpleSingleton
    singleton_value::Int
end

typed_json_schema(SimpleSingleton)
Dict{Any, Any} with 1 entry:
  :singleton_value => "integer"
# Test a struct that contains another struct.
struct Nested
    inside_element::SimpleSingleton
end

typed_json_schema(Nested)
Dict{Any, Any} with 1 entry:
  :inside_element => Dict{Any, Any}("singleton_value" => "integer")
# Test a struct with a vector of primitives
struct ABunchOfVectors
    strings::Vector{String}
    ints::Vector{Int}
    floats::Vector{Float64}
    nested_vector::Vector{Nested}
end

typed_json_schema(ABunchOfVectors)
Dict{Any, Any} with 4 entries:
  :strings       => "string[]"
  :ints          => "integer[]"
  :nested_vector => Dict("list[Object]"=>"{\"inside_element\":{\"singleton_value\":\"integer\"}}")
  :floats        => "number[]"

It isn't really integrated with the rest of the ecosystem yet, I may need help from @svilupp on that one.

@cpfiffer cpfiffer changed the title [FR] Add support for structured extraction with Ollama models Improve parser support May 5, 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 this pull request may close these issues.

4 participants