Skip to content

Commit f6f5dac

Browse files
committed
update
1 parent 7932dba commit f6f5dac

File tree

1 file changed

+7
-11
lines changed
  • packages/core/src/utils/google-genai

1 file changed

+7
-11
lines changed

packages/core/src/utils/google-genai/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
2323
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
2424
} from '../ai/gen-ai-attributes';
25+
import { filterMediaFromMessages } from '../ai/mediaFiltering';
2526
import { buildMethodPath, getFinalOperationName, getSpanOperation } from '../ai/utils';
2627
import { handleCallbackErrors } from '../handleCallbackErrors';
2728
import { CHAT_PATH, CHATS_CREATE_METHOD, GOOGLE_GENAI_SYSTEM_NAME } from './constants';
@@ -128,25 +129,20 @@ function extractRequestAttributes(
128129
return attributes;
129130
}
130131

131-
/**
132-
* Add private request attributes to spans.
133-
* This is only recorded if recordInputs is true.
134-
* Handles different parameter formats for different Google GenAI methods.
135-
*/
136132
function addPrivateRequestAttributes(span: Span, params: Record<string, unknown>): void {
137-
// For models.generateContent: ContentListUnion: Content | Content[] | PartUnion | PartUnion[]
138133
if ('contents' in params) {
139-
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(params.contents) });
134+
const filtered = filterMediaFromMessages(params.contents);
135+
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(filtered) });
140136
}
141137

142-
// For chat.sendMessage: message can be string or Part[]
143138
if ('message' in params) {
144-
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(params.message) });
139+
const filtered = filterMediaFromMessages(params.message);
140+
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(filtered) });
145141
}
146142

147-
// For chats.create: history contains the conversation history
148143
if ('history' in params) {
149-
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(params.history) });
144+
const filtered = filterMediaFromMessages(params.history);
145+
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(filtered) });
150146
}
151147
}
152148

0 commit comments

Comments
 (0)