Add function to sanitize AI response
This commit is contained in:
12
src/App.tsx
12
src/App.tsx
@@ -384,6 +384,18 @@ function getAiPromptTemplateLabel(template: AiPromptTemplate) {
|
|||||||
return template.title.trim() || "Untitled Prompt";
|
return template.title.trim() || "Untitled Prompt";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeAiResponse(text: string) {
|
||||||
|
const normalized = text.trim();
|
||||||
|
const markdownFenceMatch = normalized.match(
|
||||||
|
/```(?:markdown|md)\b[^\n\r]*\r?\n?([\s\S]*?)```/i
|
||||||
|
);
|
||||||
|
if (!markdownFenceMatch) {
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
return markdownFenceMatch[1].trim();
|
||||||
|
}
|
||||||
|
|
||||||
const graphemeSegmenter =
|
const graphemeSegmenter =
|
||||||
typeof Intl !== "undefined" && "Segmenter" in Intl
|
typeof Intl !== "undefined" && "Segmenter" in Intl
|
||||||
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
||||||
|
|||||||
Reference in New Issue
Block a user