mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-21 19:15:00 +00:00
feat: add grammar and functions call support
This commit is contained in:
parent
a6839fd238
commit
f09ddd2983
7 changed files with 571 additions and 9 deletions
50
pkg/grammar/functions.go
Normal file
50
pkg/grammar/functions.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package grammar
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Function struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Parameters map[string]interface{} `json:"parameters"`
|
||||
}
|
||||
type Functions []Function
|
||||
|
||||
func (f Functions) ToJSONStructure() JSONStructure {
|
||||
js := JSONStructure{}
|
||||
for _, function := range f {
|
||||
// t := function.Parameters["type"]
|
||||
//tt := t.(string)
|
||||
|
||||
properties := function.Parameters["properties"]
|
||||
dat, _ := json.Marshal(properties)
|
||||
prop := map[string]interface{}{}
|
||||
json.Unmarshal(dat, &prop)
|
||||
js.OneOf = append(js.OneOf, Item{
|
||||
Type: "object",
|
||||
Properties: Properties{
|
||||
Function: FunctionName{Const: function.Name},
|
||||
Arguments: Argument{
|
||||
Type: "object",
|
||||
Properties: prop,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
return js
|
||||
}
|
||||
|
||||
// Select returns a list of functions containing the function with the given name
|
||||
func (f Functions) Select(name string) Functions {
|
||||
var funcs Functions
|
||||
|
||||
for _, f := range f {
|
||||
if f.Name == name {
|
||||
funcs = []Function{f}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return funcs
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue