2024-11-21 21:05:35 +00:00
|
|
|
/*
|
|
|
|
* @ts-nocheck
|
|
|
|
* Preventing TS checks with files presented in the video for a better presentation.
|
|
|
|
*/
|
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 {
|
2024-12-02 19:08:41 +00:00
|
|
|
content: string | Array<{ type: string; text?: string; image?: string }>;
|
2024-07-10 16:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function UserMessage({ content }: UserMessageProps) {
|
2024-12-02 19:08:41 +00:00
|
|
|
if (Array.isArray(content)) {
|
|
|
|
const textItem = content.find((item) => item.type === 'text');
|
2024-12-16 09:01:41 +00:00
|
|
|
const textContent = stripMetadata(textItem?.text || '');
|
2024-12-02 19:08:41 +00:00
|
|
|
const images = content.filter((item) => item.type === 'image' && item.image);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="overflow-hidden pt-[4px]">
|
2024-12-16 09:01:41 +00:00
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
{textContent && <Markdown html>{textContent}</Markdown>}
|
|
|
|
{images.map((item, index) => (
|
|
|
|
<img
|
|
|
|
key={index}
|
|
|
|
src={item.image}
|
|
|
|
alt={`Image ${index + 1}`}
|
|
|
|
className="max-w-full h-auto rounded-lg"
|
|
|
|
style={{ maxHeight: '512px', objectFit: 'contain' }}
|
|
|
|
/>
|
|
|
|
))}
|
2024-12-02 19:08:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-16 09:01:41 +00:00
|
|
|
const textContent = stripMetadata(content);
|
2024-11-19 00:55:28 +00:00
|
|
|
|
2024-07-10 16:44:39 +00:00
|
|
|
return (
|
2024-08-08 13:56:36 +00:00
|
|
|
<div className="overflow-hidden pt-[4px]">
|
2024-12-16 09:01:41 +00:00
|
|
|
<Markdown html>{textContent}</Markdown>
|
2024-07-10 16:44:39 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2024-07-25 15:28:23 +00:00
|
|
|
|
2024-12-16 09:01:41 +00:00
|
|
|
function stripMetadata(content: string) {
|
2024-11-20 22:56:07 +00:00
|
|
|
return content.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, '');
|
2024-07-25 15:28:23 +00:00
|
|
|
}
|