mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-11 00:33:40 +00:00
refactor(agents): move calibration ratio capture to finally block
Reorganized the logic for capturing the calibration ratio in the AgentClient class to ensure it is executed in the finally block. This change guarantees that the ratio is captured even if the run is aborted, enhancing the reliability of the response message persistence. Removed redundant code and improved clarity in the handling of context metadata.
This commit is contained in:
parent
688296e13b
commit
4ca86fae3d
1 changed files with 12 additions and 14 deletions
|
|
@ -873,20 +873,6 @@ class AgentClient extends BaseClient {
|
|||
const hideSequentialOutputs = config.configurable.hide_sequential_outputs;
|
||||
await runAgents(initialMessages);
|
||||
|
||||
/** Capture calibration ratio from the completed run for persistence on the response message */
|
||||
if (this.run) {
|
||||
const ratio = this.run.getCalibrationRatio();
|
||||
if (ratio > 0 && ratio !== 1) {
|
||||
this.contextMeta = {
|
||||
calibrationRatio: Math.round(ratio * 1000) / 1000,
|
||||
encoding: this.getEncoding(),
|
||||
};
|
||||
logger.debug(
|
||||
`[AgentClient] contextMeta to persist: ratio=${this.contextMeta.calibrationRatio}, encoding=${this.contextMeta.encoding}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated Agent Chain */
|
||||
if (hideSequentialOutputs) {
|
||||
this.contentParts = this.contentParts.filter((part, index) => {
|
||||
|
|
@ -917,6 +903,18 @@ class AgentClient extends BaseClient {
|
|||
});
|
||||
}
|
||||
} finally {
|
||||
/** Capture calibration ratio from the run for persistence on the response message.
|
||||
* Runs in finally so the ratio is captured even on abort. */
|
||||
if (this.run) {
|
||||
const ratio = this.run.getCalibrationRatio();
|
||||
if (ratio > 0 && ratio !== 1) {
|
||||
this.contextMeta = {
|
||||
calibrationRatio: Math.round(ratio * 1000) / 1000,
|
||||
encoding: this.getEncoding(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const attachments = await this.awaitMemoryWithTimeout(memoryPromise);
|
||||
if (attachments && attachments.length > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue