mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-13 08:06:06 +00:00
* feat(ai): sync gateway providers and model discovery Add provider account types and protocol-aware model discovery, and replace predefined models with editable model pools. Align provider icons with AI Gateway, preserve international Coding Plan restrictions, and filter account counts consistently with selectable accounts. * fix(ai): preserve Ollama base paths during model discovery * fix(ai): restore custom DashScope image protocol support
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package provider
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func BuildTextRequestURL(apiType, baseURL, model string) string {
|
|
baseURL = strings.TrimRight(strings.TrimSpace(baseURL), "/")
|
|
parsed, err := url.Parse(baseURL)
|
|
if err != nil {
|
|
return baseURL
|
|
}
|
|
path := strings.TrimRight(parsed.Path, "/")
|
|
var endpoint string
|
|
switch apiType {
|
|
case "openai-completions":
|
|
endpoint = "/chat/completions"
|
|
case "openai-responses":
|
|
endpoint = "/responses"
|
|
case "anthropic-messages":
|
|
endpoint = "/messages"
|
|
case "gemini-generate-content":
|
|
if strings.Contains(path, "/models/") && strings.HasSuffix(path, ":generateContent") {
|
|
return parsed.String()
|
|
}
|
|
if !strings.HasSuffix(path, "/v1beta") {
|
|
path += "/v1beta"
|
|
}
|
|
parsed.Path = path + "/models/" + strings.TrimSpace(model) + ":generateContent"
|
|
parsed.RawPath = ""
|
|
return parsed.String()
|
|
default:
|
|
return baseURL
|
|
}
|
|
if strings.HasSuffix(path, endpoint) {
|
|
return parsed.String()
|
|
}
|
|
versioned := false
|
|
for _, segment := range strings.Split(path, "/") {
|
|
if hasAPIVersionSuffix(segment) || segment == "v1beta" {
|
|
versioned = true
|
|
break
|
|
}
|
|
}
|
|
if (apiType == "anthropic-messages" && !strings.HasSuffix(path, "/v1")) || (apiType != "anthropic-messages" && !versioned) {
|
|
path += "/v1"
|
|
}
|
|
parsed.Path = path + endpoint
|
|
parsed.RawPath = ""
|
|
return parsed.String()
|
|
}
|