66 type GenerateContentConfig ,
77 type GroundingMetadata ,
88 FunctionCallingConfigMode ,
9- Content ,
109} from "@google/genai"
1110import type { JWTInput } from "google-auth-library"
1211
@@ -15,7 +14,7 @@ import { type ModelInfo, type GeminiModelId, geminiDefaultModelId, geminiModels
1514import type { ApiHandlerOptions } from "../../shared/api"
1615import { safeJsonParse } from "../../shared/safeJsonParse"
1716
18- import { convertAnthropicContentToGemini , convertAnthropicMessageToGemini } from "../transform/gemini-format"
17+ import { convertAnthropicMessageToGemini } from "../transform/gemini-format"
1918import { t } from "i18next"
2019import type { ApiStream , GroundingSource } from "../transform/stream"
2120import { getModelParams } from "../transform/model-params"
@@ -431,30 +430,6 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
431430 }
432431 }
433432
434- override async countTokens ( content : Array < Anthropic . Messages . ContentBlockParam > ) : Promise < number > {
435- try {
436- const { id : model } = this . getModel ( )
437-
438- const countTokensRequest = {
439- model,
440- // Token counting does not need encrypted continuation; always drop thoughtSignature.
441- contents : convertAnthropicContentToGemini ( content , { includeThoughtSignatures : false } ) ,
442- }
443-
444- const response = await this . client . models . countTokens ( countTokensRequest )
445-
446- if ( response . totalTokens === undefined ) {
447- console . warn ( "Gemini token counting returned undefined, using fallback" )
448- return super . countTokens ( content )
449- }
450-
451- return response . totalTokens
452- } catch ( error ) {
453- console . warn ( "Gemini token counting failed, using fallback" , error )
454- return super . countTokens ( content )
455- }
456- }
457-
458433 public getThoughtSignature ( ) : string | undefined {
459434 return this . lastThoughtSignature
460435 }
0 commit comments