Skip to content

Commit 89a4d10

Browse files
authored
doc(eino): modify duckduckgo tool document (#1467)
1 parent e089332 commit 89a4d10

File tree

2 files changed

+98
-94
lines changed

2 files changed

+98
-94
lines changed

content/en/docs/eino/ecosystem_integration/tool/tool_duckduckgo_search.md

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Description: ""
3-
date: "2025-03-19"
3+
date: "2025-11-21"
44
lastmod: ""
55
tags: []
66
title: Tool - DuckDuckGoSearch
@@ -15,19 +15,16 @@ The DuckDuckGo Search Tool is an implementation of the Tool InvokableTool interf
1515

1616
### **Component Initialization**
1717

18-
The DuckDuckGo Search Tool is initialized through the `NewTool` function. The main configuration parameters are as follows:
18+
The DuckDuckGo Search Tool is initialized through the `NewTextSearchTool` function. The main configuration parameters are as follows:
1919

2020
```go
21-
import "github.com/cloudwego/eino-ext/components/tool/duckduckgo"
22-
23-
tool, err := duckduckgo.NewTool(ctx, &duckduckgo.Config{
24-
ToolName: "duckduckgo_search", // Tool name
25-
ToolDesc: "search web for information by duckduckgo", // Tool description
26-
Region: ddgsearch.RegionWT, // Search region
27-
MaxResults: 10, // Number of results per page
28-
SafeSearch: ddgsearch.SafeSearchOff, // Safe search level
29-
TimeRange: ddgsearch.TimeRangeAll, // Time range
30-
DDGConfig: &ddgsearch.Config{}, // DuckDuckGo configuration
21+
import "github.com/cloudwego/eino-ext/components/tool/duckduckgo/v2"
22+
23+
tool, err := duckduckgo.NewTextSearchTool(ctx, &duckduckgo.Config{
24+
ToolName: "duckduckgo_search",
25+
ToolDesc: "search for information by duckduckgo",
26+
Region: ddgsearch.RegionWT, // The geographical region for results.
27+
MaxResults: 3, // Limit the number of results returned.
3128
})
3229
```
3330

@@ -36,9 +33,12 @@ tool, err := duckduckgo.NewTool(ctx, &duckduckgo.Config{
3633
The search request supports the following parameters:
3734

3835
```go
39-
type SearchRequest struct {
40-
Query string `json:"query"` // Search keyword
41-
Page int `json:"page"` // Page number
36+
type TextSearchRequest struct {
37+
// Query is the user's search query
38+
Query string `json:"query"`
39+
// TimeRange is the search time range
40+
// Default: TimeRangeAny
41+
TimeRange TimeRange `json:"time_range"`
4242
}
4343
```
4444

@@ -54,59 +54,55 @@ import (
5454
"log"
5555
"time"
5656

57-
"github.com/cloudwego/eino-ext/components/tool/duckduckgo"
58-
"github.com/cloudwego/eino-ext/components/tool/duckduckgo/ddgsearch"
57+
"github.com/cloudwego/eino-ext/components/tool/duckduckgo/v2"
5958
)
6059

6160
func main() {
6261
ctx := context.Background()
6362

6463
// Create configuration
6564
config := &duckduckgo.Config{
66-
MaxResults: 3, // Limit to return 3 results
67-
Region: ddgsearch.RegionCN,
68-
DDGConfig: &ddgsearch.Config{
69-
Timeout: 10 * time.Second,
70-
Cache: true,
71-
MaxRetries: 5,
72-
},
65+
MaxResults: 3, // Limit to return 20 results
66+
Region: duckduckgo.RegionWT,
67+
Timeout: 10 * time.Second,
7368
}
7469

7570
// Create search client
76-
tool, err := duckduckgo.NewTool(ctx, config)
71+
tool, err := duckduckgo.NewTextSearchTool(ctx, config)
7772
if err != nil {
78-
log.Fatalf("NewTool of duckduckgo failed, err=%v", err)
73+
log.Fatalf("NewTextSearchTool of duckduckgo failed, err=%v", err)
7974
}
8075

81-
// Create search request
82-
searchReq := &duckduckgo.SearchRequest{
83-
Query: "Go programming development",
84-
Page: 1,
85-
}
76+
results := make([]*duckduckgo.TextSearchResult, 0, config.MaxResults)
8677

78+
searchReq := &duckduckgo.TextSearchRequest{
79+
Query: "eino",
80+
}
8781
jsonReq, err := json.Marshal(searchReq)
8882
if err != nil {
89-
log.Fatalf("Marshal of search request failed, err=%v", err)
83+
log.Fatalf("Marshal of search request failed, err=%v", err)
9084
}
9185

92-
// Execute search
9386
resp, err := tool.InvokableRun(ctx, string(jsonReq))
9487
if err != nil {
95-
log.Fatalf("Search of duckduckgo failed, err=%v", err)
88+
log.Fatalf("Search of duckduckgo failed, err=%v", err)
9689
}
9790

98-
var searchResp duckduckgo.SearchResponse
99-
if err := json.Unmarshal([]byte(resp), &searchResp); err != nil {
100-
log.Fatalf("Unmarshal of search response failed, err=%v", err)
91+
var searchResp duckduckgo.TextSearchResponse
92+
if err = json.Unmarshal([]byte(resp), &searchResp); err != nil {
93+
log.Fatalf("Unmarshal of search response failed, err=%v", err)
10194
}
10295

96+
results = append(results, searchResp.Results...)
97+
10398
// Print results
10499
fmt.Println("Search Results:")
105100
fmt.Println("==============")
106-
for i, result := range searchResp.Results {
107-
fmt.Printf("\n%d. Title: %s\n", i+1, result.Title)
108-
fmt.Printf(" Link: %s\n", result.Link)
109-
fmt.Printf(" Description: %s\n", result.Description)
101+
fmt.Printf("%s\n", searchResp.Message)
102+
for i, result := range results {
103+
fmt.Printf("\n%d. Title: %s\n", i+1, result.Title)
104+
fmt.Printf(" URL: %s\n", result.URL)
105+
fmt.Printf(" Summary: %s\n", result.Summary)
110106
}
111107
fmt.Println("")
112108
fmt.Println("==============")
@@ -117,16 +113,22 @@ func main() {
117113

118114
```json
119115
{
116+
"message": "Found 3 results successfully.",
120117
"results": [
121118
{
122-
"title": "Go Concurrent Programming Practice",
123-
"description": "This is an article about concurrent programming in Go...",
124-
"link": "https://example.com/article1"
119+
"title": "GitHub - cloudwego/eino: The ultimate LLM/AI application development ...",
120+
"url": "https://github.com/cloudwego/eino",
121+
"summary": "Eino ['aino] (pronounced similarly to \"I know\") aims to be the ultimate LLM application development framework in Golang. Drawing inspirations from many excellent LLM application development frameworks in the open-source community such as LangChain & LlamaIndex, etc., as well as learning from cutting-edge research and real world applications, Eino offers an LLM application development framework ..."
125122
},
126123
{
127-
"title": "Understanding Concurrency in Go",
128-
"description": "A comprehensive guide to concurrent programming...",
129-
"link": "https://example.com/article2"
124+
"title": "Eino: Overview | CloudWeGo",
125+
"url": "https://www.cloudwego.io/docs/eino/overview/",
126+
"summary": "Eino is a framework that simplifies and standardizes the development of LLM applications in Golang. It provides component abstractions, orchestration APIs, best practices, tools and examples for building and running LLM applications."
127+
}
128+
{
129+
"title": "Home - Eino - AI powered network planning",
130+
"url": "https://www.eino.ai/",
131+
"summary": "An easy-to-use, AI powered networking planning app that helps network planners create digital twins for their projects and plan every network type."
130132
}
131133
]
132134
}

content/zh/docs/eino/ecosystem_integration/tool/tool_duckduckgo_search.md

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Description: ""
3-
date: "2025-03-19"
3+
date: "2025-11-21"
44
lastmod: ""
55
tags: []
66
title: Tool - DuckDuckGoSearch
@@ -15,19 +15,16 @@ DuckDuckGo 搜索工具是 Tool InvokableTool 接口的一个实现,用于通
1515

1616
### **组件初始化**
1717

18-
DuckDuckGo 搜索工具通过 `NewTool` 函数进行初始化,主要配置参数如下:
18+
DuckDuckGo 搜索工具通过 `NewTextSearchTool` 函数进行初始化,主要配置参数如下:
1919

2020
```go
21-
import "github.com/cloudwego/eino-ext/components/tool/duckduckgo"
22-
23-
tool, err := duckduckgo.NewTool(ctx, &duckduckgo.Config{
24-
ToolName: "duckduckgo_search", // 工具名称
25-
ToolDesc: "search web for information by duckduckgo", // 工具描述
26-
Region: ddgsearch.RegionWT, // 搜索地区
27-
MaxResults: 10, // 每页结果数量
28-
SafeSearch: ddgsearch.SafeSearchOff, // 安全搜索级别
29-
TimeRange: ddgsearch.TimeRangeAll, // 时间范围
30-
DDGConfig: &ddgsearch.Config{}, // DuckDuckGo 配置
21+
import "github.com/cloudwego/eino-ext/components/tool/duckduckgo/v2"
22+
23+
tool, err := duckduckgo.NewTextSearchTool(ctx, &duckduckgo.Config{
24+
ToolName: "duckduckgo_search",
25+
ToolDesc: "search for information by duckduckgo",
26+
Region: ddgsearch.RegionWT, // The geographical region for results.
27+
MaxResults: 3, // Limit the number of results returned.
3128
})
3229
```
3330

@@ -36,9 +33,12 @@ tool, err := duckduckgo.NewTool(ctx, &duckduckgo.Config{
3633
搜索请求支持以下参数:
3734

3835
```go
39-
type SearchRequest struct {
40-
Query string `json:"query"` // 搜索关键词
41-
Page int `json:"page"` // 页码
36+
type TextSearchRequest struct {
37+
// Query is the user's search query
38+
Query string `json:"query"`
39+
// TimeRange is the search time range
40+
// Default: TimeRangeAny
41+
TimeRange TimeRange `json:"time_range"`
4242
}
4343
```
4444

@@ -54,59 +54,55 @@ import (
5454
"log"
5555
"time"
5656

57-
"github.com/cloudwego/eino-ext/components/tool/duckduckgo"
58-
"github.com/cloudwego/eino-ext/components/tool/duckduckgo/ddgsearch"
57+
"github.com/cloudwego/eino-ext/components/tool/duckduckgo/v2"
5958
)
6059

6160
func main() {
6261
ctx := context.Background()
6362

6463
// Create configuration
6564
config := &duckduckgo.Config{
66-
MaxResults: 3, // Limit to return 3 results
67-
Region: ddgsearch.RegionCN,
68-
DDGConfig: &ddgsearch.Config{
69-
Timeout: 10 * time.Second,
70-
Cache: true,
71-
MaxRetries: 5,
72-
},
65+
MaxResults: 3, // Limit to return 20 results
66+
Region: duckduckgo.RegionWT,
67+
Timeout: 10 * time.Second,
7368
}
7469

7570
// Create search client
76-
tool, err := duckduckgo.NewTool(ctx, config)
71+
tool, err := duckduckgo.NewTextSearchTool(ctx, config)
7772
if err != nil {
78-
log.Fatalf("NewTool of duckduckgo failed, err=%v", err)
73+
log.Fatalf("NewTextSearchTool of duckduckgo failed, err=%v", err)
7974
}
8075

81-
// Create search request
82-
searchReq := &duckduckgo.SearchRequest{
83-
Query: "Go programming development",
84-
Page: 1,
85-
}
76+
results := make([]*duckduckgo.TextSearchResult, 0, config.MaxResults)
8677

78+
searchReq := &duckduckgo.TextSearchRequest{
79+
Query: "eino",
80+
}
8781
jsonReq, err := json.Marshal(searchReq)
8882
if err != nil {
89-
log.Fatalf("Marshal of search request failed, err=%v", err)
83+
log.Fatalf("Marshal of search request failed, err=%v", err)
9084
}
9185

92-
// Execute search
9386
resp, err := tool.InvokableRun(ctx, string(jsonReq))
9487
if err != nil {
95-
log.Fatalf("Search of duckduckgo failed, err=%v", err)
88+
log.Fatalf("Search of duckduckgo failed, err=%v", err)
9689
}
9790

98-
var searchResp duckduckgo.SearchResponse
99-
if err := json.Unmarshal([]byte(resp), &searchResp); err != nil {
100-
log.Fatalf("Unmarshal of search response failed, err=%v", err)
91+
var searchResp duckduckgo.TextSearchResponse
92+
if err = json.Unmarshal([]byte(resp), &searchResp); err != nil {
93+
log.Fatalf("Unmarshal of search response failed, err=%v", err)
10194
}
10295

96+
results = append(results, searchResp.Results...)
97+
10398
// Print results
10499
fmt.Println("Search Results:")
105100
fmt.Println("==============")
106-
for i, result := range searchResp.Results {
107-
fmt.Printf("\n%d. Title: %s\n", i+1, result.Title)
108-
fmt.Printf(" Link: %s\n", result.Link)
109-
fmt.Printf(" Description: %s\n", result.Description)
101+
fmt.Printf("%s\n", searchResp.Message)
102+
for i, result := range results {
103+
fmt.Printf("\n%d. Title: %s\n", i+1, result.Title)
104+
fmt.Printf(" URL: %s\n", result.URL)
105+
fmt.Printf(" Summary: %s\n", result.Summary)
110106
}
111107
fmt.Println("")
112108
fmt.Println("==============")
@@ -117,16 +113,22 @@ func main() {
117113

118114
```json
119115
{
116+
"message": "Found 3 results successfully.",
120117
"results": [
121118
{
122-
"title": "Go 并发编程实践",
123-
"description": "这是一篇关于 Go 语言并发编程的文章...",
124-
"link": "https://example.com/article1"
119+
"title": "GitHub - cloudwego/eino: The ultimate LLM/AI application development ...",
120+
"url": "https://github.com/cloudwego/eino",
121+
"summary": "Eino ['aino] (pronounced similarly to \"I know\") aims to be the ultimate LLM application development framework in Golang. Drawing inspirations from many excellent LLM application development frameworks in the open-source community such as LangChain & LlamaIndex, etc., as well as learning from cutting-edge research and real world applications, Eino offers an LLM application development framework ..."
125122
},
126123
{
127-
"title": "Understanding Concurrency in Go",
128-
"description": "A comprehensive guide to concurrent programming...",
129-
"link": "https://example.com/article2"
124+
"title": "Eino: Overview | CloudWeGo",
125+
"url": "https://www.cloudwego.io/docs/eino/overview/",
126+
"summary": "Eino is a framework that simplifies and standardizes the development of LLM applications in Golang. It provides component abstractions, orchestration APIs, best practices, tools and examples for building and running LLM applications."
127+
}
128+
{
129+
"title": "Home - Eino - AI powered network planning",
130+
"url": "https://www.eino.ai/",
131+
"summary": "An easy-to-use, AI powered networking planning app that helps network planners create digital twins for their projects and plan every network type."
130132
}
131133
]
132134
}

0 commit comments

Comments
 (0)