Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/infra/providers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function normalizeBaseUrl(url: string): string {

export function normalizeOpenAIBaseUrl(url: string): string {
let normalized = url.replace(/\/+$/, '');
// Auto-append /v1 if not present (for OpenAI-compatible APIs)
if (!normalized.endsWith('/v1')) {
// Auto-append /v1 if no version path detected (e.g., /v1, /v2, /v4)
if (!/\/v\d+$/.test(normalized)) {
normalized += '/v1';
}
return normalized;
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/providers/openai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ runner
const config = provider.toConfig();
expect.toEqual(config.baseUrl, 'https://api.openai.com/v1');
})
.test('baseUrl 保留已有版本路径 /v4 (GLM coding endpoint)', async () => {
const provider = new OpenAIProvider('test-key', 'any-model', 'https://open.bigmodel.cn/api/coding/paas/v4');
const config = provider.toConfig();
expect.toEqual(config.baseUrl, 'https://open.bigmodel.cn/api/coding/paas/v4');
})
.test('请求体包含 system 与工具调用结构', async () => {
const provider = new OpenAIProvider('test-key', 'gpt-4o', 'https://api.openai.com');
const messages: Message[] = [
Expand Down