2024-10-13 18:53:43 +00:00
|
|
|
// @ts-nocheck
|
|
|
|
// Preventing TS checks with files presented in the video for a better presentation.
|
2024-07-25 15:28:23 +00:00
|
|
|
import { modificationsRegex } from '~/utils/diff';
|
2024-11-06 20:35:54 +00:00
|
|
|
import { MODEL_REGEX, PROVIDER_REGEX } from '~/utils/constants';
|
2024-07-10 16:44:39 +00:00
|
|
|
import { Markdown } from './Markdown';
|
|
|
|
|
|
|
|
interface UserMessageProps {
|
|
|
|
content: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function UserMessage({ content }: UserMessageProps) {
|
2024-11-19 00:55:28 +00:00
|
|
|
const sanitizedContent = sanitizeUserMessage(content);
|
|
|
|
const textContent = Array.isArray(sanitizedContent)
|
|
|
|
? sanitizedContent.find(item => item.type === 'text')?.text || ''
|
|
|
|
: sanitizedContent;
|
|
|
|
|
2024-07-10 16:44:39 +00:00
|
|
|
return (
|
2024-08-08 13:56:36 +00:00
|
|
|
<div className="overflow-hidden pt-[4px]">
|
2024-11-19 00:55:28 +00:00
|
|
|
<Markdown limitedMarkdown>{textContent}</Markdown>
|
2024-07-10 16:44:39 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2024-07-25 15:28:23 +00:00
|
|
|
|
2024-11-19 00:55:28 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle legacy string content
|
|
|
|
return content.replace(/\[Model:.*?\]\n\n/, '').replace(/\[Provider:.*?\]\n\n/, '');
|
2024-07-25 15:28:23 +00:00
|
|
|
}
|