refactor: change logic
This commit is contained in:
parent
23e097d87d
commit
a3b25b540e
@ -5,15 +5,14 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func testChannel(channel *model.Channel, request ChatRequest) (err error, openaiErr *OpenAIError) {
|
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 {
|
} else {
|
||||||
if channel.GetBaseURL() != "" {
|
if channel.GetBaseURL() != "" {
|
||||||
requestURL = 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)
|
jsonData, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user