mirror of
https://github.com/mudler/LocalAI.git
synced 2025-04-25 13:29:58 +00:00
* refactor: break down json grammar parser in different files Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: patch to `refactor_grammars` - propagate errors (#3006) propagate errors around Signed-off-by: Dave Lee <dave@gray101.com> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Signed-off-by: Dave Lee <dave@gray101.com> Co-authored-by: Dave <dave@gray101.com>
26 lines
684 B
Go
26 lines
684 B
Go
package functions
|
|
|
|
import "encoding/json"
|
|
|
|
type Item struct {
|
|
Type string `json:"type"`
|
|
Properties map[string]interface{} `json:"properties"`
|
|
}
|
|
|
|
type JSONFunctionStructure struct {
|
|
OneOf []Item `json:"oneOf,omitempty"`
|
|
AnyOf []Item `json:"anyOf,omitempty"`
|
|
Defs map[string]interface{} `json:"$defs,omitempty"`
|
|
}
|
|
|
|
func (j JSONFunctionStructure) Grammar(options ...func(*GrammarOption)) (string, error) {
|
|
grammarOpts := &GrammarOption{}
|
|
grammarOpts.Apply(options...)
|
|
|
|
dat, err := json.Marshal(j)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return NewJSONSchemaConverter(grammarOpts.PropOrder).GrammarFromBytes(dat, options...)
|
|
}
|