From 253c6d93ec106d7964d9650e65d728120842ad07 Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Sun, 13 Jul 2025 09:46:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(proxy):=20=E5=A4=8D=E7=94=A8client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/proxy/proxy.go | 14 ++++++++++++-- backend/pkg/request/ops.go | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/internal/proxy/proxy.go b/backend/internal/proxy/proxy.go index c0a24e5..0e61c3b 100644 --- a/backend/internal/proxy/proxy.go +++ b/backend/internal/proxy/proxy.go @@ -442,7 +442,12 @@ func (p *LLMProxy) handleCompletion(ctx context.Context, w http.ResponseWriter, startTime := time.Now() - client := request.NewClient(u.Scheme, u.Host, 30*time.Second) + client := request.NewClient( + u.Scheme, + u.Host, + 30*time.Second, + request.WithClient(p.client), + ) client.SetDebug(p.cfg.Debug) resp, err := request.Post[openai.CompletionResponse](client, u.Path, req, request.WithHeader(request.Header{ "Authorization": "Bearer " + m.APIKey, @@ -753,7 +758,12 @@ func (p *LLMProxy) handleChatCompletion(ctx context.Context, w http.ResponseWrit mode := req.Metadata["mode"] taskID := req.Metadata["task_id"] - client := request.NewClient(u.Scheme, u.Host, 30*time.Second) + client := request.NewClient( + u.Scheme, + u.Host, + 30*time.Second, + request.WithClient(p.client), + ) resp, err := request.Post[openai.ChatCompletionResponse](client, u.Path, req, request.WithHeader(request.Header{ "Authorization": "Bearer " + m.APIKey, })) diff --git a/backend/pkg/request/ops.go b/backend/pkg/request/ops.go index 9a5930e..08ea7b4 100644 --- a/backend/pkg/request/ops.go +++ b/backend/pkg/request/ops.go @@ -12,6 +12,12 @@ func WithDebug() ReqOpt { } } +func WithClient(client *http.Client) ReqOpt { + return func(c *Client) { + c.client = client + } +} + func WithTransport(tr *http.Transport) ReqOpt { return func(c *Client) { c.tr = tr