You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chat.ts 792B

12345678910111213141516171819202122232425
  1. import { EmptyConversationId, MessageType } from '@/constants/chat';
  2. import { Message } from '@/interfaces/database/chat';
  3. import { IMessage } from '@/pages/chat/interface';
  4. import { v4 as uuid } from 'uuid';
  5. export const isConversationIdExist = (conversationId: string) => {
  6. return conversationId !== EmptyConversationId && conversationId !== '';
  7. };
  8. export const buildMessageUuid = (message: Partial<Message | IMessage>) => {
  9. if ('id' in message && message.id) {
  10. return message.role === MessageType.User
  11. ? `${MessageType.User}_${message.id}`
  12. : `${MessageType.Assistant}_${message.id}`;
  13. }
  14. return uuid();
  15. };
  16. export const getMessagePureId = (id: string) => {
  17. const strings = id.split('_');
  18. if (strings.length > 0) {
  19. return strings.at(-1);
  20. }
  21. return id;
  22. };