mirror of
https://github.com/mudler/LocalAI.git
synced 2026-04-01 13:42:20 -04:00
* feat: add distributed mode (experimental) Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix data races, mutexes, transactions Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix events and tool stream in agent chat Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * use ginkgo Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(cron): compute correctly time boundaries avoiding re-triggering Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * enhancements, refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * do not flood of healthy checks Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * do not list obvious backends as text backends Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * tests fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Drop redundant healthcheck Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * enhancements, refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
86 lines
2.6 KiB
Go
86 lines
2.6 KiB
Go
package functions_test
|
|
|
|
import (
|
|
. "github.com/mudler/LocalAI/pkg/functions"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("LocalAI grammar functions", func() {
|
|
Describe("ToJSONStructure()", func() {
|
|
It("converts a list of functions to a JSON structure that can be parsed to a grammar", func() {
|
|
var functions Functions = []Function{
|
|
{
|
|
Name: "create_event",
|
|
Parameters: map[string]any{
|
|
"properties": map[string]any{
|
|
"event_name": map[string]any{
|
|
"type": "string",
|
|
},
|
|
"event_date": map[string]any{
|
|
"type": "string",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "search",
|
|
Parameters: map[string]any{
|
|
"properties": map[string]any{
|
|
"query": map[string]any{
|
|
"type": "string",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
js := functions.ToJSONStructure("function", "arguments")
|
|
Expect(len(js.OneOf)).To(Equal(2))
|
|
fnName := js.OneOf[0].Properties["function"].(FunctionName)
|
|
fnArgs := js.OneOf[0].Properties["arguments"].(Argument)
|
|
Expect(fnName.Const).To(Equal("create_event"))
|
|
Expect(fnArgs.Properties["event_name"].(map[string]any)["type"]).To(Equal("string"))
|
|
Expect(fnArgs.Properties["event_date"].(map[string]any)["type"]).To(Equal("string"))
|
|
|
|
fnName = js.OneOf[1].Properties["function"].(FunctionName)
|
|
fnArgs = js.OneOf[1].Properties["arguments"].(Argument)
|
|
Expect(fnName.Const).To(Equal("search"))
|
|
Expect(fnArgs.Properties["query"].(map[string]any)["type"]).To(Equal("string"))
|
|
|
|
// Test with custom keys
|
|
jsN := functions.ToJSONStructure("name", "arguments")
|
|
Expect(len(jsN.OneOf)).To(Equal(2))
|
|
|
|
fnName = jsN.OneOf[0].Properties["name"].(FunctionName)
|
|
fnArgs = jsN.OneOf[0].Properties["arguments"].(Argument)
|
|
|
|
Expect(fnName.Const).To(Equal("create_event"))
|
|
Expect(fnArgs.Properties["event_name"].(map[string]any)["type"]).To(Equal("string"))
|
|
Expect(fnArgs.Properties["event_date"].(map[string]any)["type"]).To(Equal("string"))
|
|
|
|
fnName = jsN.OneOf[1].Properties["name"].(FunctionName)
|
|
fnArgs = jsN.OneOf[1].Properties["arguments"].(Argument)
|
|
|
|
Expect(fnName.Const).To(Equal("search"))
|
|
Expect(fnArgs.Properties["query"].(map[string]any)["type"]).To(Equal("string"))
|
|
})
|
|
})
|
|
Context("Select()", func() {
|
|
It("selects one of the functions and returns a list containing only the selected one", func() {
|
|
var functions Functions = []Function{
|
|
{
|
|
Name: "create_event",
|
|
},
|
|
{
|
|
Name: "search",
|
|
},
|
|
}
|
|
|
|
functions = functions.Select("create_event")
|
|
Expect(len(functions)).To(Equal(1))
|
|
Expect(functions[0].Name).To(Equal("create_event"))
|
|
})
|
|
})
|
|
})
|