Skip to content

Commit 6c48e0e

Browse files
committed
merge main
1 parent 7f278f3 commit 6c48e0e

File tree

129 files changed

+23694
-5867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+23694
-5867
lines changed

backend/api/handler/coze/loop/apis/eval_target_service.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/api/handler/coze/loop/apis/evaluator_service.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/api/router/coze/loop/apis/coze.loop.apis.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/api/router/coze/loop/apis/middleware.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/cloudwego/eino-ext/components/model/qwen v0.0.0-20250520101807-b2008771903a
3333
github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250519084852-38fafa73d9ea
3434
github.com/cloudwego/gopkg v0.1.4
35-
github.com/cloudwego/hertz v0.9.7
35+
github.com/cloudwego/hertz v0.10.1
3636
github.com/cloudwego/kitex v0.13.1
3737
github.com/coocood/freecache v1.2.4
3838
github.com/coreos/go-semver v0.3.0
@@ -99,6 +99,8 @@ require (
9999

100100
require github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect
101101

102+
require github.com/brianvoe/gofakeit/v6 v6.28.0
103+
102104
require (
103105
cloud.google.com/go v0.116.0 // indirect
104106
cloud.google.com/go/ai v0.8.0 // indirect

backend/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE
150150
github.com/bluele/gcache v0.0.2 h1:WcbfdXICg7G/DGBh1PFfcirkWOQV+v077yF1pSy3DGw=
151151
github.com/bluele/gcache v0.0.2/go.mod h1:m15KV+ECjptwSPxKhOhQoAFQVtUFjTVkc3H8o0t/fp0=
152152
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
153+
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
154+
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
153155
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
154156
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
155157
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
@@ -225,8 +227,8 @@ github.com/cloudwego/frugal v0.2.5 h1:zRICkWpBCQ6TY4QmRf+uINzcHbv7ogCHOM8h7ltPRz
225227
github.com/cloudwego/frugal v0.2.5/go.mod h1:nC1U47gswLRiaxv6dybrhZvsDGCfQP9RGiiWC73CnoI=
226228
github.com/cloudwego/gopkg v0.1.4 h1:EoQiCG4sTonTPHxOGE0VlQs+sQR+Hsi2uN0qqwu8O50=
227229
github.com/cloudwego/gopkg v0.1.4/go.mod h1:FQuXsRWRsSqJLsMVd5SYzp8/Z1y5gXKnVvRrWUOsCMI=
228-
github.com/cloudwego/hertz v0.9.7 h1:tAVaiO+vTf+ZkQhvNhKbDJ0hmC4oJ7bzwDi1KhvhHy4=
229-
github.com/cloudwego/hertz v0.9.7/go.mod h1:t6d7NcoQxPmETvzPMMIVPHMn5C5QzpqIiFsaavoLJYQ=
230+
github.com/cloudwego/hertz v0.10.1 h1:gTM2JIGO7vmRoaDz71GctyoUE19pXGuznFX55HjGs1g=
231+
github.com/cloudwego/hertz v0.10.1/go.mod h1:0sofikwk5YcHCerClgCzcaoamY61JiRwR5G0mAUo+Y0=
230232
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
231233
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
232234
github.com/cloudwego/kitex v0.13.1 h1:oPJS/hy9gvo0rlfQmJAKJj8F4PMLG74IYzpaPlCRgg8=

backend/infra/http/client.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2025 coze-dev Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package http
5+
6+
import (
7+
"bytes"
8+
"context"
9+
"encoding/json"
10+
"fmt"
11+
"io"
12+
"net/http"
13+
"time"
14+
)
15+
16+
// HTTPClient HTTP客户端实现
17+
type HTTPClient struct {
18+
client *http.Client
19+
}
20+
21+
// NewHTTPClient 创建HTTP客户端实例
22+
func NewHTTPClient() IClient {
23+
return &HTTPClient{
24+
client: &http.Client{
25+
Timeout: 30 * time.Second,
26+
},
27+
}
28+
}
29+
30+
// DoHTTPRequest 执行HTTP请求
31+
func (c *HTTPClient) DoHTTPRequest(ctx context.Context, requestParam *RequestParam) error {
32+
if requestParam == nil {
33+
return fmt.Errorf("request param is nil")
34+
}
35+
36+
// 设置超时
37+
if requestParam.Timeout > 0 {
38+
var cancel context.CancelFunc
39+
ctx, cancel = context.WithTimeout(ctx, requestParam.Timeout)
40+
defer cancel()
41+
}
42+
43+
// 序列化请求体
44+
var body io.Reader
45+
if requestParam.Body != nil {
46+
// 如果Body已经是io.Reader类型,直接使用
47+
if reader, ok := requestParam.Body.(io.Reader); ok {
48+
body = reader
49+
} else {
50+
// 否则进行JSON序列化
51+
bodyBytes, err := json.Marshal(requestParam.Body)
52+
if err != nil {
53+
return fmt.Errorf("failed to marshal request body: %w", err)
54+
}
55+
body = bytes.NewReader(bodyBytes)
56+
}
57+
}
58+
59+
// 创建HTTP请求
60+
req, err := http.NewRequestWithContext(ctx, requestParam.Method, requestParam.RequestURI, body)
61+
if err != nil {
62+
return fmt.Errorf("failed to create request: %w", err)
63+
}
64+
65+
// 设置请求头
66+
if requestParam.Header != nil {
67+
for key, value := range requestParam.Header {
68+
req.Header.Set(key, value)
69+
}
70+
}
71+
72+
// 如果没有设置Content-Type且有body,设置为application/json
73+
if requestParam.Body != nil && req.Header.Get("Content-Type") == "" {
74+
// 如果Body是io.Reader类型,默认设置为text/plain
75+
if _, ok := requestParam.Body.(io.Reader); ok {
76+
req.Header.Set("Content-Type", "text/plain")
77+
} else {
78+
req.Header.Set("Content-Type", "application/json")
79+
}
80+
}
81+
82+
// 发送请求
83+
resp, err := c.client.Do(req)
84+
if err != nil {
85+
return fmt.Errorf("failed to send request: %w", err)
86+
}
87+
defer resp.Body.Close()
88+
89+
// 检查HTTP状态码
90+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
91+
bodyBytes, _ := io.ReadAll(resp.Body)
92+
return fmt.Errorf("HTTP request failed with status %d: %s", resp.StatusCode, string(bodyBytes))
93+
}
94+
95+
// 解析响应体
96+
if requestParam.Response != nil {
97+
bodyBytes, err := io.ReadAll(resp.Body)
98+
if err != nil {
99+
return fmt.Errorf("failed to read response body: %w", err)
100+
}
101+
102+
if err := json.Unmarshal(bodyBytes, requestParam.Response); err != nil {
103+
return fmt.Errorf("failed to unmarshal response body: %w", err)
104+
}
105+
}
106+
107+
return nil
108+
}

backend/kitex_gen/coze/loop/apis/evaltargetservice/client.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/kitex_gen/coze/loop/apis/evaltargetservice/evaltargetservice.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/kitex_gen/coze/loop/apis/evaluatorservice/client.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)