mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
🐛 fix(memory-user-memory): should fallback to server configured provider & model (#11643)
This commit is contained in:
@@ -89,8 +89,9 @@ describe('MemoryExtractionExecutor.resolveRuntimeKeyVaults', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when no provider can satisfy an embedding model', () => {
|
||||
it('warns and falls back to server provider when no enabled provider satisfies embedding model', () => {
|
||||
const executor = createExecutor();
|
||||
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
const runtimeState = createRuntimeState(
|
||||
[
|
||||
@@ -106,6 +107,15 @@ describe('MemoryExtractionExecutor.resolveRuntimeKeyVaults', () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(() => (executor as any).resolveRuntimeKeyVaults(runtimeState)).toThrow(/embedding/i);
|
||||
const keyVaults = (executor as any).resolveRuntimeKeyVaults(runtimeState);
|
||||
|
||||
expect(keyVaults).toMatchObject({
|
||||
'provider-b': { apiKey: 'b-key' },
|
||||
'provider-l': { apiKey: 'l-key' },
|
||||
});
|
||||
expect(keyVaults).not.toHaveProperty('provider-e');
|
||||
expect(warnSpy).toHaveBeenCalled();
|
||||
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1660,6 +1660,7 @@ export class MemoryExtractionExecutor {
|
||||
config,
|
||||
]),
|
||||
);
|
||||
|
||||
const providerModels = runtimeState.enabledAiModels.reduce<Record<string, Set<string>>>(
|
||||
(acc, model) => {
|
||||
const providerId = normalizeProvider(model.providerId);
|
||||
@@ -1692,15 +1693,23 @@ export class MemoryExtractionExecutor {
|
||||
for (const providerId of providerOrder) {
|
||||
const models = providerModels[providerId];
|
||||
if (!models) continue;
|
||||
|
||||
if (models.has(modelId)) return providerId;
|
||||
|
||||
const preferredMatch = candidateModels.find((preferredModel) => models.has(preferredModel));
|
||||
if (preferredMatch) return providerId;
|
||||
}
|
||||
if (fallbackProvider) {
|
||||
console.warn(
|
||||
`[memory-extraction] no enabled provider found for ${label || 'model'} "${modelId}"`,
|
||||
`(preferred ${preferredProviders}), falling back to server-configured provider "${fallbackProvider}".`,
|
||||
);
|
||||
|
||||
return normalizeProvider(fallbackProvider);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Unable to resolve provider for ${label || 'model'} "${modelId}". Check preferred providers/models configuration.`,
|
||||
`Unable to resolve provider for ${label || 'model'} "${modelId}". ` +
|
||||
`Check preferred providers/models configuration.`,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user