@google/genai 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,11 +46,11 @@ declare class ApiClient {
46
46
  private shouldPrependVertexProjectPath;
47
47
  request(request: HttpRequest): Promise<HttpResponse>;
48
48
  private patchHttpOptions;
49
- requestStream(request: HttpRequest): Promise<any>;
49
+ requestStream(request: HttpRequest): Promise<AsyncGenerator<HttpResponse>>;
50
50
  private includeExtraHttpOptionsToRequestInit;
51
51
  private unaryApiCall;
52
52
  private streamApiCall;
53
- processStreamResponse(response: Response): AsyncGenerator<any>;
53
+ processStreamResponse(response: Response): AsyncGenerator<HttpResponse>;
54
54
  private apiCall;
55
55
  getDefaultHeaders(): Record<string, string>;
56
56
  private getHeadersInternal;
@@ -237,8 +237,8 @@ export declare class Caches extends BaseModule {
237
237
  *
238
238
  * @remarks
239
239
  * Context caching is only supported for specific models. See [Gemini
240
- * Developer API reference] (https://ai.google.dev/gemini-api/docs/caching?lang=node/context-cac)
241
- * and [Vertex AI reference] (https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview#supported_models)
240
+ * Developer API reference](https://ai.google.dev/gemini-api/docs/caching?lang=node/context-cac)
241
+ * and [Vertex AI reference](https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview#supported_models)
242
242
  * for more information.
243
243
  *
244
244
  * @param params - The parameters for the create request.
@@ -540,7 +540,7 @@ export declare interface ContentEmbeddingStatistics {
540
540
  tokenCount?: number;
541
541
  }
542
542
 
543
- export declare type ContentListUnion = ContentUnion[] | ContentUnion;
543
+ export declare type ContentListUnion = Content | Content[] | PartUnion | PartUnion[];
544
544
 
545
545
  export declare type ContentUnion = Content | PartUnion[] | PartUnion;
546
546
 
@@ -897,6 +897,14 @@ export declare interface ExecutableCode {
897
897
  language?: Language;
898
898
  }
899
899
 
900
+ /** Options for feature selection preference. */
901
+ export declare enum FeatureSelectionPreference {
902
+ FEATURE_SELECTION_PREFERENCE_UNSPECIFIED = "FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",
903
+ PRIORITIZE_QUALITY = "PRIORITIZE_QUALITY",
904
+ BALANCED = "BALANCED",
905
+ PRIORITIZE_COST = "PRIORITIZE_COST"
906
+ }
907
+
900
908
  export declare interface FetchPredictOperationConfig {
901
909
  /** Used to override HTTP request options. */
902
910
  httpOptions?: HttpOptions;
@@ -1239,6 +1247,9 @@ export declare interface GenerateContentConfig {
1239
1247
  /** Configuration for model router requests.
1240
1248
  */
1241
1249
  routingConfig?: GenerationConfigRoutingConfig;
1250
+ /** Configuration for model selection.
1251
+ */
1252
+ modelSelectionConfig?: ModelSelectionConfig;
1242
1253
  /** Safety settings in the request to block unsafe content in the
1243
1254
  response.
1244
1255
  */
@@ -2140,17 +2151,20 @@ export declare class Live {
2140
2151
  @experimental
2141
2152
 
2142
2153
  @remarks
2143
- If using the Gemini API, Live is currently only supported behind API
2144
- version `v1alpha`. Ensure that the API version is set to `v1alpha` when
2145
- initializing the SDK if relying on the Gemini API.
2146
2154
 
2147
2155
  @param params - The parameters for establishing a connection to the model.
2148
2156
  @return A live session.
2149
2157
 
2150
2158
  @example
2151
2159
  ```ts
2160
+ let model: string;
2161
+ if (GOOGLE_GENAI_USE_VERTEXAI) {
2162
+ model = 'gemini-2.0-flash-live-preview-04-09';
2163
+ } else {
2164
+ model = 'gemini-2.0-flash-live-001';
2165
+ }
2152
2166
  const session = await ai.live.connect({
2153
- model: 'gemini-2.0-flash-exp',
2167
+ model: model,
2154
2168
  config: {
2155
2169
  responseModalities: [Modality.AUDIO],
2156
2170
  },
@@ -2265,7 +2279,7 @@ export declare interface LiveClientSetup {
2265
2279
  /** The user provided system instructions for the model.
2266
2280
  Note: only text should be used in parts and content in each part will be
2267
2281
  in a separate paragraph. */
2268
- systemInstruction?: Content;
2282
+ systemInstruction?: ContentUnion;
2269
2283
  /** A list of `Tools` the model may use to generate the next response.
2270
2284
 
2271
2285
  A `Tool` is a piece of code that enables the system to interact with
@@ -2282,6 +2296,13 @@ export declare interface LiveClientSetup {
2282
2296
 
2283
2297
  If included, server will compress context window to fit into given length. */
2284
2298
  contextWindowCompression?: ContextWindowCompressionConfig;
2299
+ /** The transcription of the input aligns with the input audio language.
2300
+ */
2301
+ inputAudioTranscription?: AudioTranscriptionConfig;
2302
+ /** The transcription of the output aligns with the language code
2303
+ specified for the output audio.
2304
+ */
2305
+ outputAudioTranscription?: AudioTranscriptionConfig;
2285
2306
  }
2286
2307
 
2287
2308
  /** Client generated response to a `ToolCall` received from the server.
@@ -2307,13 +2328,42 @@ export declare interface LiveConnectConfig {
2307
2328
  modalities that the model can return. Defaults to AUDIO if not specified.
2308
2329
  */
2309
2330
  responseModalities?: Modality[];
2331
+ /** Value that controls the degree of randomness in token selection.
2332
+ Lower temperatures are good for prompts that require a less open-ended or
2333
+ creative response, while higher temperatures can lead to more diverse or
2334
+ creative results.
2335
+ */
2336
+ temperature?: number;
2337
+ /** Tokens are selected from the most to least probable until the sum
2338
+ of their probabilities equals this value. Use a lower value for less
2339
+ random responses and a higher value for more random responses.
2340
+ */
2341
+ topP?: number;
2342
+ /** For each token selection step, the ``top_k`` tokens with the
2343
+ highest probabilities are sampled. Then tokens are further filtered based
2344
+ on ``top_p`` with the final token selected using temperature sampling. Use
2345
+ a lower number for less random responses and a higher number for more
2346
+ random responses.
2347
+ */
2348
+ topK?: number;
2349
+ /** Maximum number of tokens that can be generated in the response.
2350
+ */
2351
+ maxOutputTokens?: number;
2352
+ /** If specified, the media resolution specified will be used.
2353
+ */
2354
+ mediaResolution?: MediaResolution;
2355
+ /** When ``seed`` is fixed to a specific number, the model makes a best
2356
+ effort to provide the same response for repeated requests. By default, a
2357
+ random number is used.
2358
+ */
2359
+ seed?: number;
2310
2360
  /** The speech generation configuration.
2311
2361
  */
2312
2362
  speechConfig?: SpeechConfig;
2313
2363
  /** The user provided system instructions for the model.
2314
2364
  Note: only text should be used in parts and content in each part will be
2315
2365
  in a separate paragraph. */
2316
- systemInstruction?: Content;
2366
+ systemInstruction?: ContentUnion;
2317
2367
  /** A list of `Tools` the model may use to generate the next response.
2318
2368
 
2319
2369
  A `Tool` is a piece of code that enables the system to interact with
@@ -2324,6 +2374,13 @@ export declare interface LiveConnectConfig {
2324
2374
 
2325
2375
  If included the server will send SessionResumptionUpdate messages. */
2326
2376
  sessionResumption?: SessionResumptionConfig;
2377
+ /** The transcription of the input aligns with the input audio language.
2378
+ */
2379
+ inputAudioTranscription?: AudioTranscriptionConfig;
2380
+ /** The transcription of the output aligns with the language code
2381
+ specified for the output audio.
2382
+ */
2383
+ outputAudioTranscription?: AudioTranscriptionConfig;
2327
2384
  /** Configures the realtime input behavior in BidiGenerateContent. */
2328
2385
  realtimeInputConfig?: RealtimeInputConfig;
2329
2386
  /** Configures context window compression mechanism.
@@ -2391,6 +2448,15 @@ export declare interface LiveServerContent {
2391
2448
  has finished generating all content. This is a signal to the client
2392
2449
  that it can stop sending messages. */
2393
2450
  generationComplete?: boolean;
2451
+ /** Input transcription. The transcription is independent to the model
2452
+ turn which means it doesn’t imply any ordering between transcription and
2453
+ model turn. */
2454
+ inputTranscription?: Transcription;
2455
+ /** Output transcription. The transcription is independent to the model
2456
+ turn which means it doesn’t imply any ordering between transcription and
2457
+ model turn.
2458
+ */
2459
+ outputTranscription?: Transcription;
2394
2460
  }
2395
2461
 
2396
2462
  /** Server will not be able to service client soon. */
@@ -2811,6 +2877,12 @@ export declare class Models extends BaseModule {
2811
2877
  generateVideos(params: types.GenerateVideosParameters): Promise<types.GenerateVideosOperation>;
2812
2878
  }
2813
2879
 
2880
+ /** Config for model selection. */
2881
+ export declare interface ModelSelectionConfig {
2882
+ /** Options for feature selection preference. */
2883
+ featureSelectionPreference?: FeatureSelectionPreference;
2884
+ }
2885
+
2814
2886
  /** Parameters for the get method of the operations module. */
2815
2887
  export declare interface OperationGetParameters {
2816
2888
  /** The operation to be retrieved. */
@@ -3018,6 +3090,54 @@ export declare interface PrebuiltVoiceConfig {
3018
3090
  voiceName?: string;
3019
3091
  }
3020
3092
 
3093
+ /** Specifies the context retrieval config. */
3094
+ export declare interface RagRetrievalConfig {
3095
+ /** Optional. Config for filters. */
3096
+ filter?: RagRetrievalConfigFilter;
3097
+ /** Optional. Config for Hybrid Search. */
3098
+ hybridSearch?: RagRetrievalConfigHybridSearch;
3099
+ /** Optional. Config for ranking and reranking. */
3100
+ ranking?: RagRetrievalConfigRanking;
3101
+ /** Optional. The number of contexts to retrieve. */
3102
+ topK?: number;
3103
+ }
3104
+
3105
+ /** Config for filters. */
3106
+ export declare interface RagRetrievalConfigFilter {
3107
+ /** Optional. String for metadata filtering. */
3108
+ metadataFilter?: string;
3109
+ /** Optional. Only returns contexts with vector distance smaller than the threshold. */
3110
+ vectorDistanceThreshold?: number;
3111
+ /** Optional. Only returns contexts with vector similarity larger than the threshold. */
3112
+ vectorSimilarityThreshold?: number;
3113
+ }
3114
+
3115
+ /** Config for Hybrid Search. */
3116
+ export declare interface RagRetrievalConfigHybridSearch {
3117
+ /** Optional. Alpha value controls the weight between dense and sparse vector search results. The range is [0, 1], while 0 means sparse vector search only and 1 means dense vector search only. The default value is 0.5 which balances sparse and dense vector search equally. */
3118
+ alpha?: number;
3119
+ }
3120
+
3121
+ /** Config for ranking and reranking. */
3122
+ export declare interface RagRetrievalConfigRanking {
3123
+ /** Optional. Config for LlmRanker. */
3124
+ llmRanker?: RagRetrievalConfigRankingLlmRanker;
3125
+ /** Optional. Config for Rank Service. */
3126
+ rankService?: RagRetrievalConfigRankingRankService;
3127
+ }
3128
+
3129
+ /** Config for LlmRanker. */
3130
+ export declare interface RagRetrievalConfigRankingLlmRanker {
3131
+ /** Optional. The model name used for ranking. Format: `gemini-1.5-pro` */
3132
+ modelName?: string;
3133
+ }
3134
+
3135
+ /** Config for Rank Service. */
3136
+ export declare interface RagRetrievalConfigRankingRankService {
3137
+ /** Optional. The model name of the rank service. Format: `semantic-ranker-512@latest` */
3138
+ modelName?: string;
3139
+ }
3140
+
3021
3141
  /** A raw reference image.
3022
3142
 
3023
3143
  A raw reference image represents the base image to edit, provided by the user.
@@ -3340,8 +3460,14 @@ export declare class Session {
3340
3460
 
3341
3461
  @example
3342
3462
  ```ts
3463
+ let model: string;
3464
+ if (GOOGLE_GENAI_USE_VERTEXAI) {
3465
+ model = 'gemini-2.0-flash-live-preview-04-09';
3466
+ } else {
3467
+ model = 'gemini-2.0-flash-live-001';
3468
+ }
3343
3469
  const session = await ai.live.connect({
3344
- model: 'gemini-2.0-flash-exp',
3470
+ model: model,
3345
3471
  config: {
3346
3472
  responseModalities: [Modality.AUDIO],
3347
3473
  }
@@ -3384,6 +3510,10 @@ export declare interface SpeechConfig {
3384
3510
  /** The configuration for the speaker to use.
3385
3511
  */
3386
3512
  voiceConfig?: VoiceConfig;
3513
+ /** Language code (ISO 639. e.g. en-US) for the speech synthesization.
3514
+ Only available for Live API.
3515
+ */
3516
+ languageCode?: string;
3387
3517
  }
3388
3518
 
3389
3519
  export declare type SpeechConfigUnion = SpeechConfig | string;
@@ -3538,6 +3668,16 @@ export declare enum TrafficType {
3538
3668
  PROVISIONED_THROUGHPUT = "PROVISIONED_THROUGHPUT"
3539
3669
  }
3540
3670
 
3671
+ /** Audio transcription in Server Conent. */
3672
+ export declare interface Transcription {
3673
+ /** Transcription text.
3674
+ */
3675
+ text?: string;
3676
+ /** The bool indicates the end of the transcription.
3677
+ */
3678
+ finished?: boolean;
3679
+ }
3680
+
3541
3681
  /** A tuned machine learning model. */
3542
3682
  export declare interface TunedModelInfo {
3543
3683
  /** ID of the base model that you want to tune. */
@@ -3591,6 +3731,7 @@ declare namespace types {
3591
3731
  TrafficType,
3592
3732
  Modality,
3593
3733
  MediaResolution,
3734
+ FeatureSelectionPreference,
3594
3735
  DynamicRetrievalConfigMode,
3595
3736
  FunctionCallingConfigMode,
3596
3737
  SafetyFilterLevel,
@@ -3617,6 +3758,7 @@ declare namespace types {
3617
3758
  Content,
3618
3759
  HttpOptions,
3619
3760
  Schema,
3761
+ ModelSelectionConfig,
3620
3762
  SafetySetting,
3621
3763
  FunctionDeclaration,
3622
3764
  GoogleSearch,
@@ -3624,6 +3766,12 @@ declare namespace types {
3624
3766
  GoogleSearchRetrieval,
3625
3767
  VertexAISearch,
3626
3768
  VertexRagStoreRagResource,
3769
+ RagRetrievalConfigFilter,
3770
+ RagRetrievalConfigHybridSearch,
3771
+ RagRetrievalConfigRankingLlmRanker,
3772
+ RagRetrievalConfigRankingRankService,
3773
+ RagRetrievalConfigRanking,
3774
+ RagRetrievalConfig,
3627
3775
  VertexRagStore,
3628
3776
  Retrieval,
3629
3777
  ToolCodeExecution,
@@ -3744,6 +3892,7 @@ declare namespace types {
3744
3892
  SubjectReferenceConfig,
3745
3893
  SubjectReferenceImage,
3746
3894
  LiveServerSetupComplete,
3895
+ Transcription,
3747
3896
  LiveServerContent,
3748
3897
  LiveServerToolCall,
3749
3898
  LiveServerToolCallCancellation,
@@ -3756,6 +3905,7 @@ declare namespace types {
3756
3905
  SessionResumptionConfig,
3757
3906
  SlidingWindow,
3758
3907
  ContextWindowCompressionConfig,
3908
+ AudioTranscriptionConfig,
3759
3909
  LiveClientSetup,
3760
3910
  LiveClientContent,
3761
3911
  ActivityStart,
@@ -3763,7 +3913,6 @@ declare namespace types {
3763
3913
  LiveClientRealtimeInput,
3764
3914
  LiveClientToolResponse,
3765
3915
  LiveClientMessage,
3766
- AudioTranscriptionConfig,
3767
3916
  LiveConnectConfig,
3768
3917
  LiveConnectParameters,
3769
3918
  CreateChatParameters,
@@ -3916,6 +4065,8 @@ export declare interface VertexRagStore {
3916
4065
  ragCorpora?: string[];
3917
4066
  /** Optional. The representation of the rag source. It can be used to specify corpus only or ragfiles. Currently only support one corpus or multiple files from one corpus. In the future we may open up multiple corpora support. */
3918
4067
  ragResources?: VertexRagStoreRagResource[];
4068
+ /** Optional. The retrieval config for the Rag query. */
4069
+ ragRetrievalConfig?: RagRetrievalConfig;
3919
4070
  /** Optional. Number of top k results to return from the selected corpora. */
3920
4071
  similarityTopK?: number;
3921
4072
  /** Optional. Only return results with vector distance smaller than the threshold. */