mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-09 17:31:19 +00:00
refactor(agents): remove unused tokenCountMap and streamline calibration ratio handling
Eliminated the unused tokenCountMap variable from the AgentClient class to enhance code clarity. Additionally, streamlined the logic for capturing the calibration ratio by using optional chaining and a fallback value, ensuring that context metadata is consistently defined. This change improves maintainability and reduces potential confusion in the codebase.
This commit is contained in:
parent
07f1998109
commit
1bfc9bfa3a
1 changed files with 8 additions and 12 deletions
|
|
@ -329,9 +329,6 @@ class AgentClient extends BaseClient {
|
|||
|
||||
const sharedRunContext = sharedRunContextParts.join('\n\n');
|
||||
|
||||
/** @type {Record<string, number> | undefined} */
|
||||
let tokenCountMap;
|
||||
|
||||
/** Preserve canonical pre-format token counts for all history entering graph formatting */
|
||||
this.indexTokenCountMap = canonicalTokenCountMap;
|
||||
|
||||
|
|
@ -344,7 +341,6 @@ class AgentClient extends BaseClient {
|
|||
}
|
||||
|
||||
const result = {
|
||||
tokenCountMap,
|
||||
prompt: payload,
|
||||
promptTokens,
|
||||
messages,
|
||||
|
|
@ -907,14 +903,14 @@ 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(),
|
||||
};
|
||||
}
|
||||
const ratio = this.run?.getCalibrationRatio() ?? 0;
|
||||
if (ratio > 0 && ratio !== 1) {
|
||||
this.contextMeta = {
|
||||
calibrationRatio: Math.round(ratio * 1000) / 1000,
|
||||
encoding: this.getEncoding(),
|
||||
};
|
||||
} else {
|
||||
this.contextMeta = undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue