Skip to content

Commit

Permalink
Update functioncall.go
Browse files Browse the repository at this point in the history
support array
  • Loading branch information
Naist4869 authored Sep 1, 2023
1 parent db9573c commit 38a2430
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions functioncall/functioncall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Param struct {
Description string `json:"description,omitempty"`
Required bool `json:"-"`
// Enum []any `json:"enum,omitempty"`
Items Params `json:",omitempty"`
}

func (funcs Funcs) MarshalJSON() ([]byte, error) {
Expand All @@ -38,12 +39,21 @@ func (funcs Funcs) MarshalJSON() ([]byte, error) {

func (params Params) MarshalJSON() ([]byte, error) {
required := []string{}
props := map[string]Param{}
props := map[string]any{}
for _, p := range params {
if p.Required {
required = append(required, p.Name)
}
props[p.Name] = p
if p.Type == "array" && p.Items != nil {
schema := map[string]any{
"type": "array",
"items": p.Items,
"required": required,
}
props[p.Name] = schema
} else {
props[p.Name] = p
}
}
schema := map[string]any{
"type": "object",
Expand Down

0 comments on commit 38a2430

Please sign in to comment.