Files
new-api/relay/constant/relay_mode.go

125 lines
4.0 KiB
Go
Raw Normal View History

2024-02-29 01:08:18 +08:00
package constant
import (
"net/http"
"strings"
)
2024-02-29 01:08:18 +08:00
const (
RelayModeUnknown = iota
RelayModeChatCompletions
RelayModeCompletions
RelayModeEmbeddings
RelayModeModerations
RelayModeImagesGenerations
RelayModeEdits
2024-07-16 22:07:10 +08:00
2024-02-29 01:08:18 +08:00
RelayModeMidjourneyImagine
RelayModeMidjourneyDescribe
RelayModeMidjourneyBlend
RelayModeMidjourneyChange
RelayModeMidjourneySimpleChange
RelayModeMidjourneyNotify
RelayModeMidjourneyTaskFetch
RelayModeMidjourneyTaskImageSeed
2024-02-29 01:08:18 +08:00
RelayModeMidjourneyTaskFetchByCondition
RelayModeMidjourneyAction
RelayModeMidjourneyModal
2024-03-13 17:46:34 +08:00
RelayModeMidjourneyShorten
2024-03-14 18:08:12 +08:00
RelayModeSwapFace
2024-07-31 15:48:51 +08:00
RelayModeMidjourneyUpload
2024-07-16 22:07:10 +08:00
RelayModeAudioSpeech // tts
RelayModeAudioTranscription // whisper
RelayModeAudioTranslation // whisper
RelayModeSunoFetch
RelayModeSunoFetchByID
RelayModeSunoSubmit
2024-07-16 22:07:10 +08:00
2024-07-06 17:09:22 +08:00
RelayModeRerank
RelayModeRealtime
2024-02-29 01:08:18 +08:00
)
func Path2RelayMode(path string) int {
relayMode := RelayModeUnknown
2024-09-26 00:59:09 +08:00
if strings.HasPrefix(path, "/v1/chat/completions") || strings.HasPrefix(path, "/pg/chat/completions") {
2024-02-29 01:08:18 +08:00
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
2024-07-06 17:09:22 +08:00
} else if strings.HasPrefix(path, "/v1/rerank") {
relayMode = RelayModeRerank
} else if strings.HasPrefix(path, "/v1/realtime") {
relayMode = RelayModeRealtime
2024-02-29 01:08:18 +08:00
}
return relayMode
}
2024-03-13 18:26:16 +08:00
func Path2RelayModeMidjourney(path string) int {
relayMode := RelayModeUnknown
2024-03-29 17:36:44 +08:00
if strings.HasSuffix(path, "/mj/submit/action") {
2024-03-13 18:26:16 +08:00
// midjourney plus
relayMode = RelayModeMidjourneyAction
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/modal") {
2024-03-13 18:26:16 +08:00
// midjourney plus
relayMode = RelayModeMidjourneyModal
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/shorten") {
2024-03-13 18:26:16 +08:00
// midjourney plus
relayMode = RelayModeMidjourneyShorten
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/insight-face/swap") {
2024-03-14 18:08:12 +08:00
// midjourney plus
relayMode = RelayModeSwapFace
2024-07-31 15:48:51 +08:00
} else if strings.HasSuffix(path, "/submit/upload-discord-images") {
// midjourney plus
relayMode = RelayModeMidjourneyUpload
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/imagine") {
2024-03-13 18:26:16 +08:00
relayMode = RelayModeMidjourneyImagine
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/blend") {
2024-03-13 18:26:16 +08:00
relayMode = RelayModeMidjourneyBlend
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/describe") {
2024-03-13 18:26:16 +08:00
relayMode = RelayModeMidjourneyDescribe
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/notify") {
2024-03-13 18:26:16 +08:00
relayMode = RelayModeMidjourneyNotify
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/change") {
2024-03-13 18:26:16 +08:00
relayMode = RelayModeMidjourneyChange
2024-03-29 17:36:44 +08:00
} else if strings.HasSuffix(path, "/mj/submit/simple-change") {
2024-03-13 18:26:16 +08:00
relayMode = RelayModeMidjourneyChange
} else if strings.HasSuffix(path, "/fetch") {
relayMode = RelayModeMidjourneyTaskFetch
} else if strings.HasSuffix(path, "/image-seed") {
relayMode = RelayModeMidjourneyTaskImageSeed
2024-03-13 18:26:16 +08:00
} 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
}