Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ export async function getBlockContent(block: BlockEntity, parentBlock = true, le

return content;
}


export function escapeLLMOutput(text: string) {
function removeThinkingPart(text: string) {
// <think> ... </think>
const thinkingPattern = /<think>[\s\S]*?<\/think>/gi;
return text.replace(thinkingPattern, '');
}

let cleanedText = removeThinkingPart(text);
return cleanedText.trim();
}