Skip to content

Commit 02d2b96

Browse files
committed
Add truncation
1 parent 7d92384 commit 02d2b96

File tree

1 file changed

+3
-1
lines changed
  • packages/core/src/utils/langchain

1 file changed

+3
-1
lines changed

packages/core/src/utils/langchain/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
2424
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
2525
} from '../ai/gen-ai-attributes';
26+
import { truncateGenAiMessages } from '../ai/messageTruncation';
2627
import { LANGCHAIN_ORIGIN, ROLE_MAP } from './constants';
2728
import type { LangChainLLMResult, LangChainMessage, LangChainSerialized } from './types';
2829

@@ -281,7 +282,8 @@ export function extractChatModelRequestAttributes(
281282

282283
if (recordInputs && Array.isArray(langChainMessages) && langChainMessages.length > 0) {
283284
const normalized = normalizeLangChainMessages(langChainMessages.flat());
284-
setIfDefined(attrs, GEN_AI_REQUEST_MESSAGES_ATTRIBUTE, asString(normalized));
285+
const truncated = truncateGenAiMessages(normalized);
286+
setIfDefined(attrs, GEN_AI_REQUEST_MESSAGES_ATTRIBUTE, asString(truncated));
285287
}
286288

287289
return attrs;

0 commit comments

Comments
 (0)