Add extra parameters support for OpenAI compatible providers

This commit is contained in:
el95149 2026-04-09 13:01:18 +03:00
parent 41288c0f62
commit 34a9cce909
4 changed files with 28 additions and 2 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "obsidian-inscribe",
"version": "1.1.5",
"version": "1.2.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "obsidian-inscribe",
"version": "1.1.5",
"version": "1.2.0",
"license": "MIT",
"dependencies": {
"@google/genai": "^1.41.0",

View file

@ -32,6 +32,7 @@ export class OpenAICompatibleProvider implements Provider {
],
temperature: options.temperature,
stream: true,
...options.extraParams,
}, { signal: this.abortcontroller.signal });
let completion = "";

View file

@ -12,6 +12,7 @@ export interface ProfileOptions {
userPrompt: string,
systemPrompt: string,
temperature: number,
extraParams: Record<string, unknown>,
}
// Profile settings
@ -142,6 +143,7 @@ export const DEFAULT_SETTINGS: Settings = {
userPrompt: 'If the last sentence is incomplete, only complete the sentence and nothing else. If the last sentence is complete, generate a new sentence that follows logically:\n---\n{{{pre_cursor}}}',
systemPrompt: "You are a writing assistant that predicts and completes sentences in a natural, context-aware manner. Your goal is to continue the users text smoothly, maintaining coherence, fluency, and style. Adapt to the users writing tone, whether formal, informal, creative, or technical. Ensure that completions feel intuitive, useful, and free of unnecessary repetition. Do not generate completion that includes the prompt itself.",
temperature: 0.5,
extraParams: {},
}
},
},

View file

@ -495,6 +495,29 @@ class ProfilesSection {
});
});
// Extra Parameters
new Setting(this.container)
.setName("Extra parameters")
.setDesc(`${profile.name} | Only applicable to OpenAI-compatible providers. Additional parameters passed to the API (JSON format). Example: {"chat_template_kwargs": {"enable_thinking": false}}`)
.addTextArea((text) => {
text.inputEl.rows = 5;
text.setValue(JSON.stringify(profile.completionOptions.extraParams, null, 2))
.setPlaceholder("{}")
.onChange(async (value) => {
try {
const params = value.trim() ? JSON.parse(value) : {};
if (typeof params === 'object' && params !== null && !Array.isArray(params)) {
profile.completionOptions.extraParams = params;
await this.plugin.saveSettings();
} else {
new Notice("Extra parameters must be a valid JSON object");
}
} catch (e) {
new Notice("Invalid JSON format");
}
});
});
// System Prompt
new Setting(this.container)
.setName("System prompt")