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: [tool/httprequest] add httprequest tool #147

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

maiconjobim
Copy link

What type of PR is this?

feat: add request tool

Check the PR title.

Title: feat: [tool/request] add request tool

  • 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

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
This PR implements a new Request Tool for the Eino framework. Inspired by LangChain's Requests integration (see LangChain Requests Tool), this tool provides a simple and consistent interface for performing HTTP GET and POST operations. It supports configurable headers, timeouts, and response content types (either JSON or text), making it easy for developers to integrate external web APIs into their Eino-based applications. By following the design principles of LangChain, this tool offers a familiar experience to developers and extends the overall capabilities of the Eino tool ecosystem.

zh (optional):
此 PR 为 Eino 框架实现了一个全新的 Request 工具。该工具受 LangChain 的 Requests 集成启发(参见 LangChain Requests Tool),提供了一个简单且一致的接口,用于执行 HTTP GET 和 POST 操作。它支持可配置的请求头、超时以及响应内容类型(JSON 或纯文本),从而使开发人员能够轻松地将外部 Web API 集成到基于 Eino 的应用中。该工具遵循 LangChain 的设计原则,为开发人员提供了熟悉的使用体验,并扩展了 Eino 工具生态系统的整体功能。

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@CLAassistant
Copy link

CLAassistant commented Mar 6, 2025

CLA assistant check
All committers have signed the CLA.

@maiconjobim maiconjobim force-pushed the feat/mj-add-request-tool branch from dc1cc5d to dfb1bd3 Compare March 6, 2025 17:51
@meguminnnnnnnnn meguminnnnnnnnn self-assigned this Mar 7, 2025
@@ -0,0 +1,357 @@
# HTTP Request Tools
Copy link
Contributor

Choose a reason for hiding this comment

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

The core of this tool should be HTTP, and the package name request doesn't feel quite right. Should it be called http or httprequest?

Timeout: conf.Timeout,
ResponseContentType: conf.ResponseContentType,
}
getTool, err := get.NewTool(ctx, getConf)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think including PUT and DELETE is better, as they are commonly used in RESTful applications.

}

func (c *Config) validate() error {
if c.ToolName == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Write a comment to explain that it is sourced from LangChain.


var content interface{}
if r.config.ResponseContentType == "json" {
if err := sonic.Unmarshal(body, &content); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deserialize and then serialize here? Unlike LangChain, this tool always outputs a string, so is this field unnecessary?


type Config struct {
Headers map[string]string `json:"headers"`
Timeout time.Duration `json:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide the HTTP client directly instead of just the timeout.

}
getTool, err := get.NewTool(ctx, getConf)
if err != nil {
return nil, fmt.Errorf("erro ao criar ferramenta GET: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

use english please~

Copy link
Author

Choose a reason for hiding this comment

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

You're right! Sorry, I let that slip, but I've already fixed it.
I also implemented the tool for PUT and DELETE requests.

@maiconjobim maiconjobim changed the title feat: [tool/request] add request tool feat: [tool/httprequest] add httprequest tool Mar 7, 2025
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.

3 participants