mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
Merge 2296a180ae into b2244f7b53
This commit is contained in:
commit
3a117fe256
3 changed files with 159 additions and 8 deletions
|
|
@ -546,8 +546,11 @@ class AgentClient extends BaseClient {
|
|||
const currentAttachments = this.options.attachments ? await this.options.attachments : [];
|
||||
const compatibleHistoricalAttachments =
|
||||
this.getModelBoundAttachmentsForEndpoint(historicalAttachments);
|
||||
const compatibleCurrentAttachments =
|
||||
this.getModelBoundAttachmentsForEndpoint(currentAttachments);
|
||||
/* A tool file refreshed this turn is replayed with its message; count it once. */
|
||||
const replayedFileIds = collectFileIds(compatibleHistoricalAttachments);
|
||||
const compatibleCurrentAttachments = this.getModelBoundAttachmentsForEndpoint(
|
||||
currentAttachments,
|
||||
).filter((file) => !replayedFileIds.has(file?.file_id));
|
||||
this.turnSteerAttachmentHistory = undefined;
|
||||
this.turnHistoricalAttachmentIds = collectHistoricalAttachmentIds(
|
||||
historicalAttachments,
|
||||
|
|
@ -2488,6 +2491,17 @@ class AgentClient extends BaseClient {
|
|||
const requestAttachments = requestAttachmentsSource ? await requestAttachmentsSource : [];
|
||||
const modelBoundRequestAttachments =
|
||||
this.getModelBoundAttachmentsForEndpoint(requestAttachments);
|
||||
/* A tool file the turn refreshes keeps its text and media in the message it was
|
||||
* attached to; the latest message only takes files no earlier message carries. */
|
||||
const latestMessageId = orderedMessages[orderedMessages.length - 1]?.messageId;
|
||||
const replayedFileIds = collectFileIds(
|
||||
Object.entries(this.message_file_map ?? {})
|
||||
.filter(([messageId]) => messageId !== latestMessageId)
|
||||
.flatMap(([, files]) => files),
|
||||
);
|
||||
const isNotReplayed = (file) => !replayedFileIds.has(file?.file_id);
|
||||
const turnAttachments = requestAttachments.filter(isNotReplayed);
|
||||
const turnModelBoundAttachments = modelBoundRequestAttachments.filter(isNotReplayed);
|
||||
const retainedHistoricalFileContexts =
|
||||
this.options.resendFiles === false
|
||||
? orderedMessages
|
||||
|
|
@ -2503,7 +2517,7 @@ class AgentClient extends BaseClient {
|
|||
const sharedAttachmentFiles = [
|
||||
...Object.values(this.message_file_map ?? {}).flat(),
|
||||
...(this.modelBoundHistoricalSteerFiles ?? []),
|
||||
...modelBoundRequestAttachments,
|
||||
...turnModelBoundAttachments,
|
||||
];
|
||||
const sharedRunAttachmentIds = collectFileIds(sharedAttachmentFiles);
|
||||
this.options.agentContextAttachmentsByAgentId = resolveScopedTurnAttachments({
|
||||
|
|
@ -2569,8 +2583,8 @@ class AgentClient extends BaseClient {
|
|||
|
||||
if (requestAttachmentsSource) {
|
||||
const attachments = this.getProcessableAttachmentsForEndpoint(
|
||||
requestAttachments,
|
||||
modelBoundRequestAttachments,
|
||||
turnAttachments,
|
||||
turnModelBoundAttachments,
|
||||
);
|
||||
const latestMessage = orderedMessages[orderedMessages.length - 1];
|
||||
this.modelBoundCurrentFiles = [...modelBoundRequestAttachments];
|
||||
|
|
@ -2597,11 +2611,13 @@ class AgentClient extends BaseClient {
|
|||
}
|
||||
|
||||
const [, files] = await Promise.all([
|
||||
this.addFileContextToMessage(latestMessage, modelBoundRequestAttachments),
|
||||
this.addFileContextToMessage(latestMessage, turnModelBoundAttachments),
|
||||
this.processAttachments(latestMessage, attachments),
|
||||
]);
|
||||
|
||||
this.options.attachments = files;
|
||||
this.options.attachments = files.concat(
|
||||
requestAttachments.filter((file) => !isNotReplayed(file)),
|
||||
);
|
||||
} else {
|
||||
agentScopedContextPromise = startAgentScopedContext();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue