You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
2 years ago
|
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
|
||
|
}
|