Skip to content

Commit

Permalink
bring smart chat settings up to date with new SmartEnvSettings structure
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpetro committed Aug 24, 2024
1 parent ada3e4a commit 73c3384
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/chat/smart_chat_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { SmartSettings } from "smart-setting";
export class SmartChatSettings extends SmartSettings {
update_smart_chat_folder() { this.plugin.update_smart_chat_folder(); }
async changed_smart_chat_model(render = true){
console.log(this.plugin.settings.chat_model_platform_key);
await this.plugin.save_settings();
this.plugin.env.chat_model = null;
this.plugin.env.init_chat_model(this.plugin.settings.chat_model_platform_key);
const platform_config = this.plugin.env.chat_model.platforms[this.plugin.settings.chat_model_platform_key];
let smart_chat_model_config = this.plugin.settings[this.plugin.settings.chat_model_platform_key] || {};
console.log(this.env.settings.chat_model_platform_key);
// await this.plugin.save_settings();
this.env.chat_model = null;
this.env.init_chat_model(this.env.settings.chat_model_platform_key);
const platform_config = this.env.chat_model.platforms[this.env.settings.chat_model_platform_key];
let smart_chat_model_config = this.env.settings[this.env.settings.chat_model_platform_key] || {};
if(smart_chat_model_config.model_name){
const platform_models = await this.plugin.env.chat_model.get_models();
const platform_models = await this.env.chat_model.get_models();
const model_config = platform_models.find(m => m.model_name === smart_chat_model_config.model_name);
// console.log("model_config", model_config);
smart_chat_model_config = {
Expand All @@ -21,26 +21,26 @@ export class SmartChatSettings extends SmartSettings {
...(model_config || {}),
};
// console.log("smart_chat_model_config", smart_chat_model_config);
this.plugin.settings[this.plugin.settings.chat_model_platform_key] = smart_chat_model_config;
this.env.settings[this.env.settings.chat_model_platform_key] = smart_chat_model_config;
}
await this.plugin.save_settings();
// await this.plugin.save_settings();
if(render) this.render();
}
async test_chat_api_key(){
await this.changed_smart_chat_model();
const resp = await this.plugin.env.chat_model.test_api_key();
const resp = await this.env.chat_model.test_api_key();
if(resp) return this.plugin.notices.show('api key test pass', "Success! API key is valid");
this.plugin.notices.show('api key test fail', "Error: API key is invalid!");
}
get self_ref_list() { return "Current: " + ScTranslations[this.config.language].pronouns.join(", "); }
get template() { return this.templates['smart_chat_settings']; }
async get_view_data() {
const view_data = {
settings: this.plugin.settings,
chat_platform: this.env.chat_model?.platforms[this.plugin.settings.chat_model_platform_key],
settings: this.env.settings,
chat_platform: this.env.chat_model?.platforms[this.env.settings.chat_model_platform_key],
chat_platforms: this.env.chat_model?.platforms ? Object.keys(this.env.chat_model.platforms).map(platform_key => ({ key: platform_key, ...(this.env.chat_model?.platforms[platform_key] || {}) })) : [],
};
view_data.platform_chat_models = await this.plugin.env.chat_model?.get_models();
view_data.platform_chat_models = await this.env.chat_model?.get_models();
view_data.smart_chat_settings = this.ejs.render(this.template, view_data);
return view_data;
}
Expand Down

0 comments on commit 73c3384

Please sign in to comment.