Skip to content

Commit a0e96f1

Browse files
authored
refactor: migration from OpenAPIV3 to JSONSchema (#108)
1 parent 05568cd commit a0e96f1

File tree

6 files changed

+107
-163
lines changed

6 files changed

+107
-163
lines changed

components/tool/jsonschema/main.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2024 CloudWeGo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/davecgh/go-spew/spew"
23+
"github.com/eino-contrib/jsonschema"
24+
orderedmap "github.com/wk8/go-ordered-map/v2"
25+
26+
"github.com/cloudwego/eino/schema"
27+
)
28+
29+
func main() {
30+
JSONSchemaToToolInfo()
31+
}
32+
33+
func JSONSchemaToToolInfo() {
34+
js := &jsonschema.Schema{
35+
Type: string(schema.Object),
36+
Required: []string{"title"},
37+
Properties: orderedmap.New[string, *jsonschema.Schema](
38+
orderedmap.WithInitialData[string, *jsonschema.Schema](
39+
orderedmap.Pair[string, *jsonschema.Schema]{
40+
Key: "title",
41+
Value: &jsonschema.Schema{
42+
Type: string(schema.String),
43+
},
44+
},
45+
orderedmap.Pair[string, *jsonschema.Schema]{
46+
Key: "completed",
47+
Value: &jsonschema.Schema{
48+
Type: string(schema.Boolean),
49+
},
50+
},
51+
),
52+
),
53+
}
54+
55+
toolInfo := schema.ToolInfo{
56+
Name: "todo_manager",
57+
Desc: "manage todo list",
58+
ParamsOneOf: schema.NewParamsOneOfByJSONSchema(js),
59+
}
60+
61+
fmt.Printf("\n=========tool from api path=========\n")
62+
spew.Dump(toolInfo)
63+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 说明
22

3-
eino 提供了把 openapi3 文档中的 json schema 转为 eino tool schema 的方法。
3+
eino 提供了把 json schema 转为 eino tool schema 的方法。
44
对于想直接把一个 http 接口作为 eino 中的一个 tool 使用的场景,提供了便捷的方法。
55

66
关于 tool 更多的信息,可以参考: https://www.cloudwego.io/zh/docs/eino/core_modules/components/tools_node_guide/

components/tool/openapi3/main.go

Lines changed: 0 additions & 107 deletions
This file was deleted.

components/tool/openapi3/openapi.json

Lines changed: 0 additions & 44 deletions
This file was deleted.

go.mod

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,39 @@ toolchain go1.24.4
66

77
require (
88
github.com/bytedance/sonic v1.14.0
9-
github.com/cloudwego/eino v0.4.0
9+
github.com/cloudwego/eino v0.4.7
1010
github.com/cloudwego/eino-ext/components/document/parser/html v0.0.0-20250117061805-cd80d1780d76
1111
github.com/cloudwego/eino-ext/components/document/parser/pdf v0.0.0-20250117061805-cd80d1780d76
12-
github.com/cloudwego/eino-ext/components/model/ark v0.1.18
13-
github.com/cloudwego/eino-ext/components/model/deepseek v0.0.0-20250221090944-e8ef7aabbe10
14-
github.com/cloudwego/eino-ext/components/model/ollama v0.1.0
15-
github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250728034832-de7648551801
12+
github.com/cloudwego/eino-ext/components/model/ark v0.1.22
13+
github.com/cloudwego/eino-ext/components/model/deepseek v0.0.0-20250826125654-37d4a5029810
14+
github.com/cloudwego/eino-ext/components/model/ollama v0.1.2
15+
github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250826125654-37d4a5029810
1616
github.com/cloudwego/eino-ext/components/retriever/volc_vikingdb v0.0.0-20250319082935-6219ec437e56
17-
github.com/cloudwego/eino-ext/components/tool/duckduckgo/v2 v2.0.0-20250707040601-2fab92740585
17+
github.com/cloudwego/eino-ext/components/tool/duckduckgo/v2 v2.0.0-20250826125654-37d4a5029810
1818
github.com/cloudwego/eino-ext/devops v0.1.7
1919
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
20-
github.com/getkin/kin-openapi v0.118.0
21-
github.com/ollama/ollama v0.9.6
20+
github.com/eino-contrib/jsonschema v1.0.0
21+
github.com/ollama/ollama v0.11.4
2222
github.com/stretchr/testify v1.10.0
23+
github.com/wk8/go-ordered-map/v2 v2.1.8
2324
)
2425

2526
require (
2627
github.com/PuerkitoBio/goquery v1.10.3 // indirect
2728
github.com/andybalholm/cascadia v1.3.3 // indirect
2829
github.com/aymerick/douceur v0.2.0 // indirect
30+
github.com/bahlo/generic-list-go v0.2.0 // indirect
31+
github.com/buger/jsonparser v1.1.1 // indirect
2932
github.com/bytedance/sonic/loader v0.3.0 // indirect
3033
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
3134
github.com/cloudwego/base64x v0.1.5 // indirect
32-
github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250728034832-de7648551801 // indirect
33-
github.com/cohesion-org/deepseek-go v1.2.3 // indirect
35+
github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250826113018-8c6f6358d4bb // indirect
36+
github.com/cohesion-org/deepseek-go v1.3.2 // indirect
3437
github.com/corpix/uarand v0.2.0 // indirect
3538
github.com/dslipak/pdf v0.0.2 // indirect
3639
github.com/dustin/go-humanize v1.0.1 // indirect
3740
github.com/evanphx/json-patch v0.5.2 // indirect
41+
github.com/getkin/kin-openapi v0.118.0 // indirect
3842
github.com/go-openapi/jsonpointer v0.21.1 // indirect
3943
github.com/go-openapi/swag v0.23.1 // indirect
4044
github.com/google/uuid v1.6.0 // indirect
@@ -50,7 +54,7 @@ require (
5054
github.com/mailru/easyjson v0.9.0 // indirect
5155
github.com/matoous/go-nanoid v1.5.1 // indirect
5256
github.com/mattn/go-colorable v0.1.14 // indirect
53-
github.com/meguminnnnnnnnn/go-openai v0.0.0-20250723112853-3bce976e5ccc // indirect
57+
github.com/meguminnnnnnnnn/go-openai v0.0.0-20250821095446-07791bea23a0 // indirect
5458
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
5559
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5660
github.com/modern-go/reflect2 v1.0.2 // indirect

0 commit comments

Comments
 (0)