Skip to content

Commit

Permalink
fix linebreak in system_prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
clusterzx committed Jan 2, 2025
1 parent a13db89 commit 19512f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 15 additions & 2 deletions routes/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ router.use(async (req, res, next) => {
next();
});

// const base64Encode = (str) => Buffer.from(str).toString('base64');

router.get('/setup', async (req, res) => {

// Helper function to properly handle multiline strings
const processSystemPrompt = (prompt) => {
if (!prompt) return '';
// Replace escaped newlines with actual newlines
return prompt.replace('\n', '\n');
};

const isConfigured = await setupService.isConfigured();
let config = {
PAPERLESS_API_URL: process.env.PAPERLESS_API_URL || 'http://localhost:8000',
Expand Down Expand Up @@ -244,12 +254,15 @@ router.post('/setup', express.urlencoded({ extended: true }), async (req, res) =
openaiModel,
ollamaUrl,
ollamaModel,
scanInterval ,
scanInterval,
systemPrompt,
showTags,
tags
} = req.body;

// Process system prompt - replace line breaks with \n
const processedPrompt = systemPrompt.replace(/\r\n/g, '\n').replace(/\n/g, '\\n');

// Validate Paperless config
const isPaperlessValid = await setupService.validatePaperlessConfig(paperlessUrl, paperlessToken);
if (!isPaperlessValid) {
Expand All @@ -265,7 +278,7 @@ router.post('/setup', express.urlencoded({ extended: true }), async (req, res) =
PAPERLESS_API_TOKEN: paperlessToken,
AI_PROVIDER: aiProvider,
SCAN_INTERVAL: scanInterval,
SYSTEM_PROMPT: systemPrompt,
SYSTEM_PROMPT: processedPrompt, // Use the processed prompt
PROCESS_PREDEFINED_DOCUMENTS: showTags,
TAGS: tags.split(',').map(tag => tag.trim())
};
Expand Down
6 changes: 6 additions & 0 deletions views/setup.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@
</div>
</main>
</div>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const systemPromptTextarea = document.getElementById('systemPrompt');
systemPromptTextarea.value = systemPromptTextarea.value.replace(/\\n/g, '\n');
});
</script>
<script src="js/setup.js"></script>
</body>
</html>

0 comments on commit 19512f6

Please sign in to comment.