mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat: update integer, number and string rules - allow primitives as root types (#862)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
08b59b5cc5
commit
4aa5dac768
2 changed files with 14 additions and 5 deletions
|
@ -15,10 +15,13 @@ var (
|
||||||
|
|
||||||
PRIMITIVE_RULES = map[string]string{
|
PRIMITIVE_RULES = map[string]string{
|
||||||
"boolean": `("true" | "false") space`,
|
"boolean": `("true" | "false") space`,
|
||||||
"number": `[0-9]+ space`, // TODO complete
|
"number": `("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? space`,
|
||||||
"integer": `[0-9]+ space`, // TODO complete
|
"integer": `("-"? ([0-9] | [1-9] [0-9]*)) space`,
|
||||||
"string": `"\"" [ \t!#-\[\]-~]* "\"" space`, // TODO complete
|
"string": `"\"" (
|
||||||
"null": `"null" space`,
|
[^"\\] |
|
||||||
|
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
|
||||||
|
)* "\"" space`,
|
||||||
|
"null": `"null" space`,
|
||||||
}
|
}
|
||||||
|
|
||||||
INVALID_RULE_CHARS_RE = regexp.MustCompile(`[^a-zA-Z0-9-]+`)
|
INVALID_RULE_CHARS_RE = regexp.MustCompile(`[^a-zA-Z0-9-]+`)
|
||||||
|
@ -176,6 +179,9 @@ func (sc *JSONSchemaConverter) visit(schema map[string]interface{}, name string,
|
||||||
if !exists {
|
if !exists {
|
||||||
panic(fmt.Sprintf("Unrecognized schema: %v", schema))
|
panic(fmt.Sprintf("Unrecognized schema: %v", schema))
|
||||||
}
|
}
|
||||||
|
if ruleName == "root" {
|
||||||
|
schemaType = "root"
|
||||||
|
}
|
||||||
return sc.addRule(schemaType, primitiveRule)
|
return sc.addRule(schemaType, primitiveRule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,10 @@ root ::= root-0 | root-1
|
||||||
space ::= " "?
|
space ::= " "?
|
||||||
root-0-arguments ::= "{" space "\"date\"" space ":" space string "," space "\"time\"" space ":" space string "," space "\"title\"" space ":" space string "}" space
|
root-0-arguments ::= "{" space "\"date\"" space ":" space string "," space "\"time\"" space ":" space string "," space "\"title\"" space ":" space string "}" space
|
||||||
root-1 ::= "{" space "\"arguments\"" space ":" space root-1-arguments "," space "\"function\"" space ":" space root-1-function "}" space
|
root-1 ::= "{" space "\"arguments\"" space ":" space root-1-arguments "," space "\"function\"" space ":" space root-1-function "}" space
|
||||||
string ::= "\"" [ \t!#-\[\]-~]* "\"" space
|
string ::= "\"" (
|
||||||
|
[^"\\] |
|
||||||
|
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
|
||||||
|
)* "\"" space
|
||||||
root-1-function ::= "\"search\""`
|
root-1-function ::= "\"search\""`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue