Model switch (#413)

Add ability to switch models in chat
This commit is contained in:
arkml 2026-03-02 21:42:46 +05:30 committed by GitHub
parent d7dc27a77e
commit 5a72ee06e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 444 additions and 93 deletions

View file

@ -34,6 +34,26 @@ export class FSModelConfigRepo implements IModelConfigRepo {
}
async setConfig(config: z.infer<typeof ModelConfig>): Promise<void> {
await fs.writeFile(this.configPath, JSON.stringify(config, null, 2));
let existingProviders: Record<string, Record<string, unknown>> = {};
try {
const raw = await fs.readFile(this.configPath, "utf8");
const existing = JSON.parse(raw);
existingProviders = existing.providers || {};
} catch {
// No existing config
}
existingProviders[config.provider.flavor] = {
...existingProviders[config.provider.flavor],
apiKey: config.provider.apiKey,
baseURL: config.provider.baseURL,
headers: config.provider.headers,
model: config.model,
models: config.models,
knowledgeGraphModel: config.knowledgeGraphModel,
};
const toWrite = { ...config, providers: existingProviders };
await fs.writeFile(this.configPath, JSON.stringify(toWrite, null, 2));
}
}