Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl duckduckgo search tool #5

Merged
merged 1 commit into from
Dec 26, 2024
Merged

Conversation

kuhahalong
Copy link
Contributor

What type of PR is this?

feat

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

PR Title: feat(tool): add DuckDuckGo search tool implementation

Translate the PR title into Chinese.

feat(tool): 添加 DuckDuckGo 搜索工具实现

More detailed description for this PR

en:
This PR adds a DuckDuckGo search tool implementation that integrates with Eino's tool system. The implementation includes:

  1. A native Go library for DuckDuckGo search functionality (ddgsearch package)
  2. An Eino tool implementation that wraps the DuckDuckGo search library
  3. Key features:
    • No authentication required for API usage
    • Configurable search parameters (region, timeout, retries, etc.)
    • Easy integration with Eino's ToolsNode
  4. Comprehensive documentation in both English and Chinese

zh:
本 PR 添加了一个与 Eino 工具系统集成的 DuckDuckGo 搜索工具实现。该实现包括:

  1. 一个原生 Go 语言的 DuckDuckGo 搜索功能库(ddgsearch 包)
  2. 一个封装了 DuckDuckGo 搜索库的 Eino 工具实现
  3. 主要特性:
    • 无需 API 认证
    • 可配置的搜索参数(地区、超时、重试等)
    • 易于与 Eino 的 ToolsNode 集成
  4. 完整的中英文文档支持

Which issue(s) this PR fixes:

N/A

The PR that updates user documentation:

Documentation is included in this PR with comprehensive README files in both English and Chinese.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license-eye has totally checked 53 files.

Valid Invalid Ignored Fixed
39 14 0 0
Click to see the invalid file list
  • components/tool/duckduckgo/ddgsearch/cache.go
  • components/tool/duckduckgo/ddgsearch/client.go
  • components/tool/duckduckgo/ddgsearch/client_test.go
  • components/tool/duckduckgo/ddgsearch/doc.go
  • components/tool/duckduckgo/ddgsearch/errors.go
  • components/tool/duckduckgo/ddgsearch/search_news.go
  • components/tool/duckduckgo/ddgsearch/search_news_test.go
  • components/tool/duckduckgo/ddgsearch/search_text.go
  • components/tool/duckduckgo/ddgsearch/types.go
  • components/tool/duckduckgo/ddgsearch/utils.go
  • components/tool/duckduckgo/ddgsearch/utils_test.go
  • components/tool/duckduckgo/example/main.go
  • components/tool/duckduckgo/search.go
  • components/tool/duckduckgo/search_test.go

components/tool/duckduckgo/ddgsearch/cache.go Show resolved Hide resolved
components/tool/duckduckgo/ddgsearch/doc.go Show resolved Hide resolved
components/tool/duckduckgo/ddgsearch/utils.go Show resolved Hide resolved
components/tool/duckduckgo/example/main.go Show resolved Hide resolved
components/tool/duckduckgo/search.go Show resolved Hide resolved
components/tool/duckduckgo/search_test.go Show resolved Hide resolved
@kuhahalong kuhahalong force-pushed the feat/tool_ddgsearch branch 2 times, most recently from 2ea8f5e to 1be3206 Compare December 24, 2024 04:50

English | [简体中文](README_zh.md)

A DuckDuckGo search tool implementation for [Eino](https://github.com/cloudwego/eino). This tool implements the `InvokableTool` interface, allowing it to be used with Eino's ChatModel interaction system with `ToolsNode`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段让模型帮忙改写下吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

虽然就是模型写的 😂,感觉不通顺吗

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥会有 ddgsearch 这个东西?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为 ddgsearch 比较复杂,预计后面不仅提供 Search text 的 tool,还有其他的,因此把实现统一封装到 ddgsearch 中,对标 langchain 中的 ddg_search 包

return nil
}

func NewDDGS(ctx context.Context, config *Config) (*DDGS, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥定一个 NewDDGS,不直接合并到 NewTool 里面

Copy link
Contributor

@BytePender BytePender Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1,这个包不应该暴露,用户不应该看到这个函数

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那看放哪儿合适?按理这应该是一个三方实现,此处仅做简单封装即可,但目前 golang 中没有比较通用的 duckduckgo 的实现,因此需要自己实现。
之前准备放 internal 中,但也不大合适,对于 Config ,直接引用比自己重新封装一层更简单直接。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果完全放到当前包下并不暴露,则有点把 duckduckgo search 的实现和 tool 绑定太深了,也不利于复用。
如上一个 comment 中所说,duckduckgo 的调用实现比较复杂,而且 duckduckgo 不仅仅支持 text search 的能力,还有 news、image 等等的搜索、ai chat 等能力,把 duckduckgo 的能力聚合到其本身而不是 tool 中会更好

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

刚刚误解你们的意思了,理解成了 ddgsearch 这个目录要不暴露。func NewDDGS 已经改成了 newDDGS, 还是按照当前组件下仅暴露组件的创建和使用接口

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,先按照 tool 的核心职责仅暴露必要的内容。 至于底层的通用函数,再根据实际需求到来时,再决定是否对外暴露。

Retries int `json:"retries"` // default: 3
Timeout int `json:"timeout"` // max timeout in seconds, default: 10
MaxResults int `json:"max_results"` // default: 10
Proxy string `json:"proxy"` // default: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个该咋用

@kuhahalong kuhahalong force-pushed the feat/tool_ddgsearch branch 3 times, most recently from ff6c4c7 to 62761b2 Compare December 24, 2024 07:07
@CLAassistant
Copy link

CLAassistant commented Dec 24, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

go-test-coverage report:

No coverage report available ```

@@ -0,0 +1,77 @@
// Copyright 2024 CloudWeGo Authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个怎么不过来找我问一下, 使用统一的格式呀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
使用了 ci 当中给的格式了,我改一下

@kuhahalong kuhahalong force-pushed the feat/tool_ddgsearch branch 2 times, most recently from a27fee7 to 9dabdc5 Compare December 24, 2024 10:03
@@ -0,0 +1,48 @@
module github.com/cloudwego/eino-ext/components/tool/duckduckgo

go 1.21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有必要这么高吗

@kuhahalong kuhahalong merged commit 27d130f into main Dec 26, 2024
4 checks passed
@kuhahalong kuhahalong deleted the feat/tool_ddgsearch branch December 26, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants