mirror of
https://github.com/ahmetildirim/obsidian-inscribe.git
synced 2026-07-22 05:44:10 +00:00
refactor: rename CompletionOptions to ProviderOptions and update related settings
This commit is contained in:
parent
63357000f5
commit
0d5b21a8b5
8 changed files with 30 additions and 33 deletions
|
|
@ -2,7 +2,7 @@ import { App, Editor } from "obsidian";
|
|||
import { ProfileService } from "src/profile/service";
|
||||
import { ProviderFactory } from "src/providers/factory";
|
||||
import { Suggestion } from "src/extension";
|
||||
import { CompletionOptions, Settings } from "src/settings/settings";
|
||||
import { ProviderOptions, Settings } from "src/settings/settings";
|
||||
import { Provider } from "src/providers/provider";
|
||||
import preparePrompt from "src/completions/prompt";
|
||||
import { isVimEnabled, isVimInsertMode } from "src/completions/vim";
|
||||
|
|
@ -79,7 +79,7 @@ export default class CompletionService {
|
|||
}
|
||||
}
|
||||
|
||||
private async *complete(editor: Editor, provider: Provider, prompt: string, options: CompletionOptions): AsyncGenerator<Suggestion> {
|
||||
private async *complete(editor: Editor, provider: Provider, prompt: string, options: ProviderOptions): AsyncGenerator<Suggestion> {
|
||||
for await (let text of provider.generate(editor, prompt, options)) {
|
||||
text = text.trim();
|
||||
|
||||
|
|
|
|||
|
|
@ -29,12 +29,11 @@ export default class Inscribe extends Plugin {
|
|||
}
|
||||
|
||||
async setupExtension() {
|
||||
debugger
|
||||
const extension = inlineSuggestions({
|
||||
fetchFunc: () => this.completionService.fetchCompletion(),
|
||||
getOptions: () => this.profileService.getOptions(),
|
||||
acceptanceHotkey: this.settings.suggestionSettings.acceptanceHotkey,
|
||||
triggerHotkey: this.settings.suggestionSettings.manualActivationKey,
|
||||
acceptanceHotkey: this.settings.suggestionControl.acceptanceHotkey,
|
||||
triggerHotkey: this.settings.suggestionControl.manualActivationKey,
|
||||
});
|
||||
this.registerEditorExtension(extension);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { GeminiSettings } from "./settings";
|
||||
import { Provider } from "..";
|
||||
import { Editor } from "obsidian";
|
||||
import { CompletionOptions } from "src/settings/settings";
|
||||
import { ProviderOptions } from "src/settings/settings";
|
||||
import { GoogleGenAI } from "@google/genai";
|
||||
|
||||
export class GeminiProvider implements Provider {
|
||||
|
|
@ -16,7 +16,7 @@ export class GeminiProvider implements Provider {
|
|||
});
|
||||
}
|
||||
|
||||
async * generate(editor: Editor, prompt: string, options: CompletionOptions): AsyncGenerator<string> {
|
||||
async * generate(editor: Editor, prompt: string, options: ProviderOptions): AsyncGenerator<string> {
|
||||
this.aborted = false;
|
||||
|
||||
const response = await this.client.models.generateContentStream({
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { ModelResponse, Ollama } from "ollama";
|
|||
import { OllamaSettings } from "./settings";
|
||||
import { Provider } from "..";
|
||||
import { Editor } from "obsidian";
|
||||
import { CompletionOptions } from "src/settings/settings";
|
||||
import { ProviderOptions } from "src/settings/settings";
|
||||
|
||||
export class OllamaProvider implements Provider {
|
||||
client: Ollama
|
||||
|
|
@ -14,7 +14,7 @@ export class OllamaProvider implements Provider {
|
|||
this.client = new Ollama({ host: this.settings.host });
|
||||
}
|
||||
|
||||
async *generate(editor: Editor, prompt: string, options: CompletionOptions): AsyncGenerator<string> {
|
||||
async *generate(editor: Editor, prompt: string, options: ProviderOptions): AsyncGenerator<string> {
|
||||
this.aborted = false;
|
||||
|
||||
const completionIterator = await this.client.generate({
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Provider } from "..";
|
||||
import { Editor } from "obsidian";
|
||||
import { OpenAICompatibleSettings } from ".";
|
||||
import { CompletionOptions } from "src/settings/settings";
|
||||
import { ProviderOptions } from "src/settings/settings";
|
||||
import OpenAI from "openai";
|
||||
|
||||
export class OpenAICompatibleProvider implements Provider {
|
||||
|
|
@ -19,7 +19,7 @@ export class OpenAICompatibleProvider implements Provider {
|
|||
});
|
||||
}
|
||||
|
||||
async *generate(editor: Editor, prompt: string, options: CompletionOptions): AsyncGenerator<string> {
|
||||
async *generate(editor: Editor, prompt: string, options: ProviderOptions): AsyncGenerator<string> {
|
||||
this.aborted = false;
|
||||
this.abortcontroller = new AbortController();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Provider } from "..";
|
||||
import { Editor } from "obsidian";
|
||||
import { OpenAISettings } from ".";
|
||||
import { CompletionOptions } from "src/settings/settings";
|
||||
import { ProviderOptions } from "src/settings/settings";
|
||||
import OpenAI from "openai";
|
||||
|
||||
export class OpenAIProvider implements Provider {
|
||||
|
|
@ -18,7 +18,7 @@ export class OpenAIProvider implements Provider {
|
|||
});
|
||||
}
|
||||
|
||||
async *generate(editor: Editor, prompt: string, options: CompletionOptions): AsyncGenerator<string> {
|
||||
async *generate(editor: Editor, prompt: string, options: ProviderOptions): AsyncGenerator<string> {
|
||||
this.aborted = false;
|
||||
this.abortcontroller = new AbortController();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Editor } from "obsidian";
|
||||
import { CompletionOptions } from "src/settings/settings";
|
||||
import { ProviderOptions } from "src/settings/settings";
|
||||
|
||||
export enum ProviderType {
|
||||
OLLAMA = "ollama",
|
||||
|
|
@ -11,7 +11,7 @@ export enum ProviderType {
|
|||
// Completer interface for ai integrations
|
||||
export interface Provider {
|
||||
settings: any
|
||||
generate: (editor: Editor, prompt: string, options: CompletionOptions) => AsyncGenerator<string>;
|
||||
generate: (editor: Editor, prompt: string, options: ProviderOptions) => AsyncGenerator<string>;
|
||||
abort: () => Promise<void>;
|
||||
fetchModels(): Promise<string[]> | string[];
|
||||
connectionTest(): Promise<boolean>;
|
||||
|
|
|
|||
|
|
@ -6,40 +6,39 @@ import { OpenAICompatibleSettings } from "src/providers/openai-compat";
|
|||
import { GeminiSettings } from "src/providers/gemini";
|
||||
|
||||
// Completion options for a profile
|
||||
export interface CompletionOptions {
|
||||
export interface ProviderOptions {
|
||||
model: string,
|
||||
userPrompt: string,
|
||||
systemPrompt: string,
|
||||
temperature: number,
|
||||
outputLimit: {
|
||||
enabled: boolean,
|
||||
sentences: number,
|
||||
}
|
||||
}
|
||||
|
||||
// Profile settings
|
||||
export interface Profile {
|
||||
name: string,
|
||||
provider: ProviderType,
|
||||
completionOptions: CompletionOptions,
|
||||
delayMs: number,
|
||||
// depracated, use SuggestionSettings instead
|
||||
splitStrategy: SplitStrategy
|
||||
completionOptions: ProviderOptions,
|
||||
}
|
||||
|
||||
export type ProfileId = string;
|
||||
export type Profiles = Record<ProfileId, Profile>
|
||||
export type Path = string;
|
||||
export type PathConfig = { profile: ProfileId, enabled: boolean };
|
||||
export type SuggestionSettings = {
|
||||
export type SuggestionControl = {
|
||||
acceptanceHotkey: string,
|
||||
manualActivationKey?: string,
|
||||
splitStrategy: SplitStrategy,
|
||||
delayMs: number,
|
||||
outputLimit: {
|
||||
enabled: boolean,
|
||||
sentences: number,
|
||||
},
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
enabled: boolean,
|
||||
suggestionSettings: SuggestionSettings,
|
||||
// settings for controlling suggestions
|
||||
suggestionControl: SuggestionControl,
|
||||
// available providers
|
||||
providers: {
|
||||
ollama: OllamaSettings,
|
||||
|
|
@ -57,10 +56,15 @@ export const DEFAULT_PROFILE: ProfileId = "default";
|
|||
export const DEFAULT_PATH = "/";
|
||||
export const DEFAULT_SETTINGS: Settings = {
|
||||
enabled: false,
|
||||
suggestionSettings: {
|
||||
suggestionControl: {
|
||||
acceptanceHotkey: "Tab",
|
||||
splitStrategy: "sentence",
|
||||
manualActivationKey: "",
|
||||
outputLimit: {
|
||||
enabled: true,
|
||||
sentences: 1,
|
||||
},
|
||||
delayMs: 500,
|
||||
},
|
||||
providers: {
|
||||
openai: {
|
||||
|
|
@ -108,17 +112,11 @@ export const DEFAULT_SETTINGS: Settings = {
|
|||
default: {
|
||||
name: "Default profile",
|
||||
provider: ProviderType.OLLAMA,
|
||||
delayMs: 500,
|
||||
splitStrategy: "sentence",
|
||||
completionOptions: {
|
||||
model: "gemma3:12b",
|
||||
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 user’s text smoothly, maintaining coherence, fluency, and style. Adapt to the user’s 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,
|
||||
outputLimit: {
|
||||
enabled: false,
|
||||
sentences: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue