@google/genai 0.4.0 → 0.6.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.
@@ -261,10 +261,12 @@ export declare interface Candidate {
261
261
  /** Number of tokens for this candidate.
262
262
  */
263
263
  tokenCount?: number;
264
+ /** The reason why the model stopped generating tokens.
265
+ If empty, the model has not stopped generating the tokens.
266
+ */
267
+ finishReason?: FinishReason;
264
268
  /** Output only. Average log probability score of the candidate. */
265
269
  avgLogprobs?: number;
266
- /** Output only. The reason why the model stopped generating tokens. If empty, the model has not stopped generating the tokens. */
267
- finishReason?: FinishReason;
268
270
  /** Output only. Metadata specifies sources used to ground generated content. */
269
271
  groundingMetadata?: GroundingMetadata;
270
272
  /** Output only. Index of the candidate. */
@@ -375,7 +377,7 @@ export declare class Chats {
375
377
  * @remarks
376
378
  * The config in the params will be used for all requests within the chat
377
379
  * session unless overridden by a per-request `config` in
378
- * {@link ./types.SendMessageParameters}.
380
+ * @see {@link types.SendMessageParameters#config}.
379
381
  *
380
382
  * @param params - Parameters for creating a chat session.
381
383
  * @returns A new chat session.
@@ -496,12 +498,6 @@ export declare interface ContentEmbeddingStatistics {
496
498
 
497
499
  export declare type ContentListUnion = ContentUnion[] | ContentUnion;
498
500
 
499
- /** @internal */
500
- export declare function contentToMldev(apiClient: ApiClient, fromObject: types.Content): Record<string, unknown>;
501
-
502
- /** @internal */
503
- export declare function contentToVertex(apiClient: ApiClient, fromObject: types.Content): Record<string, unknown>;
504
-
505
501
  export declare type ContentUnion = Content | PartUnion[] | PartUnion;
506
502
 
507
503
  /** Configuration for a Control reference image. */
@@ -989,7 +985,8 @@ export declare enum FinishReason {
989
985
  BLOCKLIST = "BLOCKLIST",
990
986
  PROHIBITED_CONTENT = "PROHIBITED_CONTENT",
991
987
  SPII = "SPII",
992
- MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL"
988
+ MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL",
989
+ IMAGE_SAFETY = "IMAGE_SAFETY"
993
990
  }
994
991
 
995
992
  declare function formatMap(templateString: string, valueMap: Record<string, unknown>): string;
@@ -1317,13 +1314,25 @@ export declare class GenerateContentResponsePromptFeedback {
1317
1314
 
1318
1315
  /** Usage metadata about response(s). */
1319
1316
  export declare class GenerateContentResponseUsageMetadata {
1317
+ /** Output only. List of modalities of the cached content in the request input. */
1318
+ cacheTokensDetails?: ModalityTokenCount[];
1320
1319
  /** Output only. Number of tokens in the cached part in the input (the cached content). */
1321
1320
  cachedContentTokenCount?: number;
1322
1321
  /** Number of tokens in the response(s). */
1323
1322
  candidatesTokenCount?: number;
1323
+ /** Output only. List of modalities that were returned in the response. */
1324
+ candidatesTokensDetails?: ModalityTokenCount[];
1324
1325
  /** Number of tokens in the request. When `cached_content` is set, this is still the total effective prompt size meaning this includes the number of tokens in the cached content. */
1325
1326
  promptTokenCount?: number;
1326
- /** Total token count for prompt and response candidates. */
1327
+ /** Output only. List of modalities that were processed in the request input. */
1328
+ promptTokensDetails?: ModalityTokenCount[];
1329
+ /** Output only. Number of tokens present in thoughts output. */
1330
+ thoughtsTokenCount?: number;
1331
+ /** Output only. Number of tokens present in tool-use prompt(s). */
1332
+ toolUsePromptTokenCount?: number;
1333
+ /** Output only. List of modalities that were processed for tool-use request inputs. */
1334
+ toolUsePromptTokensDetails?: ModalityTokenCount[];
1335
+ /** Total token count for prompt, response candidates, and tool-use prompts (if present). */
1327
1336
  totalTokenCount?: number;
1328
1337
  }
1329
1338
 
@@ -1512,13 +1521,22 @@ declare function getValueByPath(data: unknown, keys: string[]): unknown;
1512
1521
  * The Google GenAI SDK.
1513
1522
  *
1514
1523
  * @remarks
1515
- * Provides access to the GenAI features through either the {@link https://cloud.google.com/vertex-ai/docs/reference/rest | Gemini API}
1516
- * or the {@link https://cloud.google.com/vertex-ai/docs/reference/rest | Vertex AI API}.
1524
+ * Provides access to the GenAI features through either the {@link
1525
+ * https://cloud.google.com/vertex-ai/docs/reference/rest | Gemini API} or
1526
+ * the {@link https://cloud.google.com/vertex-ai/docs/reference/rest | Vertex AI
1527
+ * API}.
1528
+ *
1529
+ * The {@link GoogleGenAIOptions.vertexai} value determines which of the API
1530
+ * services to use.
1517
1531
  *
1518
- * The {@link GoogleGenAIOptions.vertexai} value determines which of the API services to use.
1532
+ * When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must also be
1533
+ * set. When using Vertex AI, both {@link GoogleGenAIOptions.project} and {@link
1534
+ * GoogleGenAIOptions.location} must be set, or a {@link
1535
+ * GoogleGenAIOptions.apiKey} must be set when using Express Mode.
1519
1536
  *
1520
- * When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must also be set,
1521
- * when using Vertex AI {@link GoogleGenAIOptions.project} and {@link GoogleGenAIOptions.location} must also be set.
1537
+ * Explicitly passed in values in {@link GoogleGenAIOptions} will always take
1538
+ * precedence over environment variables. If both project/location and api_key
1539
+ * exist in the environment variables, the project/location will be used.
1522
1540
  *
1523
1541
  * @example
1524
1542
  * Initializing the SDK for using the Gemini API:
@@ -1886,6 +1904,11 @@ export declare class Live {
1886
1904
 
1887
1905
  @experimental
1888
1906
 
1907
+ @remarks
1908
+ If using the Gemini API, Live is currently only supported behind API
1909
+ version `v1alpha`. Ensure that the API version is set to `v1alpha` when
1910
+ initializing the SDK if relying on the Gemini API.
1911
+
1889
1912
  @param params - The parameters for establishing a connection to the model.
1890
1913
  @return A live session.
1891
1914
 
@@ -2058,6 +2081,28 @@ export declare interface LiveConnectParameters {
2058
2081
  config?: LiveConnectConfig;
2059
2082
  }
2060
2083
 
2084
+ /** Parameters for sending client content to the live API. */
2085
+ export declare interface LiveSendClientContentParameters {
2086
+ /** Client content to send to the session. */
2087
+ turns?: ContentListUnion;
2088
+ /** If true, indicates that the server content generation should start with
2089
+ the currently accumulated prompt. Otherwise, the server will await
2090
+ additional messages before starting generation. */
2091
+ turnComplete?: boolean;
2092
+ }
2093
+
2094
+ /** Parameters for sending realtime input to the live API. */
2095
+ export declare interface LiveSendRealtimeInputParameters {
2096
+ /** Realtime input to send to the session. */
2097
+ media: Blob_2;
2098
+ }
2099
+
2100
+ /** Parameters for sending tool responses to the live API. */
2101
+ export declare class LiveSendToolResponseParameters {
2102
+ /** Tool responses to send to the session. */
2103
+ functionResponses: FunctionResponse[] | FunctionResponse;
2104
+ }
2105
+
2061
2106
  /** Incremental server update generated by the model in response to client messages.
2062
2107
 
2063
2108
  Content is generated as quickly as possible, and not in real time. Clients
@@ -2185,6 +2230,14 @@ export declare enum Modality {
2185
2230
  AUDIO = "AUDIO"
2186
2231
  }
2187
2232
 
2233
+ /** Represents token counting info for a single modality. */
2234
+ export declare interface ModalityTokenCount {
2235
+ /** The modality associated with this token count. */
2236
+ modality?: Modality;
2237
+ /** Number of tokens. */
2238
+ tokenCount?: number;
2239
+ }
2240
+
2188
2241
  export declare enum Mode {
2189
2242
  MODE_UNSPECIFIED = "MODE_UNSPECIFIED",
2190
2243
  MODE_DYNAMIC = "MODE_DYNAMIC"
@@ -2374,7 +2427,7 @@ export declare enum Outcome {
2374
2427
  * SPDX-License-Identifier: Apache-2.0
2375
2428
  */
2376
2429
  /**
2377
- * @fileoverview Pagers for the GenAI List APIs.
2430
+ * Pagers for the GenAI List APIs.
2378
2431
  */
2379
2432
  declare enum PagedItem {
2380
2433
  PAGED_ITEM_BATCH_JOBS = "batchJobs",
@@ -2755,12 +2808,13 @@ export declare class Session {
2755
2808
  `turnComplete`.
2756
2809
 
2757
2810
  - `turns` will be converted to a `Content[]`
2758
- - `turnComplete: true` indicates that you are done sending content and
2759
- expect a response.
2811
+ - `turnComplete: true` [default] indicates that you are done sending
2812
+ content and expect a response. If `turnComplete: false`, the server
2813
+ will wait for additional messages before starting generation.
2760
2814
 
2761
2815
  @experimental
2762
2816
 
2763
- @remanks
2817
+ @remarks
2764
2818
  There are two ways to send messages to the live API:
2765
2819
  `sendClientContent` and `sendRealtimeInput`.
2766
2820
 
@@ -2796,7 +2850,7 @@ export declare class Session {
2796
2850
  ```
2797
2851
  @experimental
2798
2852
  */
2799
- sendClientContent(params: types.SessionSendClientContentParameters): void;
2853
+ sendClientContent(params: types.LiveSendClientContentParameters): void;
2800
2854
  /**
2801
2855
  Send a realtime message over the established connection.
2802
2856
 
@@ -2806,7 +2860,7 @@ export declare class Session {
2806
2860
 
2807
2861
  @experimental
2808
2862
 
2809
- @remanks
2863
+ @remarks
2810
2864
  Use `sendRealtimeInput` for realtime audio chunks and video frames (images).
2811
2865
 
2812
2866
  With `sendRealtimeInput` the api will respond to audio automatically
@@ -2819,7 +2873,7 @@ export declare class Session {
2819
2873
  Note: The Call signature expects a `Blob` object, but only a subset
2820
2874
  of audio and image mimetypes are allowed.
2821
2875
  */
2822
- sendRealtimeInput(params: types.SessionSendRealtimeInputParameters): void;
2876
+ sendRealtimeInput(params: types.LiveSendRealtimeInputParameters): void;
2823
2877
  /**
2824
2878
  Send a function response message over the established connection.
2825
2879
 
@@ -2827,14 +2881,14 @@ export declare class Session {
2827
2881
 
2828
2882
  - `functionResponses` will be converted to a `functionResponses[]`
2829
2883
 
2830
- @remanks
2884
+ @remarks
2831
2885
  Use `sendFunctionResponse` to reply to `LiveServerToolCall` from the server.
2832
2886
 
2833
- Use {@link LiveConnectConfig#tools} to configure the callable functions.
2887
+ Use {@link types.LiveConnectConfig#tools} to configure the callable functions.
2834
2888
 
2835
2889
  @experimental
2836
2890
  */
2837
- sendToolResponse(params: types.SessionSendToolResponseParameters): void;
2891
+ sendToolResponse(params: types.LiveSendToolResponseParameters): void;
2838
2892
  /**
2839
2893
  Terminates the WebSocket connection.
2840
2894
 
@@ -2855,28 +2909,6 @@ export declare class Session {
2855
2909
  close(): void;
2856
2910
  }
2857
2911
 
2858
- /** Parameters for sending client content to the live API. */
2859
- export declare interface SessionSendClientContentParameters {
2860
- /** Client content to send to the session. */
2861
- turns?: ContentListUnion;
2862
- /** If true, indicates that the server content generation should start with
2863
- the currently accumulated prompt. Otherwise, the server will await
2864
- additional messages before starting generation. */
2865
- turnComplete?: boolean;
2866
- }
2867
-
2868
- /** Parameters for sending realtime input to the live API. */
2869
- export declare interface SessionSendRealtimeInputParameters {
2870
- /** Realtime input to send to the session. */
2871
- media: Blob_2;
2872
- }
2873
-
2874
- /** Parameters for sending tool responses to the live API. */
2875
- export declare class SessionSendToolResponseParameters {
2876
- /** Tool responses to send to the session. */
2877
- functionResponses: FunctionResponse | FunctionResponse[];
2878
- }
2879
-
2880
2912
  declare function setValueByPath(data: Record<string, unknown>, keys: string[], value: unknown): void;
2881
2913
 
2882
2914
  /** The speech generation configuration. */
@@ -3024,12 +3056,6 @@ export declare interface ToolConfig {
3024
3056
 
3025
3057
  export declare type ToolListUnion = Tool[];
3026
3058
 
3027
- /** @internal */
3028
- export declare function toolToMldev(apiClient: ApiClient, fromObject: types.Tool): Record<string, unknown>;
3029
-
3030
- /** @internal */
3031
- export declare function toolToVertex(apiClient: ApiClient, fromObject: types.Tool): Record<string, unknown>;
3032
-
3033
3059
  export declare enum Type {
3034
3060
  TYPE_UNSPECIFIED = "TYPE_UNSPECIFIED",
3035
3061
  STRING = "STRING",
@@ -3062,6 +3088,7 @@ declare namespace types {
3062
3088
  HarmProbability,
3063
3089
  HarmSeverity,
3064
3090
  BlockedReason,
3091
+ Modality,
3065
3092
  State,
3066
3093
  DynamicRetrievalConfigMode,
3067
3094
  FunctionCallingConfigMode,
@@ -3074,7 +3101,6 @@ declare namespace types {
3074
3101
  MaskReferenceMode,
3075
3102
  ControlReferenceType,
3076
3103
  SubjectReferenceType,
3077
- Modality,
3078
3104
  VideoMetadata,
3079
3105
  CodeExecutionResult,
3080
3106
  ExecutableCode,
@@ -3125,6 +3151,7 @@ declare namespace types {
3125
3151
  SafetyRating,
3126
3152
  Candidate,
3127
3153
  GenerateContentResponsePromptFeedback,
3154
+ ModalityTokenCount,
3128
3155
  GenerateContentResponseUsageMetadata,
3129
3156
  GenerateContentResponse,
3130
3157
  EmbedContentConfig,
@@ -3206,9 +3233,9 @@ declare namespace types {
3206
3233
  LiveConnectParameters,
3207
3234
  CreateChatParameters,
3208
3235
  SendMessageParameters,
3209
- SessionSendClientContentParameters,
3210
- SessionSendRealtimeInputParameters,
3211
- SessionSendToolResponseParameters,
3236
+ LiveSendClientContentParameters,
3237
+ LiveSendRealtimeInputParameters,
3238
+ LiveSendToolResponseParameters,
3212
3239
  PartUnion,
3213
3240
  PartListUnion,
3214
3241
  ContentUnion,