Make AI categorization prompts user-configurable
Add SystemPrompt and UserPromptTemplate fields to AI categorization settings so users can customize the prompts sent to Ollama without code changes. Null/empty values fall back to built-in defaults. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -493,6 +493,8 @@ export interface AiCategorizationSettings {
|
||||
confidenceThreshold: number
|
||||
timeoutSeconds: number
|
||||
updatePayeeDefaults: boolean
|
||||
systemPrompt: string | null
|
||||
userPromptTemplate: string | null
|
||||
}
|
||||
|
||||
export interface OllamaConnectionTestResult {
|
||||
|
||||
@@ -466,6 +466,44 @@
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
|
||||
<v-card class="mt-4">
|
||||
<v-card-title>Prompt Templates</v-card-title>
|
||||
<v-card-text>
|
||||
<p class="text-body-2 text-medium-emphasis mb-4">
|
||||
Customize the prompts sent to the AI model. Leave empty to use built-in defaults.
|
||||
The category list is always appended to the system prompt, and the transaction list is always appended to the user prompt.
|
||||
</p>
|
||||
|
||||
<v-textarea
|
||||
v-model="aiSettings.systemPrompt"
|
||||
label="System Prompt"
|
||||
variant="outlined"
|
||||
rows="8"
|
||||
:placeholder="defaultSystemPrompt"
|
||||
persistent-placeholder
|
||||
class="mb-4"
|
||||
/>
|
||||
|
||||
<v-textarea
|
||||
v-model="aiSettings.userPromptTemplate"
|
||||
label="User Prompt Template"
|
||||
variant="outlined"
|
||||
rows="3"
|
||||
:placeholder="defaultUserPromptTemplate"
|
||||
persistent-placeholder
|
||||
class="mb-4"
|
||||
/>
|
||||
|
||||
<v-btn
|
||||
variant="tonal"
|
||||
color="secondary"
|
||||
@click="resetPromptsToDefaults"
|
||||
>
|
||||
Reset to Defaults
|
||||
</v-btn>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
|
||||
<v-snackbar v-model="showAiSuccess" :timeout="4000" color="success">
|
||||
AI categorization settings saved
|
||||
</v-snackbar>
|
||||
@@ -801,7 +839,9 @@ const aiSettings = reactive<AiCategorizationSettings>({
|
||||
modelName: 'llama3.1:8b',
|
||||
confidenceThreshold: 0.7,
|
||||
timeoutSeconds: 30,
|
||||
updatePayeeDefaults: true
|
||||
updatePayeeDefaults: true,
|
||||
systemPrompt: null,
|
||||
userPromptTemplate: null
|
||||
})
|
||||
const aiSaving = ref(false)
|
||||
const aiTesting = ref(false)
|
||||
@@ -811,6 +851,31 @@ const showAiSuccess = ref(false)
|
||||
const showAiError = ref(false)
|
||||
const aiErrorMessage = ref('')
|
||||
|
||||
const defaultSystemPrompt = `You are a personal finance transaction categorizer. Classify each transaction into the most appropriate category.
|
||||
|
||||
You MUST respond with valid JSON in exactly this format:
|
||||
{
|
||||
"classifications": [
|
||||
{"index": 0, "categoryName": "Groceries", "confidence": 0.9},
|
||||
{"index": 1, "categoryName": "Utilities", "confidence": 0.85}
|
||||
]
|
||||
}
|
||||
|
||||
Rules:
|
||||
- "index" must be the transaction number (integer) from the list below
|
||||
- "categoryName" must be one of the exact category names listed below
|
||||
- "confidence" must be a number between 0 and 1
|
||||
- Include one entry for every transaction
|
||||
|
||||
Available categories:`
|
||||
|
||||
const defaultUserPromptTemplate = 'Classify these uncategorized transactions:'
|
||||
|
||||
function resetPromptsToDefaults() {
|
||||
aiSettings.systemPrompt = null
|
||||
aiSettings.userPromptTemplate = null
|
||||
}
|
||||
|
||||
async function loadAiSettings() {
|
||||
try {
|
||||
const { data } = await aiCategorizationApi.getSettings()
|
||||
|
||||
Reference in New Issue
Block a user