fixes for PR #332

This commit is contained in:
Andrew Trokhymenko
2024-11-20 17:56:07 -05:00
parent fe3ea8005e
commit 76713c2e6e
3 changed files with 15 additions and 20 deletions

View File

@@ -9,10 +9,7 @@ interface UserMessageProps {
}
export function UserMessage({ content }: UserMessageProps) {
const sanitizedContent = sanitizeUserMessage(content);
const textContent = Array.isArray(sanitizedContent)
? sanitizedContent.find(item => item.type === 'text')?.text || ''
: sanitizedContent;
const textContent = sanitizeUserMessage(content);
return (
<div className="overflow-hidden pt-[4px]">
@@ -23,17 +20,9 @@ export function UserMessage({ content }: UserMessageProps) {
function sanitizeUserMessage(content: string | Array<{type: string, text?: string, image_url?: {url: string}}>) {
if (Array.isArray(content)) {
return content.map(item => {
if (item.type === 'text') {
return {
type: 'text',
text: item.text?.replace(/\[Model:.*?\]\n\n/, '').replace(/\[Provider:.*?\]\n\n/, '')
};
}
return item; // Keep image_url items unchanged
});
const textItem = content.find(item => item.type === 'text');
return textItem?.text?.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, '') || '';
}
// Handle legacy string content
return content.replace(/\[Model:.*?\]\n\n/, '').replace(/\[Provider:.*?\]\n\n/, '');
}
return content.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, '');
}