32 lines
1.5 KiB
Go
32 lines
1.5 KiB
Go
|
|
package modeladapter
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
// 与拉取端 buildModelsEndpoint 的形态矩阵保持对称:
|
||
|
|
// 聊天调用对 baseURL 带或不带 /v1 应当同样收敛到正确端点。
|
||
|
|
func TestOpenAIEndpointURLResolvesBaseURLShapes(t *testing.T) {
|
||
|
|
cases := []struct {
|
||
|
|
name string
|
||
|
|
baseURL string
|
||
|
|
endpoint string
|
||
|
|
want string
|
||
|
|
}{
|
||
|
|
{"裸 host 追加完整端点", "https://example.com", "/v1/responses", "https://example.com/v1/responses"},
|
||
|
|
{"裸 host 追加 chat completions", "https://example.com", "/v1/chat/completions", "https://example.com/v1/chat/completions"},
|
||
|
|
{"base 以 /v1 结尾时去重拼接", "https://example.com/v1", "/v1/chat/completions", "https://example.com/v1/chat/completions"},
|
||
|
|
{"base 以 /v1 结尾时不重复 /v1", "https://example.com/v1/", "/v1/responses", "https://example.com/v1/responses"},
|
||
|
|
{"base 内嵌 chat completions 时直用", "https://example.com/v1/chat/completions", "/v1/responses", "https://example.com/v1/chat/completions"},
|
||
|
|
{"base 内嵌 responses 时直用", "https://example.com/v1/responses", "/v1/chat/completions", "https://example.com/v1/responses"},
|
||
|
|
{"endpoint 为空时回退默认 responses", "https://example.com", "", "https://example.com/v1/responses"},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tc := range cases {
|
||
|
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
|
if got := OpenAIEndpointURL(tc.baseURL, tc.endpoint); got != tc.want {
|
||
|
|
t.Fatalf("OpenAIEndpointURL(%q, %q) = %q, 期望 %q", tc.baseURL, tc.endpoint, got, tc.want)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|