@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.
package/dist/web/web.d.ts CHANGED
@@ -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
  */
@@ -2133,17 +2144,20 @@ export declare class Live {
2133
2144
  @experimental
2134
2145
 
2135
2146
  @remarks
2136
- If using the Gemini API, Live is currently only supported behind API
2137
- version `v1alpha`. Ensure that the API version is set to `v1alpha` when
2138
- initializing the SDK if relying on the Gemini API.
2139
2147
 
2140
2148
  @param params - The parameters for establishing a connection to the model.
2141
2149
  @return A live session.
2142
2150
 
2143
2151
  @example
2144
2152
  ```ts
2153
+ let model: string;
2154
+ if (GOOGLE_GENAI_USE_VERTEXAI) {
2155
+ model = 'gemini-2.0-flash-live-preview-04-09';
2156
+ } else {
2157
+ model = 'gemini-2.0-flash-live-001';
2158
+ }
2145
2159
  const session = await ai.live.connect({
2146
- model: 'gemini-2.0-flash-exp',
2160
+ model: model,
2147
2161
  config: {
2148
2162
  responseModalities: [Modality.AUDIO],
2149
2163
  },
@@ -2258,7 +2272,7 @@ export declare interface LiveClientSetup {
2258
2272
  /** The user provided system instructions for the model.
2259
2273
  Note: only text should be used in parts and content in each part will be
2260
2274
  in a separate paragraph. */
2261
- systemInstruction?: Content;
2275
+ systemInstruction?: ContentUnion;
2262
2276
  /** A list of `Tools` the model may use to generate the next response.
2263
2277
 
2264
2278
  A `Tool` is a piece of code that enables the system to interact with
@@ -2275,6 +2289,13 @@ export declare interface LiveClientSetup {
2275
2289
 
2276
2290
  If included, server will compress context window to fit into given length. */
2277
2291
  contextWindowCompression?: ContextWindowCompressionConfig;
2292
+ /** The transcription of the input aligns with the input audio language.
2293
+ */
2294
+ inputAudioTranscription?: AudioTranscriptionConfig;
2295
+ /** The transcription of the output aligns with the language code
2296
+ specified for the output audio.
2297
+ */
2298
+ outputAudioTranscription?: AudioTranscriptionConfig;
2278
2299
  }
2279
2300
 
2280
2301
  /** Client generated response to a `ToolCall` received from the server.
@@ -2300,13 +2321,42 @@ export declare interface LiveConnectConfig {
2300
2321
  modalities that the model can return. Defaults to AUDIO if not specified.
2301
2322
  */
2302
2323
  responseModalities?: Modality[];
2324
+ /** Value that controls the degree of randomness in token selection.
2325
+ Lower temperatures are good for prompts that require a less open-ended or
2326
+ creative response, while higher temperatures can lead to more diverse or
2327
+ creative results.
2328
+ */
2329
+ temperature?: number;
2330
+ /** Tokens are selected from the most to least probable until the sum
2331
+ of their probabilities equals this value. Use a lower value for less
2332
+ random responses and a higher value for more random responses.
2333
+ */
2334
+ topP?: number;
2335
+ /** For each token selection step, the ``top_k`` tokens with the
2336
+ highest probabilities are sampled. Then tokens are further filtered based
2337
+ on ``top_p`` with the final token selected using temperature sampling. Use
2338
+ a lower number for less random responses and a higher number for more
2339
+ random responses.
2340
+ */
2341
+ topK?: number;
2342
+ /** Maximum number of tokens that can be generated in the response.
2343
+ */
2344
+ maxOutputTokens?: number;
2345
+ /** If specified, the media resolution specified will be used.
2346
+ */
2347
+ mediaResolution?: MediaResolution;
2348
+ /** When ``seed`` is fixed to a specific number, the model makes a best
2349
+ effort to provide the same response for repeated requests. By default, a
2350
+ random number is used.
2351
+ */
2352
+ seed?: number;
2303
2353
  /** The speech generation configuration.
2304
2354
  */
2305
2355
  speechConfig?: SpeechConfig;
2306
2356
  /** The user provided system instructions for the model.
2307
2357
  Note: only text should be used in parts and content in each part will be
2308
2358
  in a separate paragraph. */
2309
- systemInstruction?: Content;
2359
+ systemInstruction?: ContentUnion;
2310
2360
  /** A list of `Tools` the model may use to generate the next response.
2311
2361
 
2312
2362
  A `Tool` is a piece of code that enables the system to interact with
@@ -2317,6 +2367,13 @@ export declare interface LiveConnectConfig {
2317
2367
 
2318
2368
  If included the server will send SessionResumptionUpdate messages. */
2319
2369
  sessionResumption?: SessionResumptionConfig;
2370
+ /** The transcription of the input aligns with the input audio language.
2371
+ */
2372
+ inputAudioTranscription?: AudioTranscriptionConfig;
2373
+ /** The transcription of the output aligns with the language code
2374
+ specified for the output audio.
2375
+ */
2376
+ outputAudioTranscription?: AudioTranscriptionConfig;
2320
2377
  /** Configures the realtime input behavior in BidiGenerateContent. */
2321
2378
  realtimeInputConfig?: RealtimeInputConfig;
2322
2379
  /** Configures context window compression mechanism.
@@ -2384,6 +2441,15 @@ export declare interface LiveServerContent {
2384
2441
  has finished generating all content. This is a signal to the client
2385
2442
  that it can stop sending messages. */
2386
2443
  generationComplete?: boolean;
2444
+ /** Input transcription. The transcription is independent to the model
2445
+ turn which means it doesn’t imply any ordering between transcription and
2446
+ model turn. */
2447
+ inputTranscription?: Transcription;
2448
+ /** Output transcription. The transcription is independent to the model
2449
+ turn which means it doesn’t imply any ordering between transcription and
2450
+ model turn.
2451
+ */
2452
+ outputTranscription?: Transcription;
2387
2453
  }
2388
2454
 
2389
2455
  /** Server will not be able to service client soon. */
@@ -2804,6 +2870,12 @@ export declare class Models extends BaseModule {
2804
2870
  generateVideos(params: types.GenerateVideosParameters): Promise<types.GenerateVideosOperation>;
2805
2871
  }
2806
2872
 
2873
+ /** Config for model selection. */
2874
+ export declare interface ModelSelectionConfig {
2875
+ /** Options for feature selection preference. */
2876
+ featureSelectionPreference?: FeatureSelectionPreference;
2877
+ }
2878
+
2807
2879
  /** Parameters for the get method of the operations module. */
2808
2880
  export declare interface OperationGetParameters {
2809
2881
  /** The operation to be retrieved. */
@@ -3011,6 +3083,54 @@ export declare interface PrebuiltVoiceConfig {
3011
3083
  voiceName?: string;
3012
3084
  }
3013
3085
 
3086
+ /** Specifies the context retrieval config. */
3087
+ export declare interface RagRetrievalConfig {
3088
+ /** Optional. Config for filters. */
3089
+ filter?: RagRetrievalConfigFilter;
3090
+ /** Optional. Config for Hybrid Search. */
3091
+ hybridSearch?: RagRetrievalConfigHybridSearch;
3092
+ /** Optional. Config for ranking and reranking. */
3093
+ ranking?: RagRetrievalConfigRanking;
3094
+ /** Optional. The number of contexts to retrieve. */
3095
+ topK?: number;
3096
+ }
3097
+
3098
+ /** Config for filters. */
3099
+ export declare interface RagRetrievalConfigFilter {
3100
+ /** Optional. String for metadata filtering. */
3101
+ metadataFilter?: string;
3102
+ /** Optional. Only returns contexts with vector distance smaller than the threshold. */
3103
+ vectorDistanceThreshold?: number;
3104
+ /** Optional. Only returns contexts with vector similarity larger than the threshold. */
3105
+ vectorSimilarityThreshold?: number;
3106
+ }
3107
+
3108
+ /** Config for Hybrid Search. */
3109
+ export declare interface RagRetrievalConfigHybridSearch {
3110
+ /** 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. */
3111
+ alpha?: number;
3112
+ }
3113
+
3114
+ /** Config for ranking and reranking. */
3115
+ export declare interface RagRetrievalConfigRanking {
3116
+ /** Optional. Config for LlmRanker. */
3117
+ llmRanker?: RagRetrievalConfigRankingLlmRanker;
3118
+ /** Optional. Config for Rank Service. */
3119
+ rankService?: RagRetrievalConfigRankingRankService;
3120
+ }
3121
+
3122
+ /** Config for LlmRanker. */
3123
+ export declare interface RagRetrievalConfigRankingLlmRanker {
3124
+ /** Optional. The model name used for ranking. Format: `gemini-1.5-pro` */
3125
+ modelName?: string;
3126
+ }
3127
+
3128
+ /** Config for Rank Service. */
3129
+ export declare interface RagRetrievalConfigRankingRankService {
3130
+ /** Optional. The model name of the rank service. Format: `semantic-ranker-512@latest` */
3131
+ modelName?: string;
3132
+ }
3133
+
3014
3134
  /** A raw reference image.
3015
3135
 
3016
3136
  A raw reference image represents the base image to edit, provided by the user.
@@ -3333,8 +3453,14 @@ export declare class Session {
3333
3453
 
3334
3454
  @example
3335
3455
  ```ts
3456
+ let model: string;
3457
+ if (GOOGLE_GENAI_USE_VERTEXAI) {
3458
+ model = 'gemini-2.0-flash-live-preview-04-09';
3459
+ } else {
3460
+ model = 'gemini-2.0-flash-live-001';
3461
+ }
3336
3462
  const session = await ai.live.connect({
3337
- model: 'gemini-2.0-flash-exp',
3463
+ model: model,
3338
3464
  config: {
3339
3465
  responseModalities: [Modality.AUDIO],
3340
3466
  }
@@ -3377,6 +3503,10 @@ export declare interface SpeechConfig {
3377
3503
  /** The configuration for the speaker to use.
3378
3504
  */
3379
3505
  voiceConfig?: VoiceConfig;
3506
+ /** Language code (ISO 639. e.g. en-US) for the speech synthesization.
3507
+ Only available for Live API.
3508
+ */
3509
+ languageCode?: string;
3380
3510
  }
3381
3511
 
3382
3512
  export declare type SpeechConfigUnion = SpeechConfig | string;
@@ -3531,6 +3661,16 @@ export declare enum TrafficType {
3531
3661
  PROVISIONED_THROUGHPUT = "PROVISIONED_THROUGHPUT"
3532
3662
  }
3533
3663
 
3664
+ /** Audio transcription in Server Conent. */
3665
+ export declare interface Transcription {
3666
+ /** Transcription text.
3667
+ */
3668
+ text?: string;
3669
+ /** The bool indicates the end of the transcription.
3670
+ */
3671
+ finished?: boolean;
3672
+ }
3673
+
3534
3674
  /** A tuned machine learning model. */
3535
3675
  export declare interface TunedModelInfo {
3536
3676
  /** ID of the base model that you want to tune. */
@@ -3584,6 +3724,7 @@ declare namespace types {
3584
3724
  TrafficType,
3585
3725
  Modality,
3586
3726
  MediaResolution,
3727
+ FeatureSelectionPreference,
3587
3728
  DynamicRetrievalConfigMode,
3588
3729
  FunctionCallingConfigMode,
3589
3730
  SafetyFilterLevel,
@@ -3610,6 +3751,7 @@ declare namespace types {
3610
3751
  Content,
3611
3752
  HttpOptions,
3612
3753
  Schema,
3754
+ ModelSelectionConfig,
3613
3755
  SafetySetting,
3614
3756
  FunctionDeclaration,
3615
3757
  GoogleSearch,
@@ -3617,6 +3759,12 @@ declare namespace types {
3617
3759
  GoogleSearchRetrieval,
3618
3760
  VertexAISearch,
3619
3761
  VertexRagStoreRagResource,
3762
+ RagRetrievalConfigFilter,
3763
+ RagRetrievalConfigHybridSearch,
3764
+ RagRetrievalConfigRankingLlmRanker,
3765
+ RagRetrievalConfigRankingRankService,
3766
+ RagRetrievalConfigRanking,
3767
+ RagRetrievalConfig,
3620
3768
  VertexRagStore,
3621
3769
  Retrieval,
3622
3770
  ToolCodeExecution,
@@ -3737,6 +3885,7 @@ declare namespace types {
3737
3885
  SubjectReferenceConfig,
3738
3886
  SubjectReferenceImage,
3739
3887
  LiveServerSetupComplete,
3888
+ Transcription,
3740
3889
  LiveServerContent,
3741
3890
  LiveServerToolCall,
3742
3891
  LiveServerToolCallCancellation,
@@ -3749,6 +3898,7 @@ declare namespace types {
3749
3898
  SessionResumptionConfig,
3750
3899
  SlidingWindow,
3751
3900
  ContextWindowCompressionConfig,
3901
+ AudioTranscriptionConfig,
3752
3902
  LiveClientSetup,
3753
3903
  LiveClientContent,
3754
3904
  ActivityStart,
@@ -3756,7 +3906,6 @@ declare namespace types {
3756
3906
  LiveClientRealtimeInput,
3757
3907
  LiveClientToolResponse,
3758
3908
  LiveClientMessage,
3759
- AudioTranscriptionConfig,
3760
3909
  LiveConnectConfig,
3761
3910
  LiveConnectParameters,
3762
3911
  CreateChatParameters,
@@ -3909,6 +4058,8 @@ export declare interface VertexRagStore {
3909
4058
  ragCorpora?: string[];
3910
4059
  /** 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. */
3911
4060
  ragResources?: VertexRagStoreRagResource[];
4061
+ /** Optional. The retrieval config for the Rag query. */
4062
+ ragRetrievalConfig?: RagRetrievalConfig;
3912
4063
  /** Optional. Number of top k results to return from the selected corpora. */
3913
4064
  similarityTopK?: number;
3914
4065
  /** Optional. Only return results with vector distance smaller than the threshold. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/genai",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "main": "dist/node/index.js",
6
6
  "module": "dist/web/index.mjs",
@@ -93,7 +93,9 @@
93
93
  },
94
94
  "dependencies": {
95
95
  "google-auth-library": "^9.14.2",
96
- "ws": "^8.18.0"
96
+ "ws": "^8.18.0",
97
+ "zod": "^3.22.4",
98
+ "zod-to-json-schema": "^3.22.4"
97
99
  },
98
100
  "repository": {
99
101
  "type": "git",