mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(stats): Use request model as fallback for stats logging (#8423)
This commit is contained in:
@@ -299,6 +299,17 @@ describe('converter', () => {
|
||||
codeAssistRes.response.automaticFunctionCallingHistory,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle modelVersion', () => {
|
||||
const codeAssistRes: CaGenerateContentResponse = {
|
||||
response: {
|
||||
candidates: [],
|
||||
modelVersion: 'gemini-2.5-pro',
|
||||
},
|
||||
};
|
||||
const genaiRes = fromGenerateContentResponse(codeAssistRes);
|
||||
expect(genaiRes.modelVersion).toEqual('gemini-2.5-pro');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toContents', () => {
|
||||
|
||||
@@ -80,6 +80,7 @@ interface VertexGenerateContentResponse {
|
||||
automaticFunctionCallingHistory?: Content[];
|
||||
promptFeedback?: GenerateContentResponsePromptFeedback;
|
||||
usageMetadata?: GenerateContentResponseUsageMetadata;
|
||||
modelVersion?: string;
|
||||
}
|
||||
|
||||
export interface CaCountTokenRequest {
|
||||
@@ -137,6 +138,7 @@ export function fromGenerateContentResponse(
|
||||
out.automaticFunctionCallingHistory = inres.automaticFunctionCallingHistory;
|
||||
out.promptFeedback = inres.promptFeedback;
|
||||
out.usageMetadata = inres.usageMetadata;
|
||||
out.modelVersion = inres.modelVersion;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ export class LoggingContentGenerator implements ContentGenerator {
|
||||
const durationMs = Date.now() - startTime;
|
||||
this._logApiResponse(
|
||||
durationMs,
|
||||
response.modelVersion || '',
|
||||
response.modelVersion || req.model,
|
||||
userPromptId,
|
||||
response.usageMetadata,
|
||||
JSON.stringify(response),
|
||||
@@ -143,13 +143,19 @@ export class LoggingContentGenerator implements ContentGenerator {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return this.loggingStreamWrapper(stream, startTime, userPromptId);
|
||||
return this.loggingStreamWrapper(
|
||||
stream,
|
||||
startTime,
|
||||
userPromptId,
|
||||
req.model,
|
||||
);
|
||||
}
|
||||
|
||||
private async *loggingStreamWrapper(
|
||||
stream: AsyncGenerator<GenerateContentResponse>,
|
||||
startTime: number,
|
||||
userPromptId: string,
|
||||
model: string,
|
||||
): AsyncGenerator<GenerateContentResponse> {
|
||||
const responses: GenerateContentResponse[] = [];
|
||||
|
||||
@@ -166,7 +172,7 @@ export class LoggingContentGenerator implements ContentGenerator {
|
||||
const durationMs = Date.now() - startTime;
|
||||
this._logApiResponse(
|
||||
durationMs,
|
||||
responses[0]?.modelVersion || '',
|
||||
responses[0]?.modelVersion || model,
|
||||
userPromptId,
|
||||
lastUsageMetadata,
|
||||
JSON.stringify(responses),
|
||||
@@ -176,7 +182,7 @@ export class LoggingContentGenerator implements ContentGenerator {
|
||||
this._logApiError(
|
||||
durationMs,
|
||||
error,
|
||||
responses[0]?.modelVersion || '',
|
||||
responses[0]?.modelVersion || model,
|
||||
userPromptId,
|
||||
);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user