mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-23 06:22:23 +00:00
2169c3497d
* wip Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * get rid of panics Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * expose it properly from the config Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Simplify Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * forgot to commit Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Remove focus on test Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Small fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package grammars_test
|
|
|
|
import (
|
|
"strings"
|
|
|
|
. "github.com/mudler/LocalAI/pkg/functions/grammars"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
const (
|
|
testllama31Input1 = `
|
|
{
|
|
"oneOf": [
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"function": {"const": "create_event"},
|
|
"arguments": {
|
|
"type": "object",
|
|
"properties": {
|
|
"title": {"type": "string"},
|
|
"date": {"type": "string"},
|
|
"time": {"type": "string"}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"function": {"const": "search"},
|
|
"arguments": {
|
|
"type": "object",
|
|
"properties": {
|
|
"query": {"type": "string"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}`
|
|
// <function=example_function_name>{{"example_name": "example_value"}}</function>
|
|
testllama31inputResult1 = `root-0-function ::= "create_event"
|
|
freestring ::= (
|
|
[^"\\] |
|
|
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
|
|
)* space
|
|
root-0 ::= "<function=" root-0-function ">{" root-0-arguments "}</function>"
|
|
root-1-arguments ::= "{" space "\"query\"" space ":" space string "}" space
|
|
root ::= root-0 | root-1
|
|
space ::= " "?
|
|
root-0-arguments ::= "{" space "\"date\"" space ":" space string "," space "\"time\"" space ":" space string "," space "\"title\"" space ":" space string "}" space
|
|
root-1 ::= "<function=" root-1-function ">{" root-1-arguments "}</function>"
|
|
string ::= "\"" (
|
|
[^"\\] |
|
|
"\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
|
|
)* "\"" space
|
|
root-1-function ::= "search"`
|
|
)
|
|
|
|
var _ = Describe("JSON schema grammar tests", func() {
|
|
Context("JSON", func() {
|
|
It("generates a valid grammar from JSON schema", func() {
|
|
grammar, err := NewLLama31SchemaConverter("function").GrammarFromBytes([]byte(testllama31Input1))
|
|
Expect(err).ToNot(HaveOccurred())
|
|
results := strings.Split(testllama31inputResult1, "\n")
|
|
for _, r := range results {
|
|
if r != "" {
|
|
Expect(grammar).To(ContainSubstring(r))
|
|
}
|
|
}
|
|
Expect(len(results)).To(Equal(len(strings.Split(grammar, "\n"))))
|
|
})
|
|
})
|
|
})
|