mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-03 06:40:20 +01:00
🪙 feat: Add messageId to Transactions (#11987)
* feat: Add messageId to transactions * chore: field order * feat: Enhance token usage tracking by adding messageId parameter - Updated `recordTokenUsage` method in BaseClient to accept a new `messageId` parameter for improved tracking. - Propagated `messageId` in the AgentClient when recording usage. - Added tests to ensure `messageId` is correctly passed and handled in various scenarios, including propagation across multiple usage entries. * chore: Correct field order in createGeminiImageTool function - Moved the conversationId field to the correct position in the object being passed to the recordTokenUsage method, ensuring proper parameter alignment for improved functionality. * refactor: Update OpenAIChatCompletionController and createResponse to use responseId instead of requestId - Replaced instances of requestId with responseId in the OpenAIChatCompletionController for improved clarity in logging and tracking. - Updated createResponse to include responseId in the requestBody, ensuring consistency across the handling of message identifiers. * test: Add messageId to agent client tests - Included messageId in the agent client tests to ensure proper handling and propagation of message identifiers during transaction recording. - This update enhances the test coverage for scenarios involving messageId, aligning with recent changes in the tracking of message identifiers. * fix: Update OpenAIChatCompletionController to use requestId for context - Changed the context object in OpenAIChatCompletionController to use `requestId` instead of `responseId` for improved clarity and consistency in handling request identifiers. * chore: field order
This commit is contained in:
parent
6169d4f70b
commit
8b159079f5
10 changed files with 149 additions and 13 deletions
|
|
@ -27,8 +27,15 @@ const { abortRun } = require('./abortRun');
|
|||
* @param {string} params.conversationId - Conversation ID
|
||||
* @param {Array<Object>} params.collectedUsage - Usage metadata from all models
|
||||
* @param {string} [params.fallbackModel] - Fallback model name if not in usage
|
||||
* @param {string} [params.messageId] - The response message ID for transaction correlation
|
||||
*/
|
||||
async function spendCollectedUsage({ userId, conversationId, collectedUsage, fallbackModel }) {
|
||||
async function spendCollectedUsage({
|
||||
userId,
|
||||
conversationId,
|
||||
collectedUsage,
|
||||
fallbackModel,
|
||||
messageId,
|
||||
}) {
|
||||
if (!collectedUsage || collectedUsage.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -50,6 +57,7 @@ async function spendCollectedUsage({ userId, conversationId, collectedUsage, fal
|
|||
|
||||
const txMetadata = {
|
||||
context: 'abort',
|
||||
messageId,
|
||||
conversationId,
|
||||
user: userId,
|
||||
model: usage.model ?? fallbackModel,
|
||||
|
|
@ -144,6 +152,7 @@ async function abortMessage(req, res) {
|
|||
conversationId: jobData?.conversationId,
|
||||
collectedUsage,
|
||||
fallbackModel: jobData?.model,
|
||||
messageId: jobData?.responseMessageId,
|
||||
});
|
||||
} else {
|
||||
// Fallback: no collected usage, use text-based token counting for primary model only
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue