mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-19 04:27:02 +08:00
feat: add support for custom OpenAI endpoint path
- Introduced a new endpoint option for OpenAI integrations, allowing users to specify a custom path. - Updated relevant components and validation logic to accommodate the new endpoint. - Enhanced documentation and error messages to reflect the addition of the custom endpoint option.
This commit is contained in:
@@ -13,6 +13,7 @@ const ChannelIDHexLength = 16
|
||||
const (
|
||||
OpenAIEndpointResponses = "/v1/responses"
|
||||
OpenAIEndpointChatCompletions = "/v1/chat/completions"
|
||||
OpenAIEndpointCustom = "/custom"
|
||||
)
|
||||
|
||||
func NormalizeBaseURL(raw string) (string, error) {
|
||||
@@ -39,20 +40,37 @@ func NormalizeBaseURL(raw string) (string, error) {
|
||||
return normalized, nil
|
||||
}
|
||||
|
||||
// NormalizeOpenAIEndpoint 归一化 OpenAI endpoint 路径。
|
||||
// 支持三个预设值:/v1/responses、/v1/chat/completions、/custom(自定义路径)。
|
||||
// 选 /custom 时,用户需在接口地址栏填写完整请求 URL。
|
||||
func NormalizeOpenAIEndpoint(providerType string, endpoint string) string {
|
||||
if strings.TrimSpace(strings.ToLower(providerType)) != "openai" {
|
||||
return ""
|
||||
}
|
||||
switch strings.ToLower(strings.TrimSpace(endpoint)) {
|
||||
case "", OpenAIEndpointResponses:
|
||||
normalized := strings.TrimSpace(endpoint)
|
||||
switch normalized {
|
||||
case "":
|
||||
return OpenAIEndpointResponses
|
||||
case OpenAIEndpointChatCompletions:
|
||||
return OpenAIEndpointChatCompletions
|
||||
case OpenAIEndpointResponses, OpenAIEndpointChatCompletions, OpenAIEndpointCustom:
|
||||
return normalized
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAIEndpointShape 根据 endpoint 路径末段推断协议形态。
|
||||
// 返回 "responses"(Responses API)或 "chat/completions"(Chat Completions API)。
|
||||
// 这样 /v1/chat/completions、/v4/chat/completions、/chat/completions 都走同一协议分支。
|
||||
func OpenAIEndpointShape(endpoint string) string {
|
||||
lower := strings.ToLower(strings.TrimSpace(endpoint))
|
||||
switch {
|
||||
case strings.HasSuffix(lower, "/responses"):
|
||||
return "responses"
|
||||
default:
|
||||
return "chat/completions"
|
||||
}
|
||||
}
|
||||
|
||||
func BuildLegacyChannelID(baseURL string, modelID string, apiKey string, name string) string {
|
||||
return buildChannelID([]string{
|
||||
strings.TrimSpace(baseURL),
|
||||
|
||||
Reference in New Issue
Block a user