feat(Message): add and handle isEdited property when edited/continued as this can include user input

This commit is contained in:
Daniel Avila 2023-09-07 06:37:04 -04:00 committed by Danny Avila
parent cc260105ec
commit 327a69dba3
11 changed files with 17 additions and 41 deletions

View file

@ -473,6 +473,7 @@ class BaseClient {
conversationId, conversationId,
parentMessageId: userMessage.messageId, parentMessageId: userMessage.messageId,
isCreatedByUser: false, isCreatedByUser: false,
isEdited,
model: this.modelOptions.model, model: this.modelOptions.model,
sender: this.sender, sender: this.sender,
text: addSpaceIfNeeded(generation) + (await this.sendCompletion(payload, opts)), text: addSpaceIfNeeded(generation) + (await this.sendCompletion(payload, opts)),

View file

@ -242,6 +242,7 @@ class PluginsClient extends OpenAIClient {
} }
const { const {
user, user,
isEdited,
conversationId, conversationId,
responseMessageId, responseMessageId,
saveOptions, saveOptions,
@ -293,6 +294,7 @@ class PluginsClient extends OpenAIClient {
conversationId, conversationId,
parentMessageId: userMessage.messageId, parentMessageId: userMessage.messageId,
isCreatedByUser: false, isCreatedByUser: false,
isEdited,
model: this.modelOptions.model, model: this.modelOptions.model,
sender: this.sender, sender: this.sender,
promptTokens, promptTokens,

View file

@ -14,6 +14,7 @@ module.exports = {
error, error,
unfinished, unfinished,
cancelled, cancelled,
isEdited = false,
finish_reason = null, finish_reason = null,
tokenCount = null, tokenCount = null,
plugin = null, plugin = null,
@ -34,6 +35,7 @@ module.exports = {
sender, sender,
text, text,
isCreatedByUser, isCreatedByUser,
isEdited,
finish_reason, finish_reason,
error, error,
unfinished, unfinished,
@ -63,6 +65,7 @@ module.exports = {
async updateMessage(message) { async updateMessage(message) {
try { try {
const { messageId, ...update } = message; const { messageId, ...update } = message;
update.isEdited = true;
const updatedMessage = await Message.findOneAndUpdate({ messageId }, update, { new: true }); const updatedMessage = await Message.findOneAndUpdate({ messageId }, update, { new: true });
if (!updatedMessage) { if (!updatedMessage) {
@ -77,6 +80,7 @@ module.exports = {
text: updatedMessage.text, text: updatedMessage.text,
isCreatedByUser: updatedMessage.isCreatedByUser, isCreatedByUser: updatedMessage.isCreatedByUser,
tokenCount: updatedMessage.tokenCount, tokenCount: updatedMessage.tokenCount,
isEdited: true,
}; };
} catch (err) { } catch (err) {
console.error(`Error updating message: ${err}`); console.error(`Error updating message: ${err}`);

View file

@ -55,6 +55,10 @@ const messageSchema = mongoose.Schema(
required: true, required: true,
default: false, default: false,
}, },
isEdited: {
type: Boolean,
default: false,
},
unfinished: { unfinished: {
type: Boolean, type: Boolean,
default: false, default: false,

View file

@ -61,6 +61,7 @@ router.post(
text: partialText, text: partialText,
unfinished: true, unfinished: true,
cancelled: false, cancelled: false,
isEdited: true,
error: false, error: false,
}); });
} }

View file

@ -80,6 +80,7 @@ router.post(
model: endpointOption.modelOptions.model, model: endpointOption.modelOptions.model,
unfinished: true, unfinished: true,
cancelled: false, cancelled: false,
isEdited: true,
error: false, error: false,
}); });
} }

View file

@ -63,6 +63,7 @@ router.post(
model: endpointOption.modelOptions.model, model: endpointOption.modelOptions.model,
unfinished: true, unfinished: true,
cancelled: false, cancelled: false,
isEdited: true,
error: false, error: false,
}); });
} }

View file

@ -12,47 +12,6 @@ const EModelEndpoint = {
const eModelEndpointSchema = z.nativeEnum(EModelEndpoint); const eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
/*
const tMessageSchema = z.object({
messageId: z.string(),
clientId: z.string().nullable().optional(),
conversationId: z.string().nullable(),
parentMessageId: z.string().nullable(),
sender: z.string(),
text: z.string(),
isCreatedByUser: z.boolean(),
error: z.boolean(),
createdAt: z
.string()
.optional()
.default(() => new Date().toISOString()),
updatedAt: z
.string()
.optional()
.default(() => new Date().toISOString()),
current: z.boolean().optional(),
unfinished: z.boolean().optional(),
submitting: z.boolean().optional(),
searchResult: z.boolean().optional(),
finish_reason: z.string().optional(),
});
const tPresetSchema = tConversationSchema
.omit({
conversationId: true,
createdAt: true,
updatedAt: true,
title: true,
})
.merge(
z.object({
conversationId: z.string().optional(),
presetId: z.string().nullable().optional(),
title: z.string().nullable().optional(),
}),
);
*/
const tPluginAuthConfigSchema = z.object({ const tPluginAuthConfigSchema = z.object({
authField: z.string(), authField: z.string(),
label: z.string(), label: z.string(),

View file

@ -69,6 +69,7 @@ const EditMessage = ({
? { ? {
...msg, ...msg,
text, text,
isEdited: true,
} }
: msg, : msg,
), ),

View file

@ -101,6 +101,7 @@ const useMessageHandler = () => {
unfinished: false, unfinished: false,
submitting: true, submitting: true,
isCreatedByUser: false, isCreatedByUser: false,
isEdited: isEditOrContinue,
error: false, error: false,
}; };

View file

@ -77,6 +77,7 @@ export const tMessageSchema = z.object({
sender: z.string(), sender: z.string(),
text: z.string(), text: z.string(),
generation: z.string().nullable().optional(), generation: z.string().nullable().optional(),
isEdited: z.boolean().optional(),
isCreatedByUser: z.boolean(), isCreatedByUser: z.boolean(),
error: z.boolean(), error: z.boolean(),
createdAt: z createdAt: z