feat: support prompt templates
This commit is contained in:
parent
7c405e2e0d
commit
5ecd7c81ac
9 changed files with 156 additions and 29 deletions
|
@ -6,6 +6,17 @@
|
|||
</head>
|
||||
<body>
|
||||
<label>Endpoint: <input id="endpoint" type="text"></label><br>
|
||||
<label>Prompt template:
|
||||
<select id="template"></select>
|
||||
</label><br>
|
||||
<div id="custom-template-container" style="display:none">
|
||||
<label>Custom template</label><br>
|
||||
<textarea id="custom-template" rows="6" cols="60"></textarea>
|
||||
<p>Placeholders: {{system}}, {{email}}, {{operator}}, {{query}}</p>
|
||||
</div>
|
||||
<label>System instructions:</label><br>
|
||||
<textarea id="system-instructions" rows="4" cols="60"></textarea>
|
||||
<button id="reset-system">Reset to default</button><br>
|
||||
<button id="save">Save</button>
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
|
|
|
@ -1,14 +1,54 @@
|
|||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
let { endpoint = 'http://127.0.0.1:5000/v1/classify' } = await browser.storage.local.get(['endpoint']);
|
||||
document.getElementById('endpoint').value = endpoint;
|
||||
});
|
||||
const defaults = await browser.storage.local.get([
|
||||
'endpoint',
|
||||
'templateName',
|
||||
'customTemplate',
|
||||
'customSystemPrompt'
|
||||
]);
|
||||
document.getElementById('endpoint').value = defaults.endpoint || 'http://127.0.0.1:5000/v1/classify';
|
||||
|
||||
document.getElementById('save').addEventListener('click', async () => {
|
||||
const endpoint = document.getElementById('endpoint').value;
|
||||
await browser.storage.local.set({ endpoint });
|
||||
try {
|
||||
await browser.aiFilter.initConfig({ endpoint });
|
||||
} catch (e) {
|
||||
console.error('[ai-filter][options] failed to apply config', e);
|
||||
const templates = {
|
||||
openai: browser.i18n.getMessage('template.openai'),
|
||||
qwen: browser.i18n.getMessage('template.qwen'),
|
||||
mistral: browser.i18n.getMessage('template.mistral'),
|
||||
custom: browser.i18n.getMessage('template.custom')
|
||||
};
|
||||
const templateSelect = document.getElementById('template');
|
||||
for (const [value, label] of Object.entries(templates)) {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = value;
|
||||
opt.textContent = label;
|
||||
templateSelect.appendChild(opt);
|
||||
}
|
||||
templateSelect.value = defaults.templateName || 'openai';
|
||||
|
||||
const customBox = document.getElementById('custom-template-container');
|
||||
const customTemplate = document.getElementById('custom-template');
|
||||
customTemplate.value = defaults.customTemplate || '';
|
||||
|
||||
function updateVisibility() {
|
||||
customBox.style.display = templateSelect.value === 'custom' ? 'block' : 'none';
|
||||
}
|
||||
templateSelect.addEventListener('change', updateVisibility);
|
||||
updateVisibility();
|
||||
|
||||
const DEFAULT_SYSTEM = 'Determine whether the email satisfies the user\'s criterion.';
|
||||
const systemBox = document.getElementById('system-instructions');
|
||||
systemBox.value = defaults.customSystemPrompt || DEFAULT_SYSTEM;
|
||||
document.getElementById('reset-system').addEventListener('click', () => {
|
||||
systemBox.value = DEFAULT_SYSTEM;
|
||||
});
|
||||
|
||||
document.getElementById('save').addEventListener('click', async () => {
|
||||
const endpoint = document.getElementById('endpoint').value;
|
||||
const templateName = templateSelect.value;
|
||||
const customTemplateText = customTemplate.value;
|
||||
const customSystemPrompt = systemBox.value;
|
||||
await browser.storage.local.set({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt });
|
||||
try {
|
||||
await browser.aiFilter.initConfig({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt });
|
||||
} catch (e) {
|
||||
console.error('[ai-filter][options] failed to apply config', e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue