Skip to content

Commit

Permalink
🐛 fix: fix Qwen baseUrl calling (lobehub#4799)
Browse files Browse the repository at this point in the history
* 🐛 fix: fix Qwen baseUrl calling

* ♻️ refactor: refactor baseURL import logic

* 🔨 chore: rollback changes

* 🔨 chore: add unit test
  • Loading branch information
hezhijie0327 authored Nov 26, 2024
1 parent 66c820b commit 8fd7eb7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/server/modules/AgentRuntime/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ describe('initAgentRuntimeWithUserPayload method', () => {
expect(runtime['_runtime']).toBeInstanceOf(LobeQwenAI);
});

it('Qwen AI provider: without endpoint', async () => {
const jwtPayload: JWTPayload = { apiKey: 'user-qwen-key' };
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.Qwen, jwtPayload);

// 假设 LobeQwenAI 是 Qwen 提供者的实现类
expect(runtime['_runtime']).toBeInstanceOf(LobeQwenAI);
// endpoint 不存在,应返回 DEFAULT_BASE_URL
expect(runtime['_runtime'].baseURL).toBe('https://dashscope.aliyuncs.com/compatible-mode/v1');
});

it('Bedrock AI provider: without apikey', async () => {
const jwtPayload = {};
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.Bedrock, jwtPayload);
Expand Down
2 changes: 1 addition & 1 deletion src/server/modules/AgentRuntime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {
const apiKey = apiKeyManager.pick(payload?.apiKey || llmConfig[`${upperProvider}_API_KEY`]);
const baseURL = payload?.endpoint || process.env[`${upperProvider}_PROXY_URL`];

return { apiKey, baseURL };
return baseURL ? { apiKey, baseURL } : { apiKey };
}

case ModelProvider.Azure: {
Expand Down

0 comments on commit 8fd7eb7

Please sign in to comment.