mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-15 20:16:02 +00:00
🐛 fix: fix fallback behavior of default mode in AgentRuntime (#4813)
* 🐛 fix: fix fallback behavior of default mode in AgentRuntime * ♻️ refactor: optimize fallback behavior * 🔨 chore: add unit test
This commit is contained in:
@@ -370,6 +370,28 @@ describe('initAgentRuntimeWithUserPayload method', () => {
|
||||
expect(runtime['_runtime']).toBeInstanceOf(LobeWenxinAI);
|
||||
});
|
||||
|
||||
it('OpenAI provider: without apikey with OPENAI_PROXY_URL', async () => {
|
||||
process.env.OPENAI_PROXY_URL = 'https://proxy.example.com/v1';
|
||||
|
||||
const jwtPayload: JWTPayload = {};
|
||||
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.OpenAI, jwtPayload);
|
||||
expect(runtime['_runtime']).toBeInstanceOf(LobeOpenAI);
|
||||
// 应返回 OPENAI_PROXY_URL
|
||||
expect(runtime['_runtime'].baseURL).toBe('https://proxy.example.com/v1');
|
||||
});
|
||||
|
||||
it('Qwen AI provider: without apiKey and endpoint with OPENAI_PROXY_URL', async () => {
|
||||
process.env.OPENAI_PROXY_URL = 'https://proxy.example.com/v1';
|
||||
|
||||
const jwtPayload: JWTPayload = {};
|
||||
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('Unknown Provider', async () => {
|
||||
const jwtPayload = {};
|
||||
const runtime = await initAgentRuntimeWithUserPayload('unknown', jwtPayload);
|
||||
|
||||
@@ -33,7 +33,7 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {
|
||||
default: {
|
||||
let upperProvider = provider.toUpperCase();
|
||||
|
||||
if (!llmConfig[`${upperProvider}_API_KEY`]) {
|
||||
if (!( `${upperProvider}_API_KEY` in llmConfig)) {
|
||||
upperProvider = ModelProvider.OpenAI.toUpperCase(); // Use OpenAI options as default
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user