Skip to content

Commit

Permalink
fix: fix tool calls required omitempty field
Browse files Browse the repository at this point in the history
Co-Authored-By: Minghan Zhang <[email protected]>
  • Loading branch information
Sh1n3zZ and zmh-program committed Jun 21, 2024
1 parent 485066f commit 78ff6a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 7 additions & 4 deletions adapter/skylark/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package skylark
import (
"chat/globals"
"chat/utils"

structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/volcengine/volc-sdk-golang/service/maas/models/api"
)
Expand All @@ -20,19 +21,21 @@ func getFunctionCall(calls *globals.ToolCalls) *api.FunctionCall {
}

func getType(p globals.ToolProperty) string {
if p.Type == nil {
t, ok := p["type"]
if !ok {
return "string"
}

return *p.Type
return t.(string)
}

func getDescription(p globals.ToolProperty) string {
if p.Description == nil {
desc, ok := p["description"]
if !ok {
return ""
}

return *p.Description
return desc.(string)
}

func getValue(p globals.ToolProperty) *structpb.Value {
Expand Down
5 changes: 3 additions & 2 deletions globals/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ToolFunction struct {
type ToolParameters struct {
Type string `json:"type"`
Properties ToolProperties `json:"properties"`
Required []string `json:"required"`
Required *[]string `json:"required,omitempty"`
}

type ToolProperties map[string]ToolProperty
Expand All @@ -25,7 +25,8 @@ type ToolProperties map[string]ToolProperty

type JsonSchemaType any
type JSONSchemaDefinition any
type ToolProperty struct {
type ToolProperty map[string]interface{}
type DetailToolProperty struct {
Type *string `json:"type,omitempty"`
Enum *[]JsonSchemaType `json:"enum,omitempty"`
Const *JsonSchemaType `json:"const,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions utils/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func NumTokensFromMessages(messages []globals.Message, model string, responseTyp
}

func NumTokensFromResponse(response string, model string) int {
if len(response) == 0 {
return 0
}

return NumTokensFromMessages([]globals.Message{{Content: response}}, model, true)
}

Expand Down

0 comments on commit 78ff6a1

Please sign in to comment.