Revert "Sanitize citations from clinical image prompts"
All checks were successful
Forgejo Android APK / Build signed APK (push) Successful in 1m43s

This reverts commit 7833018695.
This commit is contained in:
Daniel 2026-09-02 01:50:44 +02:00
parent 7833018695
commit 2942d4f6b3
3 changed files with 3 additions and 15 deletions

View file

@ -285,7 +285,7 @@ async function imageSourceToBlob(src) {
export function buildContextualImagePrompt(request, lastAnswer) {
var prompt = String(request || '').trim();
if (!lastAnswer) return prompt;
var answer = String(lastAnswer || '').replace(/\\?\[(?:\^?\d+(?:\s*,\s*\^?\d+)*)\\?\]/g, '').slice(0, 3000);
var answer = String(lastAnswer || '').replace(/\[\d+(?:\s*,\s*\d+)*\]/g, '').slice(0, 3000);
return prompt + '\n\nUse this clinical answer as the required context. Do not switch topics or introduce unrelated scenes such as gardening. Create a medical teaching visual faithful to the answer. Do not include citations, reference numbers, footnotes, source lists, or named organizations; do not invent references.\n\nAnswer:\n' + answer;
}

View file

@ -66,11 +66,6 @@ function positiveInt(value, fallback) {
return Number.isFinite(n) && n > 0 ? Math.floor(n) : fallback;
}
function prepareClinicalImagePrompt(value) {
var prompt = String(value || '').replace(/\\?\[(?:\^?\d+(?:\s*,\s*\^?\d+)*)\\?\]/g, '').trim().slice(0, 4600);
return prompt + '\n\nDo not include citations, reference numbers, footnotes, source lists, named organizations, or invented references.';
}
if (process.env.CLINICAL_ASSISTANT_MCP_WARMUP !== 'false') {
setTimeout(function() {
warmMcpSession().catch(function(e) {
@ -292,7 +287,7 @@ router.post('/clinical-assistant/image', async function(req, res) {
try {
var prompt = String(req.body.prompt || '').trim();
if (!prompt) return res.status(400).json({ error: 'Prompt is required' });
prompt = prepareClinicalImagePrompt(prompt);
if (prompt.length > 5000) prompt = prompt.substring(0, 5000);
var model = await getSetting('clinical_assistant.image_model', '') || process.env.CLINICAL_ASSISTANT_IMAGE_MODEL || 'openai-gpt-image-1';
var image = await generateImage(prompt, model);
@ -308,7 +303,7 @@ router.post('/clinical-assistant/image/jobs', async function(req, res) {
try {
var prompt = String(req.body.prompt || '').trim();
if (!prompt) return res.status(400).json({ error: 'Prompt is required' });
prompt = prepareClinicalImagePrompt(prompt);
if (prompt.length > 5000) prompt = prompt.substring(0, 5000);
var model = await getSetting('clinical_assistant.image_model', '') || process.env.CLINICAL_ASSISTANT_IMAGE_MODEL || 'openai-gpt-image-1';
var id = crypto.randomBytes(16).toString('hex');

View file

@ -13,13 +13,6 @@ test('assistant image intent does not intercept table retrieval requests', async
assert.equal(isImageRequest('show me Table 13.1'), false);
});
test('clinical image prompts strip normal, escaped, and footnote citations', async () => {
const { buildContextualImagePrompt } = await imagesModule();
const prompt = buildContextualImagePrompt('Create a teaching visual', 'Claim [1], escaped \\[2, 3\\], and footnote [^4].');
assert.doesNotMatch(prompt, /\[1\]|\\\[2, 3\\\]|\[\^4\]/);
assert.match(prompt, /Do not include citations/);
});
test('assistant image intent still handles explicit visual requests', async () => {
const { isImageRequest } = await imagesModule();
assert.equal(isImageRequest('show me the diagram'), true);