♻️ 重构 LLM 服务实例管理,移除实例缓存机制

- 删除 OpenAI 实例的内部缓存映射
- 移除 `getOpenAIInstance` 方法中的缓存逻辑
- 简化 LLM 服务实例创建流程
- 确保每次调用都创建新的 OpenAI 实例
This commit is contained in:
linshen committed 2025-03-03 00:37:57 +08:00
1 parent bf9d98eb69
commit 3bc66401ea
1 file changed
-8
@@ -10,8 +10,6 @@ import { isVercel, getProxyUrl } from '../../utils/environment';
* LLM服务实现 - 基于官方SDK
*/
export class LLMService implements ILLMService {
private openAIInstances: Map<string, OpenAI> = new Map();
constructor(private modelManager: ModelManager) {}
/**
@@ -62,11 +60,6 @@ export class LLMService implements ILLMService {
* 获取OpenAI实例
*/
private getOpenAIInstance(modelConfig: ModelConfig, isStream: boolean = false): OpenAI {
const cacheKey = `${modelConfig.provider}-${modelConfig.defaultModel}-${isStream ? 'stream' : 'normal'}`;
if (this.openAIInstances.has(cacheKey)) {
return this.openAIInstances.get(cacheKey)!;
}
const apiKey = modelConfig.apiKey || '';
@@ -100,7 +93,6 @@ export class LLMService implements ILLMService {
const instance = new OpenAI(config);
this.openAIInstances.set(cacheKey, instance);
return instance;
}