Skip to content

Commit

Permalink
feat: delete deprecated api and field (#24)
Browse files Browse the repository at this point in the history
* feat: delete deprecated api and field
  • Loading branch information
BytePender authored Jan 6, 2025
1 parent 7b9b0ae commit 10cdbd9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
5 changes: 1 addition & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,6 +27,7 @@ linters:
- ineffassign
- gofumpt
issues:
# include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin`
exclude-use-default: true
exclude-files:
- ".*\\.mock\\.go$"
Expand Down
21 changes: 16 additions & 5 deletions components/tool/utils/streamable_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/assert"

"github.com/cloudwego/eino/schema"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions compose/graph_call_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
36 changes: 18 additions & 18 deletions schema/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
}
}

Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions schema/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 10cdbd9

Please sign in to comment.