From a3b25b540e1dcf224268436617a01b1c8314fd66 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 5 Nov 2023 19:07:33 +0800 Subject: [PATCH] refactor: change logic --- controller/channel-test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index 1950ac51..3c6c8f43 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -5,15 +5,14 @@ import ( "encoding/json" "errors" "fmt" + "github.com/gin-gonic/gin" "net/http" "one-api/common" "one-api/model" "strconv" + "strings" "sync" "time" - "strings" - - "github.com/gin-gonic/gin" ) func testChannel(channel *model.Channel, request ChatRequest) (err error, openaiErr *OpenAIError) { @@ -48,12 +47,11 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai } else { if channel.GetBaseURL() != "" { requestURL = channel.GetBaseURL() - if !strings.HasPrefix(requestURL, "https://gateway.ai.cloudflare.com") { - requestURL += "/v1" - } } - requestURL += "/chat/completions" + requestURL += "/v1/chat/completions" } + // for Cloudflare AI gateway: https://github.com/songquanpeng/one-api/pull/639 + requestURL = strings.Replace(requestURL, "/v1/v1", "/v1", 1) jsonData, err := json.Marshal(request) if err != nil {