diff --git a/src/main.tsx b/src/main.tsx
index 5aac27f..1701d98 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -9,7 +9,7 @@ import {
import * as presetPrompts from './prompts';
import { IPrompt, PromptOutputType } from './prompts/type';
import settings, { ISettings } from './settings';
-import { getBlockContent } from './utils';
+import { escapeLLMOutput, getBlockContent } from './utils';
function getPrompts() {
const { customPrompts } = logseq.settings as unknown as ISettings;
@@ -74,7 +74,7 @@ function main() {
const input = await template.formatMessages({ content });
const message = await model.call(input);
// only accept text response for now
- const response = message.content.toString();
+ const response = escapeLLMOutput(message.content.toString());
switch (output) {
case PromptOutputType.property: {
diff --git a/src/utils.ts b/src/utils.ts
index 3542419..97b74a7 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -16,3 +16,15 @@ export async function getBlockContent(block: BlockEntity, parentBlock = true, le
return content;
}
+
+
+export function escapeLLMOutput(text: string) {
+ function removeThinkingPart(text: string) {
+ // ...
+ const thinkingPattern = /[\s\S]*?<\/think>/gi;
+ return text.replace(thinkingPattern, '');
+ }
+
+ let cleanedText = removeThinkingPart(text);
+ return cleanedText.trim();
+}