diff --git a/.golangci.yaml b/.golangci.yaml index 140e7a6..075e061 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,7 +1,3 @@ -# Options for analysis running. -run: - # include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin` - skip-dirs-use-default: true # output configuration options output: # Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions @@ -31,6 +27,7 @@ linters: - ineffassign - gofumpt issues: + # include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin` exclude-use-default: true exclude-files: - ".*\\.mock\\.go$" diff --git a/components/tool/utils/streamable_func_test.go b/components/tool/utils/streamable_func_test.go index d388416..6618195 100644 --- a/components/tool/utils/streamable_func_test.go +++ b/components/tool/utils/streamable_func_test.go @@ -22,6 +22,7 @@ import ( "io" "testing" + "github.com/getkin/kin-openapi/openapi3" "github.com/stretchr/testify/assert" "github.com/cloudwego/eino/schema" @@ -66,12 +67,22 @@ func TestNewStreamableTool(t *testing.T) { info, err := tl.Info(ctx) assert.NoError(t, err) assert.Equal(t, "search_user", info.Name) - assert.Equal(t, map[string]*schema.ParameterInfo{ - "name": { - Type: "string", - Desc: "user name", + + js, err := info.ToOpenAPIV3() + assert.NoError(t, err) + + assert.Equal(t, &openapi3.Schema{ + Type: openapi3.TypeObject, + Properties: map[string]*openapi3.SchemaRef{ + "name": { + Value: &openapi3.Schema{ + Type: openapi3.TypeString, + Description: "user name", + }, + }, }, - }, info.Params) + Required: make([]string, 0), + }, js) sr, err := tl.StreamableRun(ctx, `{"name":"xxx"}`) assert.NoError(t, err) diff --git a/compose/graph_call_options.go b/compose/graph_call_options.go index 8783b3a..c4de4d8 100644 --- a/compose/graph_call_options.go +++ b/compose/graph_call_options.go @@ -163,11 +163,6 @@ func WithCallbacks(cbs ...callbacks.Handler) Option { } } -// Deprecated: use WithRuntimeMaxSteps directly instead. -func WithGraphRunOption(opt Option) Option { - return opt -} - // WithRuntimeMaxSteps sets the maximum number of steps for the graph runtime. // e.g. // diff --git a/schema/tool.go b/schema/tool.go index 87ccdec..0b0d2e3 100644 --- a/schema/tool.go +++ b/schema/tool.go @@ -46,8 +46,8 @@ type ToolInfo struct { // The parameters the functions accepts (different models may require different parameter types). // can be described in two ways: - // - use ParameterInfo: schema.NewParamsOneOfByParams(params) - // - use OpenAPIV3: schema.NewParamsOneOfByOpenAPIV3(openAPIV3) + // - use params: schema.NewParamsOneOfByParams(params) + // - use openAPIV3: schema.NewParamsOneOfByOpenAPIV3(openAPIV3) // If is nil, signals that the tool does not need any input parameter *ParamsOneOf } @@ -71,28 +71,28 @@ type ParameterInfo struct { // ParamsOneOf is a union of the different methods user can choose which describe a tool's request parameters. // User must specify one and ONLY one method to describe the parameters. -// 1. use Params: an intuitive way to describe the parameters that covers most of the use-cases. -// 2. use OpenAPIV3: a formal way to describe the parameters that strictly adheres to OpenAPIV3.0 specification. +// 1. use NewParamsOneOfByParams(): an intuitive way to describe the parameters that covers most of the use-cases. +// 2. use NewParamsOneOfByOpenAPIV3(): a formal way to describe the parameters that strictly adheres to OpenAPIV3.0 specification. // See https://github.com/getkin/kin-openapi/blob/master/openapi3/schema.go. type ParamsOneOf struct { - // deprecated: use NewParamsOneOfByParams instead, Params will no longer be exported in the future. - Params map[string]*ParameterInfo + // use NewParamsOneOfByParams to set this field + params map[string]*ParameterInfo - // deprecated: use NewParamsOneOfByOpenAPIV3 instead, OpenAPIV3 will no longer be exported in the future. - OpenAPIV3 *openapi3.Schema + // use NewParamsOneOfByOpenAPIV3 to set this field + openAPIV3 *openapi3.Schema } // NewParamsOneOfByParams creates a ParamsOneOf with map[string]*ParameterInfo. func NewParamsOneOfByParams(params map[string]*ParameterInfo) *ParamsOneOf { return &ParamsOneOf{ - Params: params, + params: params, } } // NewParamsOneOfByOpenAPIV3 creates a ParamsOneOf with *openapi3.Schema. func NewParamsOneOfByOpenAPIV3(openAPIV3 *openapi3.Schema) *ParamsOneOf { return &ParamsOneOf{ - OpenAPIV3: openAPIV3, + openAPIV3: openAPIV3, } } @@ -103,8 +103,8 @@ func (p *ParamsOneOf) ToOpenAPIV3() (*openapi3.Schema, error) { } var ( - useParameterInfo = p.Params != nil - useOpenAPIV3 = p.OpenAPIV3 != nil + useParameterInfo = p.params != nil + useOpenAPIV3 = p.openAPIV3 != nil ) if !useParameterInfo && !useOpenAPIV3 { @@ -115,15 +115,15 @@ func (p *ParamsOneOf) ToOpenAPIV3() (*openapi3.Schema, error) { return nil, fmt.Errorf("ParamsOneOf can only have one method to describe the parameters, but not multiple methods") } - if p.Params != nil { + if p.params != nil { sc := &openapi3.Schema{ - Properties: make(map[string]*openapi3.SchemaRef, len(p.Params)), + Properties: make(map[string]*openapi3.SchemaRef, len(p.params)), Type: openapi3.TypeObject, - Required: make([]string, 0, len(p.Params)), + Required: make([]string, 0, len(p.params)), } - for k := range p.Params { - v := p.Params[k] + for k := range p.params { + v := p.params[k] sc.Properties[k] = paramInfoToJSONSchema(v) if v.Required { sc.Required = append(sc.Required, k) @@ -133,7 +133,7 @@ func (p *ParamsOneOf) ToOpenAPIV3() (*openapi3.Schema, error) { return sc, nil } - return p.OpenAPIV3, nil + return p.openAPIV3, nil } func paramInfoToJSONSchema(paramInfo *ParameterInfo) *openapi3.SchemaRef { diff --git a/schema/tool_test.go b/schema/tool_test.go index fe33b96..343396d 100644 --- a/schema/tool_test.go +++ b/schema/tool_test.go @@ -38,25 +38,25 @@ func TestParamsOneOfToJSONSchema(t *testing.T) { }) convey.Convey("user provides multiple options in ParamsOneOf", func() { - oneOf.Params = make(map[string]*ParameterInfo) - oneOf.OpenAPIV3 = &openapi3.Schema{} + oneOf.params = make(map[string]*ParameterInfo) + oneOf.openAPIV3 = &openapi3.Schema{} _, err = oneOf.ToOpenAPIV3() convey.So(err, convey.ShouldNotBeNil) convey.So(err.Error(), convey.ShouldContainSubstring, "ParamsOneOf can only have one method to describe the parameters, but not multiple methods") }) convey.Convey("user provides openAPIV3.0 json schema directly, use what the user provides", func() { - oneOf.OpenAPIV3 = &openapi3.Schema{ + oneOf.openAPIV3 = &openapi3.Schema{ Type: openapi3.TypeString, Description: "this is the only argument", } converted, err = oneOf.ToOpenAPIV3() convey.So(err, convey.ShouldBeNil) - convey.So(converted, convey.ShouldResemble, oneOf.OpenAPIV3) + convey.So(converted, convey.ShouldResemble, oneOf.openAPIV3) }) convey.Convey("user provides map[string]ParameterInfo, converts to json schema", func() { - oneOf.Params = map[string]*ParameterInfo{ + oneOf.params = map[string]*ParameterInfo{ "arg1": { Type: String, Desc: "this is the first argument",