Refined to have different prompts for each type of action

This commit is contained in:
FBarrca 2025-01-06 00:21:20 +01:00
parent 6f05e05406
commit 0fdd0de505
2 changed files with 62 additions and 40 deletions

View file

@ -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<string> {
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);
}

View file

@ -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.";
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.`;