diff --git a/src/api.ts b/src/api.ts index 438d7d7..eeaec01 100644 --- a/src/api.ts +++ b/src/api.ts @@ -13,14 +13,16 @@ import { setGeneratedResponseEffect } from "./modules/AIExtension"; export class ChatApiManager { private chatClient: ChatOpenAI | ChatOllama; private app: App; + private settings: InlineAISettings; /** * Initializes the ChatApiManager with the given settings. * @param settings - Configuration settings for the chat API. */ - constructor(private settings: InlineAISettings, app: App) { + constructor(settings: InlineAISettings, app: App) { this.app = app; this.chatClient = this.initializeChatClient(settings); + this.settings = settings; } /** @@ -122,47 +124,24 @@ export class ChatApiManager { * @returns The transformed text. */ public async callSelection(prompt: string, selectedText: string): Promise { - const systemPrompt = ` -**System Prompt:** -You are an advanced language model that performs text transformations based on specific instructions. Your task is to process input text to produce the desired output based on a given transformation type. You can handle tasks like adding emojis, making text longer or shorter, and converting text into tables, among many others. Use **Obsidian-flavored markdown** in all your transformations when applicable. Follow the examples provided to guide your responses. + let isCursor = false; + if (selectedText.trim().length === 0) { isCursor = true; } -It is **very important** that you follow the examples. Do not add anything at the start of the output like "Output:" or "Here's a rephrased version of the input text:" or anything similar. Just provide the transformed text. -**Examples:** + const systemPrompt = isCursor ? this.settings.cursorPrompt : this.settings.selectionPrompt; + let userPrompt = `` + if (isCursor) { + userPrompt = ` + **Task:** ${prompt} + **Output:**`; + } else { + userPrompt = ` + **Task:** ${prompt} + **Input:** + ${selectedText} ---- - -**Task:** Add Emojis. -**Prompt:** Add relevant emojis to make the text more engaging. - -**Input:** -"Let's celebrate the success of our project." - -**Output:** -"🎉 Let's celebrate the success of our project! 🚀👏" - ---- - -**Task:** Convert to Table. -**Prompt:** Convert the text into an Obsidian table format. - -**Input:** -"Name: John, Age: 30, Profession: Engineer" - -**Output:** -| Name | Age | Profession | -|-------|-----|-------------| -| John | 30 | Engineer| - ---- -`; - - const userPrompt = ` -**Task:** ${prompt} -**Input:** -${selectedText} - -**Output:**`; + **Output:**`; + } return this.handleEditorUpdate(systemPrompt, userPrompt); } diff --git a/src/default_prompts.ts b/src/default_prompts.ts index 95dabda..1d8e0c0 100644 --- a/src/default_prompts.ts +++ b/src/default_prompts.ts @@ -32,4 +32,47 @@ It is **very important** that you follow the examples. Do not add anything at th --- ` -export const cursorPrompt = "Generate text based on cursor position."; \ No newline at end of file +export const cursorPrompt = ` +You are an advanced language model specialized in following specific instructions to create and process markdown documents. Always use **Obsidian-flavored Markdown** syntax in your responses whenever applicable. + +## Examples: + +**Prompt:** Create a note titled "Daily Goals" with a list of tasks. +**Output:** +# Daily Goals +- [ ] Task 1: Complete the project proposal +- [ ] Task 2: Attend team meeting +- [ ] Task 3: Review budget plan + +--- + +**Prompt:** Generate a note about "Meeting Notes" with a table summarizing the key points. +**Output:** +# Meeting Notes + +| Topic | Discussion Summary | Action Items | +|-----------------|------------------------------|------------------------| +| Project Update | Discussed project milestones | Update Gantt chart | +| Budget Review | Reviewed proposed budget | Finalize budget draft | + +--- + +**Prompt:** Create a note titled "Books to Read" with headings for different genres and a list of book titles under each genre. +**Output:** +# Books to Read + +## Fiction +- *Dune* by Frank Herbert +- *1984* by George Orwell + +## Non-Fiction +- *Sapiens* by Yuval Noah Harari +- *Educated* by Tara Westover + +## Science +- *A Brief History of Time* by Stephen Hawking +- *The Selfish Gene* by Richard Dawkins + +--- + +Follow this structure and style for all responses, adapting to the specific **Prompt** provided.`;