From 49d52a5ffa5e46c135fbd32b7572257912761993 Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Thu, 10 Apr 2025 19:57:25 +0800 Subject: [PATCH] update model options settings --- src/components/chat-view/Chat.tsx | 8 ++- src/settings/SettingTab.tsx | 101 ++++++++++++++++++++++++++---- src/settings/versions/shared.ts | 25 ++++---- 3 files changed, 107 insertions(+), 27 deletions(-) diff --git a/src/components/chat-view/Chat.tsx b/src/components/chat-view/Chat.tsx index d5514c0..29b3161 100644 --- a/src/components/chat-view/Chat.tsx +++ b/src/components/chat-view/Chat.tsx @@ -290,9 +290,13 @@ const Chat = forwardRef((props, ref) => { const stream = await streamResponse( chatModel, { - model: chatModel.modelId, - temperature: 0, messages: requestMessages, + model: chatModel.modelId, + max_tokens: settings.modelOptions.max_tokens, + temperature: settings.modelOptions.temperature, + // top_p: settings.modelOptions.top_p, + // frequency_penalty: settings.modelOptions.frequency_penalty, + // presence_penalty: settings.modelOptions.presence_penalty, stream: true, }, { diff --git a/src/settings/SettingTab.tsx b/src/settings/SettingTab.tsx index d45dd67..f529aae 100644 --- a/src/settings/SettingTab.tsx +++ b/src/settings/SettingTab.tsx @@ -37,6 +37,7 @@ export class InfioSettingTab extends PluginSettingTab { const { containerEl } = this containerEl.empty() this.renderModelsSection(containerEl) + this.renderModelParametersSection(containerEl) this.renderFilesSearchSection(containerEl) this.renderChatBehaviorSection(containerEl) this.renderDeepResearchSection(containerEl) @@ -60,6 +61,90 @@ export class InfioSettingTab extends PluginSettingTab { ); } + private renderModelParametersSection(containerEl: HTMLElement): void { + new Setting(containerEl).setHeading().setName('Model parameters'); + new Setting(containerEl) + .setName('Temperature') + .setDesc('This parameter affects randomness in the sampling. Lower values result in more repetitive and deterministic responses. Higher temperatures will result in more unexpected or creative responses. Default: 0.0, please don\'t change this if you don\'t know what you are doing.') + .addText((text) => { + text + .setValue(String(this.plugin.settings.modelOptions.temperature)) + .onChange(async (value) => { + await this.plugin.setSettings({ + ...this.plugin.settings, + modelOptions: { + ...this.plugin.settings.modelOptions, + temperature: parseFloat(value), + }, + }); + }) + }); + new Setting(containerEl) + .setName('TopP') + .setDesc("Like the temperature parameter, the Top P parameter affects the randomness in sampling. Lowering the value will limit the model's token selection to likelier tokens while increasing the value expands the model's token selection with lower likelihood tokens. Default: 1, please don't change this if you don't know what you are doing.") + .addText((text) => { + text + .setValue(String(this.plugin.settings.modelOptions.top_p)) + .onChange(async (value) => { + await this.plugin.setSettings({ + ...this.plugin.settings, + modelOptions: { + ...this.plugin.settings.modelOptions, + top_p: parseFloat(value), + }, + }); + }) + }); + new Setting(containerEl) + .setName('Frequency penalty') + .setDesc('This parameter reduces the chance of repeating a token proportionally based on how often it has appeared in the text so far. This decreases the likelihood of repeating the exact same text in a response. Default: 0.25') + .addText((text) => { + text + .setValue(String(this.plugin.settings.modelOptions.frequency_penalty)) + .onChange(async (value) => { + await this.plugin.setSettings({ + ...this.plugin.settings, + modelOptions: { + ...this.plugin.settings.modelOptions, + frequency_penalty: parseFloat(value), + }, + }); + }) + }); + new Setting(containerEl) + .setName('Presence penalty') + .setDesc("This parameter reduces the chance of repeating any token that has appeared in the text so far. This increases the likelihood of introducing new topics in a response. Default: 2") + .addText((text) => { + text + .setValue(String(this.plugin.settings.modelOptions.presence_penalty)) + .onChange(async (value) => { + await this.plugin.setSettings({ + ...this.plugin.settings, + modelOptions: { + ...this.plugin.settings.modelOptions, + presence_penalty: parseFloat(value), + }, + }); + }) + }); + new Setting(containerEl) + .setName('Max tokens') + .setDesc("This parameter changes the maximum number of tokens the model is allowed to generate. Default: 4096") + .addText((text) => { + text + .setValue(String(this.plugin.settings.modelOptions.max_tokens)) + .onChange(async (value) => { + await this.plugin.setSettings({ + ...this.plugin.settings, + modelOptions: { + ...this.plugin.settings.modelOptions, + max_tokens: parseInt(value), + }, + }); + }) + }); + } + private renderFilesSearchSection(containerEl: HTMLElement): void { new Setting(containerEl).setHeading().setName('File search') new Setting(containerEl) @@ -95,7 +180,7 @@ export class InfioSettingTab extends PluginSettingTab { } private renderChatBehaviorSection(containerEl: HTMLElement): void { - new Setting(containerEl).setHeading().setName('Chat Behavior'); + new Setting(containerEl).setHeading().setName('Chat behavior'); new Setting(containerEl) .setName('Default mention for new chat') .setDesc('Choose the default file mention behavior when starting a new chat.') @@ -111,7 +196,7 @@ export class InfioSettingTab extends PluginSettingTab { defaultMention: value as 'none' | 'current-file' | 'vault', }); }), - ); + ); } renderModelsSection(containerEl: HTMLElement): void { @@ -151,7 +236,7 @@ export class InfioSettingTab extends PluginSettingTab { } return t; }) - + new Setting(containerEl) .setName('Serper search engine') .setDesc('Choose the search engine to use for web search.') @@ -395,16 +480,6 @@ export class InfioSettingTab extends PluginSettingTab { /> ); - // Model parameters - new Setting(containerEl).setName('Model parameters').setHeading(); - this.renderComponent(containerEl, - - ); - // Preprocessing new Setting(containerEl).setName('Preprocessing').setHeading(); this.renderComponent(containerEl, diff --git a/src/settings/versions/shared.ts b/src/settings/versions/shared.ts index d1b8f1e..e2f539c 100644 --- a/src/settings/versions/shared.ts +++ b/src/settings/versions/shared.ts @@ -6,10 +6,10 @@ export const MIN_MAX_CHAR_LIMIT = 100; export const MAX_MAX_CHAR_LIMIT = 10000; export const MIN_MAX_TOKENS = 128; export const MAX_MAX_TOKENS = 8192; -export const MIN_TEMPERATURE = 0; -export const MAX_TEMPERATURE = 1; -export const MIN_TOP_P = 0; -export const MAX_TOP_P = 1; +export const MIN_TEMPERATURE = 0.0; +export const MAX_TEMPERATURE = 1.0; +export const MIN_TOP_P = 0.0; +export const MAX_TOP_P = 1.0; export const MIN_FREQUENCY_PENALTY = 0; export const MAX_FREQUENCY_PENALTY = 2; export const MIN_PRESENCE_PENALTY = 0; @@ -34,17 +34,18 @@ export const ollamaApiSettingsSchema = z.object({ export const modelOptionsSchema = z.object({ temperature: z.number() - .min(0, { message: `Temperature must be at least ${MIN_TEMPERATURE}` }) - .max(1, { message: `Temperature must be at most ${MAX_TEMPERATURE}` }), + .min(MIN_TEMPERATURE, { message: `Temperature must be at least ${MIN_TEMPERATURE}` }), top_p: z.number() - .min(0, { message: `top_p must be greater than ${MIN_TOP_P}` }) - .max(1, { message: `top_p must be at most ${MAX_TOP_P}` }), + .min(MIN_TOP_P, { message: `top_p must be greater than ${MIN_TOP_P}` }) + .max(MAX_TOP_P, { message: `top_p must be at most ${MAX_TOP_P}` }), frequency_penalty: z.number() - .min(0, { message: `Frequency penalty must be at least ${MIN_FREQUENCY_PENALTY}` }) - .max(2, { message: `Frequency penalty must be at most ${MAX_FREQUENCY_PENALTY}` }), - presence_penalty: z.number().min(MIN_PRESENCE_PENALTY, { message: `Presence penalty must be at least ${MIN_PRESENCE_PENALTY}` }).max(MAX_PRESENCE_PENALTY, { message: `Presence penalty must be at most ${MAX_PRESENCE_PENALTY}` }), + .min(MIN_FREQUENCY_PENALTY, { message: `Frequency penalty must be at least ${MIN_FREQUENCY_PENALTY}` }) + .max(MAX_FREQUENCY_PENALTY, { message: `Frequency penalty must be at most ${MAX_FREQUENCY_PENALTY}` }), + presence_penalty: z.number() + .min(MIN_PRESENCE_PENALTY, { message: `Presence penalty must be at least ${MIN_PRESENCE_PENALTY}` }) + .max(MAX_PRESENCE_PENALTY, { message: `Presence penalty must be at most ${MAX_PRESENCE_PENALTY}` }), max_tokens: z.number().int() - .min(MIN_MAX_TOKENS, { message: `max_tokens must be at least than ${MIN_MAX_TOKENS}` }).max(MAX_MAX_TOKENS, { message: `max_tokens must be at most ${MAX_MAX_TOKENS}` }), + .min(MIN_MAX_TOKENS, { message: `max_tokens must be at least than ${MIN_MAX_TOKENS}` }), }).strict(); export const fewShotExampleSchema = z.object({