mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-18 00:16:37 +08:00
117 lines
3.7 KiB
Go
117 lines
3.7 KiB
Go
package constant
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
RelayModeUnknown = iota
|
|
RelayModeChatCompletions
|
|
RelayModeCompletions
|
|
RelayModeEmbeddings
|
|
RelayModeModerations
|
|
RelayModeImagesGenerations
|
|
RelayModeEdits
|
|
|
|
RelayModeMidjourneyImagine
|
|
RelayModeMidjourneyDescribe
|
|
RelayModeMidjourneyBlend
|
|
RelayModeMidjourneyChange
|
|
RelayModeMidjourneySimpleChange
|
|
RelayModeMidjourneyNotify
|
|
RelayModeMidjourneyTaskFetch
|
|
RelayModeMidjourneyTaskImageSeed
|
|
RelayModeMidjourneyTaskFetchByCondition
|
|
RelayModeMidjourneyAction
|
|
RelayModeMidjourneyModal
|
|
RelayModeMidjourneyShorten
|
|
RelayModeSwapFace
|
|
|
|
RelayModeAudioSpeech // tts
|
|
RelayModeAudioTranscription // whisper
|
|
RelayModeAudioTranslation // whisper
|
|
|
|
RelayModeSunoFetch
|
|
RelayModeSunoFetchByID
|
|
RelayModeSunoSubmit
|
|
|
|
RelayModeRerank
|
|
)
|
|
|
|
func Path2RelayMode(path string) int {
|
|
relayMode := RelayModeUnknown
|
|
if strings.HasPrefix(path, "/v1/chat/completions") {
|
|
relayMode = RelayModeChatCompletions
|
|
} else if strings.HasPrefix(path, "/v1/completions") {
|
|
relayMode = RelayModeCompletions
|
|
} else if strings.HasPrefix(path, "/v1/embeddings") {
|
|
relayMode = RelayModeEmbeddings
|
|
} else if strings.HasSuffix(path, "embeddings") {
|
|
relayMode = RelayModeEmbeddings
|
|
} else if strings.HasPrefix(path, "/v1/moderations") {
|
|
relayMode = RelayModeModerations
|
|
} else if strings.HasPrefix(path, "/v1/images/generations") {
|
|
relayMode = RelayModeImagesGenerations
|
|
} else if strings.HasPrefix(path, "/v1/edits") {
|
|
relayMode = RelayModeEdits
|
|
} else if strings.HasPrefix(path, "/v1/audio/speech") {
|
|
relayMode = RelayModeAudioSpeech
|
|
} else if strings.HasPrefix(path, "/v1/audio/transcriptions") {
|
|
relayMode = RelayModeAudioTranscription
|
|
} else if strings.HasPrefix(path, "/v1/audio/translations") {
|
|
relayMode = RelayModeAudioTranslation
|
|
} else if strings.HasPrefix(path, "/v1/rerank") {
|
|
relayMode = RelayModeRerank
|
|
}
|
|
return relayMode
|
|
}
|
|
|
|
func Path2RelayModeMidjourney(path string) int {
|
|
relayMode := RelayModeUnknown
|
|
if strings.HasSuffix(path, "/mj/submit/action") {
|
|
// midjourney plus
|
|
relayMode = RelayModeMidjourneyAction
|
|
} else if strings.HasSuffix(path, "/mj/submit/modal") {
|
|
// midjourney plus
|
|
relayMode = RelayModeMidjourneyModal
|
|
} else if strings.HasSuffix(path, "/mj/submit/shorten") {
|
|
// midjourney plus
|
|
relayMode = RelayModeMidjourneyShorten
|
|
} else if strings.HasSuffix(path, "/mj/insight-face/swap") {
|
|
// midjourney plus
|
|
relayMode = RelayModeSwapFace
|
|
} else if strings.HasSuffix(path, "/mj/submit/imagine") {
|
|
relayMode = RelayModeMidjourneyImagine
|
|
} else if strings.HasSuffix(path, "/mj/submit/blend") {
|
|
relayMode = RelayModeMidjourneyBlend
|
|
} else if strings.HasSuffix(path, "/mj/submit/describe") {
|
|
relayMode = RelayModeMidjourneyDescribe
|
|
} else if strings.HasSuffix(path, "/mj/notify") {
|
|
relayMode = RelayModeMidjourneyNotify
|
|
} else if strings.HasSuffix(path, "/mj/submit/change") {
|
|
relayMode = RelayModeMidjourneyChange
|
|
} else if strings.HasSuffix(path, "/mj/submit/simple-change") {
|
|
relayMode = RelayModeMidjourneyChange
|
|
} else if strings.HasSuffix(path, "/fetch") {
|
|
relayMode = RelayModeMidjourneyTaskFetch
|
|
} else if strings.HasSuffix(path, "/image-seed") {
|
|
relayMode = RelayModeMidjourneyTaskImageSeed
|
|
} else if strings.HasSuffix(path, "/list-by-condition") {
|
|
relayMode = RelayModeMidjourneyTaskFetchByCondition
|
|
}
|
|
return relayMode
|
|
}
|
|
|
|
func Path2RelaySuno(method, path string) int {
|
|
relayMode := RelayModeUnknown
|
|
if method == http.MethodPost && strings.HasSuffix(path, "/fetch") {
|
|
relayMode = RelayModeSunoFetch
|
|
} else if method == http.MethodGet && strings.Contains(path, "/fetch/") {
|
|
relayMode = RelayModeSunoFetchByID
|
|
} else if strings.Contains(path, "/submit/") {
|
|
relayMode = RelayModeSunoSubmit
|
|
}
|
|
return relayMode
|
|
}
|