Skip to content

Commit dfc7005

Browse files
authored
Merge pull request #39 from Gui-Yue/fix/openai-baseurl-version-suffix
fix(openai): preserve non-v1 version suffix in base URL
2 parents 102dd40 + d3aaca7 commit dfc7005

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/infra/providers/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export function normalizeBaseUrl(url: string): string {
5858

5959
export function normalizeOpenAIBaseUrl(url: string): string {
6060
let normalized = url.replace(/\/+$/, '');
61-
// Auto-append /v1 if not present (for OpenAI-compatible APIs)
62-
if (!normalized.endsWith('/v1')) {
61+
// Auto-append /v1 if no version path detected (e.g., /v1, /v2, /v4)
62+
if (!/\/v\d+$/.test(normalized)) {
6363
normalized += '/v1';
6464
}
6565
return normalized;

tests/unit/providers/openai.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ runner
1010
const config = provider.toConfig();
1111
expect.toEqual(config.baseUrl, 'https://api.openai.com/v1');
1212
})
13+
.test('baseUrl 保留已有版本路径 /v4 (GLM coding endpoint)', async () => {
14+
const provider = new OpenAIProvider('test-key', 'any-model', 'https://open.bigmodel.cn/api/coding/paas/v4');
15+
const config = provider.toConfig();
16+
expect.toEqual(config.baseUrl, 'https://open.bigmodel.cn/api/coding/paas/v4');
17+
})
1318
.test('请求体包含 system 与工具调用结构', async () => {
1419
const provider = new OpenAIProvider('test-key', 'gpt-4o', 'https://api.openai.com');
1520
const messages: Message[] = [

0 commit comments

Comments
 (0)