mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-16 21:23:44 +08:00
🔖 chore: Remove invalid code
This commit is contained in:
@@ -28,7 +28,7 @@ type AzureSpeechProvider struct {
|
||||
base.BaseProvider
|
||||
}
|
||||
|
||||
func (p *AzureSpeechProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *AzureSpeechProvider) GetFullRequestURL(requestURL string) string {
|
||||
baseURL := ""
|
||||
if p.Channel.Other != "" {
|
||||
baseURL = fmt.Sprintf("https://%s.tts.speech.microsoft.com", p.Channel.Other)
|
||||
|
||||
@@ -87,7 +87,7 @@ func (p *AzureSpeechProvider) CreateSpeech(request *types.SpeechAudioRequest) (*
|
||||
if errWithCode != nil {
|
||||
return nil, errWithCode
|
||||
}
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
headers := p.GetRequestHeaders()
|
||||
responseFormatr := outputFormatMap[request.ResponseFormat]
|
||||
if responseFormatr == "" {
|
||||
|
||||
@@ -210,7 +210,7 @@ func (h *baiduStreamHandler) handlerStream(rawLine *[]byte, dataChan chan string
|
||||
return
|
||||
}
|
||||
|
||||
h.convertToOpenaiStream(&baiduResponse, dataChan, errChan)
|
||||
h.convertToOpenaiStream(&baiduResponse, dataChan)
|
||||
|
||||
if baiduResponse.IsEnd {
|
||||
errChan <- io.EOF
|
||||
@@ -219,7 +219,7 @@ func (h *baiduStreamHandler) handlerStream(rawLine *[]byte, dataChan chan string
|
||||
}
|
||||
}
|
||||
|
||||
func (h *baiduStreamHandler) convertToOpenaiStream(baiduResponse *BaiduChatStreamResponse, dataChan chan string, errChan chan error) {
|
||||
func (h *baiduStreamHandler) convertToOpenaiStream(baiduResponse *BaiduChatStreamResponse, dataChan chan string) {
|
||||
choice := types.ChatCompletionStreamChoice{
|
||||
Index: 0,
|
||||
Delta: types.ChatCompletionStreamChoiceDelta{
|
||||
|
||||
@@ -48,7 +48,7 @@ func (p *BaseProvider) GetBaseURL() string {
|
||||
}
|
||||
|
||||
// 获取完整请求URL
|
||||
func (p *BaseProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *BaseProvider) GetFullRequestURL(requestURL string, _ string) string {
|
||||
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")
|
||||
|
||||
return fmt.Sprintf("%s%s", baseURL, requestURL)
|
||||
|
||||
@@ -58,10 +58,6 @@ var requiredHeaders = map[string]struct{}{
|
||||
"X-Amz-Tagging": {},
|
||||
}
|
||||
|
||||
// headerPredicate is a function that evaluates whether a header is of the
|
||||
// specific type. For example, whether a header should be ignored during signing.
|
||||
type headerPredicate func(header string) bool
|
||||
|
||||
// isIgnoredHeader returns true if header must be ignored during signing.
|
||||
func isIgnoredHeader(header string) bool {
|
||||
_, ok := ignoreHeaders[header]
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -47,17 +46,6 @@ func hasPrefixFold(s, prefix string) bool {
|
||||
strings.EqualFold(s[0:len(prefix)], prefix)
|
||||
}
|
||||
|
||||
// isSameDay returns true if a and b are the same date (dd-mm-yyyy).
|
||||
func isSameDay(a, b time.Time) bool {
|
||||
xYear, xMonth, xDay := a.Date()
|
||||
yYear, yMonth, yDay := b.Date()
|
||||
|
||||
if xYear != yYear || xMonth != yMonth {
|
||||
return false
|
||||
}
|
||||
return xDay == yDay
|
||||
}
|
||||
|
||||
// hostOrURLHost returns r.Host, or if empty, r.URL.Host.
|
||||
func hostOrURLHost(r *http.Request) string {
|
||||
if r.Host != "" {
|
||||
@@ -271,32 +259,3 @@ func writeCanonicalString(w *bufio.Writer, s string) {
|
||||
w.WriteByte(s[i])
|
||||
}
|
||||
}
|
||||
|
||||
type debugHasher struct {
|
||||
buf []byte
|
||||
}
|
||||
|
||||
func (dh *debugHasher) Write(b []byte) (int, error) {
|
||||
dh.buf = append(dh.buf, b...)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func (dh *debugHasher) Sum(b []byte) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dh *debugHasher) Reset() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (dh *debugHasher) Size() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (dh *debugHasher) BlockSize() int {
|
||||
return sha256.BlockSize
|
||||
}
|
||||
|
||||
func (dh *debugHasher) Println() {
|
||||
fmt.Printf("---%s---\n", dh.buf)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (p *ClaudeProvider) GetRequestHeaders() (headers map[string]string) {
|
||||
return headers
|
||||
}
|
||||
|
||||
func (p *ClaudeProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *ClaudeProvider) GetFullRequestURL(requestURL string) string {
|
||||
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")
|
||||
if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
|
||||
requestURL = strings.TrimPrefix(requestURL, "/v1")
|
||||
|
||||
@@ -71,7 +71,7 @@ func (p *ClaudeProvider) getChatRequest(request *types.ChatCompletionRequest) (*
|
||||
}
|
||||
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(nil, "invalid_claude_config", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func hmacsha256(s, key string) string {
|
||||
func (p *HunyuanProvider) sign(body any, action, method string) (*http.Request, *types.OpenAIErrorWithStatusCode) {
|
||||
service := "hunyuan"
|
||||
version := "2023-09-01"
|
||||
region := ""
|
||||
// region := ""
|
||||
host := strings.Replace(p.GetBaseURL(), "https://", "", 1)
|
||||
algorithm := "TC3-HMAC-SHA256"
|
||||
var timestamp = time.Now().Unix()
|
||||
@@ -88,9 +88,9 @@ func (p *HunyuanProvider) sign(body any, action, method string) (*http.Request,
|
||||
"Content-Type": contentType,
|
||||
"Authorization": authorization,
|
||||
}
|
||||
if region != "" {
|
||||
headers["X-TC-Region"] = region
|
||||
}
|
||||
// if region != "" {
|
||||
// headers["X-TC-Region"] = region
|
||||
// }
|
||||
|
||||
req, err := p.Requester.NewRequest(method, p.GetBaseURL(), p.Requester.WithBody(body), p.Requester.WithHeader(headers))
|
||||
if err != nil {
|
||||
|
||||
@@ -49,21 +49,3 @@ const (
|
||||
MjActionPan = "PAN"
|
||||
MjActionSwapFace = "SWAP_FACE"
|
||||
)
|
||||
|
||||
var MidjourneyModel2Action = map[string]string{
|
||||
"mj_imagine": MjActionImagine,
|
||||
"mj_describe": MjActionDescribe,
|
||||
"mj_blend": MjActionBlend,
|
||||
"mj_upscale": MjActionUpscale,
|
||||
"mj_variation": MjActionVariation,
|
||||
"mj_reroll": MjActionReRoll,
|
||||
"mj_modal": MjActionModal,
|
||||
"mj_inpaint": MjActionInPaint,
|
||||
"mj_zoom": MjActionZoom,
|
||||
"mj_custom_zoom": MjActionCustomZoom,
|
||||
"mj_shorten": MjActionShorten,
|
||||
"mj_high_variation": MjActionHighVariation,
|
||||
"mj_low_variation": MjActionLowVariation,
|
||||
"mj_pan": MjActionPan,
|
||||
"swap_face": MjActionSwapFace,
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func errorHandle(minimaxError *BaseResp) *types.OpenAIError {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *MiniMaxProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *MiniMaxProvider) GetFullRequestURL(requestURL string) string {
|
||||
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")
|
||||
keys := strings.Split(p.Channel.Key, "|")
|
||||
if len(keys) != 2 {
|
||||
|
||||
@@ -62,7 +62,7 @@ func (p *MiniMaxProvider) getChatRequest(request *types.ChatCompletionRequest) (
|
||||
}
|
||||
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(errors.New("API KEY is filled in incorrectly"), "invalid_minimax_config", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func (p *MiniMaxProvider) CreateEmbeddings(request *types.EmbeddingRequest) (*ty
|
||||
return nil, errWithCode
|
||||
}
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(nil, "invalid_minimax_config", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func getTextContent(text, format string) string {
|
||||
func extractTextFromVTT(vttContent string) string {
|
||||
scanner := bufio.NewScanner(strings.NewReader(vttContent))
|
||||
re := regexp.MustCompile(`\d{2}:\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}:\d{2}\.\d{3}`)
|
||||
text := []string{}
|
||||
var text []string
|
||||
isStart := true
|
||||
|
||||
for scanner.Scan() {
|
||||
@@ -185,7 +185,7 @@ func extractTextFromVTT(vttContent string) string {
|
||||
func extractTextFromSRT(srtContent string) string {
|
||||
scanner := bufio.NewScanner(strings.NewReader(srtContent))
|
||||
re := regexp.MustCompile(`\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}`)
|
||||
text := []string{}
|
||||
var text []string
|
||||
isContent := false
|
||||
|
||||
for scanner.Scan() {
|
||||
|
||||
@@ -69,7 +69,7 @@ func (p *PalmProvider) GetRequestHeaders() (headers map[string]string) {
|
||||
}
|
||||
|
||||
// 获取完整请求 URL
|
||||
func (p *PalmProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *PalmProvider) GetFullRequestURL(requestURL string) string {
|
||||
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")
|
||||
|
||||
return fmt.Sprintf("%s%s", baseURL, requestURL)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (p *PalmProvider) getChatRequest(request *types.ChatCompletionRequest) (*ht
|
||||
return nil, errWithCode
|
||||
}
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(nil, "invalid_palm_config", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (p *XunfeiProvider) GetRequestHeaders() (headers map[string]string) {
|
||||
}
|
||||
|
||||
// 获取完整请求 URL
|
||||
func (p *XunfeiProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *XunfeiProvider) GetFullRequestURL(modelName string) string {
|
||||
splits := strings.Split(p.Channel.Key, "|")
|
||||
if len(splits) != 3 {
|
||||
return ""
|
||||
|
||||
@@ -60,12 +60,12 @@ func (p *XunfeiProvider) CreateChatCompletionStream(request *types.ChatCompletio
|
||||
}
|
||||
|
||||
func (p *XunfeiProvider) getChatRequest(request *types.ChatCompletionRequest) (*websocket.Conn, *types.OpenAIErrorWithStatusCode) {
|
||||
url, errWithCode := p.GetSupportedAPIUri(config.RelayModeChatCompletions)
|
||||
_, errWithCode := p.GetSupportedAPIUri(config.RelayModeChatCompletions)
|
||||
if errWithCode != nil {
|
||||
return nil, errWithCode
|
||||
}
|
||||
|
||||
authUrl := p.GetFullRequestURL(url, request.Model)
|
||||
authUrl := p.GetFullRequestURL(request.Model)
|
||||
|
||||
wsConn, err := p.wsRequester.NewRequest(authUrl, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -77,7 +77,7 @@ func (p *ZhipuProvider) GetRequestHeaders() (headers map[string]string) {
|
||||
}
|
||||
|
||||
// 获取完整请求 URL
|
||||
func (p *ZhipuProvider) GetFullRequestURL(requestURL string, modelName string) string {
|
||||
func (p *ZhipuProvider) GetFullRequestURL(requestURL string) string {
|
||||
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")
|
||||
|
||||
return fmt.Sprintf("%s%s", baseURL, requestURL)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (p *ZhipuProvider) getChatRequest(request *types.ChatCompletionRequest) (*h
|
||||
}
|
||||
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(nil, "invalid_zhipu_config", http.StatusInternalServerError)
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (p *ZhipuProvider) convertToChatOpenai(response *ZhipuResponse, request *ty
|
||||
}
|
||||
|
||||
if len(openaiResponse.Choices) > 0 && openaiResponse.Choices[0].Message.ToolCalls != nil && request.Functions != nil {
|
||||
for i, _ := range openaiResponse.Choices {
|
||||
for i := range openaiResponse.Choices {
|
||||
openaiResponse.Choices[i].CheckChoice(request)
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func (p *ZhipuProvider) convertToChatOpenai(response *ZhipuResponse, request *ty
|
||||
|
||||
func (p *ZhipuProvider) convertFromChatOpenai(request *types.ChatCompletionRequest) *ZhipuRequest {
|
||||
request.ClearEmptyMessages()
|
||||
for i, _ := range request.Messages {
|
||||
for i := range request.Messages {
|
||||
request.Messages[i].Role = convertRole(request.Messages[i].Role)
|
||||
if request.Messages[i].FunctionCall != nil {
|
||||
request.Messages[i].FuncToToolCalls()
|
||||
|
||||
@@ -13,7 +13,7 @@ func (p *ZhipuProvider) CreateEmbeddings(request *types.EmbeddingRequest) (*type
|
||||
return nil, errWithCode
|
||||
}
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(nil, "invalid_zhipu_config", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func (p *ZhipuProvider) CreateImageGenerations(request *types.ImageRequest) (*ty
|
||||
return nil, errWithCode
|
||||
}
|
||||
// 获取请求地址
|
||||
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
||||
fullRequestURL := p.GetFullRequestURL(url)
|
||||
if fullRequestURL == "" {
|
||||
return nil, common.ErrorWrapper(nil, "invalid_zhipu_config", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user