Skip to content

Commit 9cd4c38

Browse files
committed
improve prompt
1 parent cc5f198 commit 9cd4c38

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/xl-ai/src/api/formats/markdown/markdown.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ export async function callLLM(
2626
options: MarkdownLLMRequestOptions
2727
) {
2828
let messages: CoreMessage[];
29-
const markdown = await editor.blocksToMarkdownLossy();
29+
// TODO: add test with empty paragraphs at end, this should break without trim()
30+
const markdown = (await editor.blocksToMarkdownLossy()).trim();
3031

3132
if ("messages" in options && options.messages) {
3233
messages = options.messages;
3334
} else if (options.useSelection) {
3435
const selection = editor.getDocumentWithSelectionMarkers();
35-
const markdown = await editor.blocksToMarkdownLossy(selection);
36+
const markdown = (await editor.blocksToMarkdownLossy(selection)).trim();
3637
messages = promptManipulateDocumentUseMarkdownWithSelection({
3738
editor,
3839
markdown,

packages/xl-ai/src/api/prompts/markdownPrompts.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ export function promptManipulateDocumentUseMarkdownWithSelection(opts: {
4040
},
4141
{
4242
role: "system",
43-
content:
44-
"Return the ENTIRE markdown document (including parts outside the selection), but make sure to ONLY change the selected text (text between [$! and !$]), keep the rest of the document unchanged. DO NOT include the markers in the response.",
43+
content: `You MUST return the ENTIRE markdown document (from start to end, INCLUDING parts outside the selection).
44+
But, the next user prompt ONLY applies to the selectiom so make sure to ONLY change the selected text (text between [$! and !$]) and keep the rest of the document unchanged.
45+
DO NOT include the markers in the response.`,
4546
},
4647
{
4748
role: "user",

0 commit comments

Comments
 (0)