mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-30 15:18:50 +01:00
⌚ fix: Wait for Initial Message Save & Correct Latest Message (#3399)
* chore: assistants, unsupported assistant, better logging * chore: remove unnecessary logger in validateAssistant middleware * fix: resolve initial conversation save/promise before saving response * chore: Import and organize dependencies in Speech component * fix: conversation statefulness - Latest Message (at index 0) should not be reset if existing convo - add debugging context for clearAllLatestMessages - Added logging concerning latest Message updates (dev mode only) - update latest message Set logic, also checks for change in conversation Id - consolidated latest message helpers to client/src/utils/messages.ts
This commit is contained in:
parent
9e7615f832
commit
2ad097647c
25 changed files with 275 additions and 113 deletions
|
|
@ -1,13 +1,17 @@
|
|||
import { ContentTypes } from 'librechat-data-provider';
|
||||
import { ContentTypes, Constants } from 'librechat-data-provider';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
|
||||
export const getLengthAndFirstFiveChars = (str?: string) => {
|
||||
const length = str ? str.length : 0;
|
||||
const firstFiveChars = str ? str.substring(0, 5) : '';
|
||||
return `${length}${firstFiveChars}`;
|
||||
export const getLengthAndLastTenChars = (str?: string): string => {
|
||||
if (!str) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
const length = str.length;
|
||||
const lastTenChars = str.slice(-10);
|
||||
return `${length}${lastTenChars}`;
|
||||
};
|
||||
|
||||
export const getLatestText = (message?: TMessage | null) => {
|
||||
export const getLatestText = (message?: TMessage | null, includeIndex?: boolean) => {
|
||||
if (!message) {
|
||||
return '';
|
||||
}
|
||||
|
|
@ -18,9 +22,24 @@ export const getLatestText = (message?: TMessage | null) => {
|
|||
for (let i = message.content.length - 1; i >= 0; i--) {
|
||||
const part = message.content[i];
|
||||
if (part.type === ContentTypes.TEXT && part[ContentTypes.TEXT]?.value?.length > 0) {
|
||||
return part[ContentTypes.TEXT].value;
|
||||
const text = part[ContentTypes.TEXT].value;
|
||||
if (includeIndex) {
|
||||
return `${text}-${i}`;
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
export const getTextKey = (message?: TMessage | null, convoId?: string | null) => {
|
||||
if (!message) {
|
||||
return '';
|
||||
}
|
||||
const text = getLatestText(message, true);
|
||||
return `${message.messageId ?? ''}${Constants.COMMON_DIVIDER}${getLengthAndLastTenChars(text)}${
|
||||
Constants.COMMON_DIVIDER
|
||||
}${message.conversationId ?? convoId}`;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue