Skip to content

Commit 36095a9

Browse files
committed
some refacotor
1 parent f79ba78 commit 36095a9

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

packages/core/src/utils/ai/gen-ai-attributes.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,3 @@ export const OPENAI_OPERATIONS = {
178178
* The response timestamp from Anthropic AI (ISO string)
179179
*/
180180
export const ANTHROPIC_AI_RESPONSE_TIMESTAMP_ATTRIBUTE = 'anthropic.response.timestamp';
181-
182-
// =============================================================================
183-
// GOOGLE GENAI OPERATIONS
184-
// =============================================================================
185-
186-
/**
187-
* Google GenAI API operations
188-
*/
189-
export const GOOGLE_GENAI_OPERATIONS = {
190-
GENERATE_CONTENT: 'generateContent',
191-
STREAM_GENERATE_CONTENT: 'streamGenerateContent',
192-
} as const;

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ export function extractModel(params: Record<string, unknown>, context?: unknown)
4747
return params.model;
4848
}
4949

50-
// For chat instances, try to get the model from the chat context
51-
// This is because the model is set during chat creation
52-
// and not passed as a parameter to the chat.sendMessage method
50+
// We retrieve the model from the chat context
51+
// because the model is defined when the chat is created,
52+
// not provided as a parameter in chat.sendMessage
5353
if (context && typeof context === 'object') {
5454
const chatObj = context as Record<string, unknown>;
5555
if (chatObj[GOOGLE_GENAI_MODEL_PROPERTY] && typeof chatObj[GOOGLE_GENAI_MODEL_PROPERTY] === 'string') {
56-
return chatObj[GOOGLE_GENAI_MODEL_PROPERTY] as string;
56+
return chatObj[GOOGLE_GENAI_MODEL_PROPERTY];
5757
}
5858
}
5959

@@ -238,11 +238,12 @@ function instrumentMethod<T extends unknown[], R>(
238238
if (finalOptions.recordInputs && args[0] && typeof args[0] === 'object') {
239239
addPrivateRequestAttributes(span, args[0] as Record<string, unknown>);
240240
}
241-
const result = (originalMethod as (...args: T) => R).apply(context, args) as R;
241+
const result = (originalMethod as (...args: T) => R).apply(context, args);
242242

243243
if (typeof model === 'string' && model !== 'unknown' && typeof result === 'object') {
244-
// We store the model in the result object so that it can be accessed later
245-
// This is because the model is not passed as a parameter to the chat.sendMessage method
244+
// For chat instances, retrieve the model from the chat context.
245+
// The model is defined when the chat is created,
246+
// not provided as a parameter in chat.sendMessage.
246247
(result as Record<string, unknown>)[GOOGLE_GENAI_MODEL_PROPERTY] = model;
247248
}
248249

@@ -255,7 +256,7 @@ function instrumentMethod<T extends unknown[], R>(
255256
throw error;
256257
}
257258
},
258-
) as R;
259+
);
259260
}
260261

261262
// Async/content-producing path
@@ -273,15 +274,15 @@ function instrumentMethod<T extends unknown[], R>(
273274

274275
const result = await Promise.resolve((originalMethod as (...args: T) => Promise<R>).apply(context, args));
275276
addResponseAttributes(span, result as GoogleGenAIResponse, finalOptions.recordOutputs);
276-
return result as R;
277+
return result;
277278
} catch (error) {
278279
captureException(error, {
279280
mechanism: { handled: false, type: 'auto.ai.google_genai', data: { function: methodPath } },
280281
});
281282
throw error;
282283
}
283284
},
284-
) as Promise<R>;
285+
);
285286
};
286287

287288
return run;

0 commit comments

Comments
 (0)