From d314d636c5f6e05242560fa0ef68bef08dfae579 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 30 Jun 2025 10:27:41 -0700 Subject: [PATCH 1/3] Convert TS enums exports in Firebase AI into const variables. --- .changeset/shy-yaks-hammer.md | 6 + packages/ai/src/types/enums.ts | 175 +++++++++++++++-------- packages/ai/src/types/imagen/requests.ts | 76 +++++++--- packages/ai/src/types/schema.ts | 26 ++-- 4 files changed, 196 insertions(+), 87 deletions(-) create mode 100644 .changeset/shy-yaks-hammer.md diff --git a/.changeset/shy-yaks-hammer.md b/.changeset/shy-yaks-hammer.md new file mode 100644 index 00000000000..47b4df179e5 --- /dev/null +++ b/.changeset/shy-yaks-hammer.md @@ -0,0 +1,6 @@ +--- +'@firebase/ai': major +'firebase': major +--- + +Convert TS enums exports in Firebase AI into const variables. diff --git a/packages/ai/src/types/enums.ts b/packages/ai/src/types/enums.ts index 47d654bbcd1..b5e4e60ab4f 100644 --- a/packages/ai/src/types/enums.ts +++ b/packages/ai/src/types/enums.ts @@ -31,229 +31,284 @@ export const POSSIBLE_ROLES = ['user', 'model', 'function', 'system'] as const; * Harm categories that would cause prompts or candidates to be blocked. * @public */ -export enum HarmCategory { - HARM_CATEGORY_HATE_SPEECH = 'HARM_CATEGORY_HATE_SPEECH', - HARM_CATEGORY_SEXUALLY_EXPLICIT = 'HARM_CATEGORY_SEXUALLY_EXPLICIT', - HARM_CATEGORY_HARASSMENT = 'HARM_CATEGORY_HARASSMENT', - HARM_CATEGORY_DANGEROUS_CONTENT = 'HARM_CATEGORY_DANGEROUS_CONTENT' -} +export const HarmCategory = { + HARM_CATEGORY_HATE_SPEECH: 'HARM_CATEGORY_HATE_SPEECH', + HARM_CATEGORY_SEXUALLY_EXPLICIT: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', + HARM_CATEGORY_HARASSMENT: 'HARM_CATEGORY_HARASSMENT', + HARM_CATEGORY_DANGEROUS_CONTENT: 'HARM_CATEGORY_DANGEROUS_CONTENT' +} as const; + +/** + * Harm categories that would cause prompts or candidates to be blocked. + * @public + */ +export type HarmCategory = (typeof HarmCategory)[keyof typeof HarmCategory]; /** * Threshold above which a prompt or candidate will be blocked. * @public */ -export enum HarmBlockThreshold { +export const HarmBlockThreshold = { /** * Content with `NEGLIGIBLE` will be allowed. */ - BLOCK_LOW_AND_ABOVE = 'BLOCK_LOW_AND_ABOVE', + BLOCK_LOW_AND_ABOVE: 'BLOCK_LOW_AND_ABOVE', /** * Content with `NEGLIGIBLE` and `LOW` will be allowed. */ - BLOCK_MEDIUM_AND_ABOVE = 'BLOCK_MEDIUM_AND_ABOVE', + BLOCK_MEDIUM_AND_ABOVE: 'BLOCK_MEDIUM_AND_ABOVE', /** * Content with `NEGLIGIBLE`, `LOW`, and `MEDIUM` will be allowed. */ - BLOCK_ONLY_HIGH = 'BLOCK_ONLY_HIGH', + BLOCK_ONLY_HIGH: 'BLOCK_ONLY_HIGH', /** * All content will be allowed. */ - BLOCK_NONE = 'BLOCK_NONE', + BLOCK_NONE: 'BLOCK_NONE', /** * All content will be allowed. This is the same as `BLOCK_NONE`, but the metadata corresponding * to the {@link HarmCategory} will not be present in the response. */ - OFF = 'OFF' -} + OFF: 'OFF' +} as const; + +/** + * Threshold above which a prompt or candidate will be blocked. + * @public + */ +export type HarmBlockThreshold = + (typeof HarmBlockThreshold)[keyof typeof HarmBlockThreshold]; /** * This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}). * * @public */ -export enum HarmBlockMethod { +export const HarmBlockMethod = { /** * The harm block method uses both probability and severity scores. */ - SEVERITY = 'SEVERITY', + SEVERITY: 'SEVERITY', /** * The harm block method uses the probability score. */ - PROBABILITY = 'PROBABILITY' -} + PROBABILITY: 'PROBABILITY' +} as const; + +/** + * This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}). + * + * @public + */ +export type HarmBlockMethod = + (typeof HarmBlockMethod)[keyof typeof HarmBlockMethod]; /** * Probability that a prompt or candidate matches a harm category. * @public */ -export enum HarmProbability { +export const HarmProbability = { /** * Content has a negligible chance of being unsafe. */ - NEGLIGIBLE = 'NEGLIGIBLE', + NEGLIGIBLE: 'NEGLIGIBLE', /** * Content has a low chance of being unsafe. */ - LOW = 'LOW', + LOW: 'LOW', /** * Content has a medium chance of being unsafe. */ - MEDIUM = 'MEDIUM', + MEDIUM: 'MEDIUM', /** * Content has a high chance of being unsafe. */ - HIGH = 'HIGH' -} + HIGH: 'HIGH' +} as const; + +/** + * Probability that a prompt or candidate matches a harm category. + * @public + */ +export type HarmProbability = + (typeof HarmProbability)[keyof typeof HarmProbability]; /** * Harm severity levels. * @public */ -export enum HarmSeverity { +export const HarmSeverity = { /** * Negligible level of harm severity. */ - HARM_SEVERITY_NEGLIGIBLE = 'HARM_SEVERITY_NEGLIGIBLE', + HARM_SEVERITY_NEGLIGIBLE: 'HARM_SEVERITY_NEGLIGIBLE', /** * Low level of harm severity. */ - HARM_SEVERITY_LOW = 'HARM_SEVERITY_LOW', + HARM_SEVERITY_LOW: 'HARM_SEVERITY_LOW', /** * Medium level of harm severity. */ - HARM_SEVERITY_MEDIUM = 'HARM_SEVERITY_MEDIUM', + HARM_SEVERITY_MEDIUM: 'HARM_SEVERITY_MEDIUM', /** * High level of harm severity. */ - HARM_SEVERITY_HIGH = 'HARM_SEVERITY_HIGH', + HARM_SEVERITY_HIGH: 'HARM_SEVERITY_HIGH', /** * Harm severity is not supported. * * @remarks * The GoogleAI backend does not support `HarmSeverity`, so this value is used as a fallback. */ - HARM_SEVERITY_UNSUPPORTED = 'HARM_SEVERITY_UNSUPPORTED' -} + HARM_SEVERITY_UNSUPPORTED: 'HARM_SEVERITY_UNSUPPORTED' +} as const; + +/** + * Harm severity levels. + * @public + */ +export type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeverity]; /** * Reason that a prompt was blocked. * @public */ -export enum BlockReason { +export const BlockReason = { /** * Content was blocked by safety settings. */ - SAFETY = 'SAFETY', + SAFETY: 'SAFETY', /** * Content was blocked, but the reason is uncategorized. */ - OTHER = 'OTHER', + OTHER: 'OTHER', /** * Content was blocked because it contained terms from the terminology blocklist. */ - BLOCKLIST = 'BLOCKLIST', + BLOCKLIST: 'BLOCKLIST', /** * Content was blocked due to prohibited content. */ - PROHIBITED_CONTENT = 'PROHIBITED_CONTENT' -} + PROHIBITED_CONTENT: 'PROHIBITED_CONTENT' +} as const; + +/** + * Reason that a prompt was blocked. + * @public + */ +export type BlockReason = (typeof BlockReason)[keyof typeof BlockReason]; /** * Reason that a candidate finished. * @public */ -export enum FinishReason { +export const FinishReason = { /** * Natural stop point of the model or provided stop sequence. */ - STOP = 'STOP', + STOP: 'STOP', /** * The maximum number of tokens as specified in the request was reached. */ - MAX_TOKENS = 'MAX_TOKENS', + MAX_TOKENS: 'MAX_TOKENS', /** * The candidate content was flagged for safety reasons. */ - SAFETY = 'SAFETY', + SAFETY: 'SAFETY', /** * The candidate content was flagged for recitation reasons. */ - RECITATION = 'RECITATION', + RECITATION: 'RECITATION', /** * Unknown reason. */ - OTHER = 'OTHER', + OTHER: 'OTHER', /** * The candidate content contained forbidden terms. */ - BLOCKLIST = 'BLOCKLIST', + BLOCKLIST: 'BLOCKLIST', /** * The candidate content potentially contained prohibited content. */ - PROHIBITED_CONTENT = 'PROHIBITED_CONTENT', + PROHIBITED_CONTENT: 'PROHIBITED_CONTENT', /** * The candidate content potentially contained Sensitive Personally Identifiable Information (SPII). */ - SPII = 'SPII', + SPII: 'SPII', /** * The function call generated by the model was invalid. */ - MALFORMED_FUNCTION_CALL = 'MALFORMED_FUNCTION_CALL' -} + MALFORMED_FUNCTION_CALL: 'MALFORMED_FUNCTION_CALL' +} as const; + +/** + * Reason that a candidate finished. + * @public + */ +export type FinishReason = (typeof FinishReason)[keyof typeof FinishReason]; /** * @public */ -export enum FunctionCallingMode { +export const FunctionCallingMode = { /** * Default model behavior; model decides to predict either a function call * or a natural language response. */ - AUTO = 'AUTO', + AUTO: 'AUTO', /** * Model is constrained to always predicting a function call only. * If `allowed_function_names` is set, the predicted function call will be * limited to any one of `allowed_function_names`, else the predicted * function call will be any one of the provided `function_declarations`. */ - ANY = 'ANY', + ANY: 'ANY', /** * Model will not predict any function call. Model behavior is same as when * not passing any function declarations. */ - NONE = 'NONE' -} + NONE: 'NONE' +} as const; + +export type FunctionCallingMode = + (typeof FunctionCallingMode)[keyof typeof FunctionCallingMode]; /** * Content part modality. * @public */ -export enum Modality { +export const Modality = { /** * Unspecified modality. */ - MODALITY_UNSPECIFIED = 'MODALITY_UNSPECIFIED', + MODALITY_UNSPECIFIED: 'MODALITY_UNSPECIFIED', /** * Plain text. */ - TEXT = 'TEXT', + TEXT: 'TEXT', /** * Image. */ - IMAGE = 'IMAGE', + IMAGE: 'IMAGE', /** * Video. */ - VIDEO = 'VIDEO', + VIDEO: 'VIDEO', /** * Audio. */ - AUDIO = 'AUDIO', + AUDIO: 'AUDIO', /** * Document (for example, PDF). */ - DOCUMENT = 'DOCUMENT' -} + DOCUMENT: 'DOCUMENT' +} as const; + +/** + * Content part modality. + * @public + */ +export type Modality = (typeof Modality)[keyof typeof Modality]; /** * Generation modalities to be returned in generation responses. diff --git a/packages/ai/src/types/imagen/requests.ts b/packages/ai/src/types/imagen/requests.ts index 09bd3dedc9b..24c8370ea09 100644 --- a/packages/ai/src/types/imagen/requests.ts +++ b/packages/ai/src/types/imagen/requests.ts @@ -110,27 +110,42 @@ export interface ImagenGenerationConfig { * * @beta */ -export enum ImagenSafetyFilterLevel { +export const ImagenSafetyFilterLevel = { /** * The most aggressive filtering level; most strict blocking. */ - BLOCK_LOW_AND_ABOVE = 'block_low_and_above', + BLOCK_LOW_AND_ABOVE: 'block_low_and_above', /** * Blocks some sensitive prompts and responses. */ - BLOCK_MEDIUM_AND_ABOVE = 'block_medium_and_above', + BLOCK_MEDIUM_AND_ABOVE: 'block_medium_and_above', /** * Blocks few sensitive prompts and responses. */ - BLOCK_ONLY_HIGH = 'block_only_high', + BLOCK_ONLY_HIGH: 'block_only_high', /** * The least aggressive filtering level; blocks very few sensitive prompts and responses. * * Access to this feature is restricted and may require your case to be reviewed and approved by * Cloud support. */ - BLOCK_NONE = 'block_none' -} + BLOCK_NONE: 'block_none' +} as const; + +/** + * A filter level controlling how aggressively to filter sensitive content. + * + * Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI + * are assessed against a list of safety filters, which include 'harmful categories' (for example, + * `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to + * filter out potentially harmful content from responses. See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation } + * and the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters | Responsible AI and usage guidelines} + * for more details. + * + * @beta + */ +export type ImagenSafetyFilterLevel = + (typeof ImagenSafetyFilterLevel)[keyof typeof ImagenSafetyFilterLevel]; /** * A filter level controlling whether generation of images containing people or faces is allowed. @@ -140,11 +155,11 @@ export enum ImagenSafetyFilterLevel { * * @beta */ -export enum ImagenPersonFilterLevel { +export const ImagenPersonFilterLevel = { /** * Disallow generation of images containing people or faces; images of people are filtered out. */ - BLOCK_ALL = 'dont_allow', + BLOCK_ALL: 'dont_allow', /** * Allow generation of images containing adults only; images of children are filtered out. * @@ -152,7 +167,7 @@ export enum ImagenPersonFilterLevel { * reviewed and approved by Cloud support; see the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen | Responsible AI and usage guidelines} * for more details. */ - ALLOW_ADULT = 'allow_adult', + ALLOW_ADULT: 'allow_adult', /** * Allow generation of images containing adults only; images of children are filtered out. * @@ -160,8 +175,19 @@ export enum ImagenPersonFilterLevel { * reviewed and approved by Cloud support; see the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen | Responsible AI and usage guidelines} * for more details. */ - ALLOW_ALL = 'allow_all' -} + ALLOW_ALL: 'allow_all' +} as const; + +/** + * A filter level controlling whether generation of images containing people or faces is allowed. + * + * See the personGeneration + * documentation for more details. + * + * @beta + */ +export type ImagenPersonFilterLevel = + (typeof ImagenPersonFilterLevel)[keyof typeof ImagenPersonFilterLevel]; /** * Settings for controlling the aggressiveness of filtering out sensitive content. @@ -194,25 +220,39 @@ export interface ImagenSafetySettings { * * @beta */ -export enum ImagenAspectRatio { +export const ImagenAspectRatio = { /** * Square (1:1) aspect ratio. */ - SQUARE = '1:1', + 'SQUARE': '1:1', /** * Landscape (3:4) aspect ratio. */ - LANDSCAPE_3x4 = '3:4', + 'LANDSCAPE_3x4': '3:4', /** * Portrait (4:3) aspect ratio. */ - PORTRAIT_4x3 = '4:3', + 'PORTRAIT_4x3': '4:3', /** * Landscape (16:9) aspect ratio. */ - LANDSCAPE_16x9 = '16:9', + 'LANDSCAPE_16x9': '16:9', /** * Portrait (9:16) aspect ratio. */ - PORTRAIT_9x16 = '9:16' -} + 'PORTRAIT_9x16': '9:16' +} as const; + +/** + * Aspect ratios for Imagen images. + * + * To specify an aspect ratio for generated images, set the `aspectRatio` property in your + * {@link ImagenGenerationConfig}. + * + * See the the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation } + * for more details and examples of the supported aspect ratios. + * + * @beta + */ +export type ImagenAspectRatio = + (typeof ImagenAspectRatio)[keyof typeof ImagenAspectRatio]; diff --git a/packages/ai/src/types/schema.ts b/packages/ai/src/types/schema.ts index 3a6c0c7301b..2bd94c53f6d 100644 --- a/packages/ai/src/types/schema.ts +++ b/packages/ai/src/types/schema.ts @@ -21,20 +21,28 @@ * {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification} * @public */ -export enum SchemaType { +export const SchemaType = { /** String type. */ - STRING = 'string', + STRING: 'string', /** Number type. */ - NUMBER = 'number', + NUMBER: 'number', /** Integer type. */ - INTEGER = 'integer', + INTEGER: 'integer', /** Boolean type. */ - BOOLEAN = 'boolean', + BOOLEAN: 'boolean', /** Array type. */ - ARRAY = 'array', + ARRAY: 'array', /** Object type. */ - OBJECT = 'object' -} + OBJECT: 'object' +} as const; + +/** + * Contains the list of OpenAPI data types + * as defined by the + * {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification} + * @public + */ +export type SchemaType = (typeof SchemaType)[keyof typeof SchemaType]; /** * Basic {@link Schema} properties shared across several Schema-related @@ -118,6 +126,6 @@ export interface SchemaInterface extends SchemaShared { * @public */ export interface ObjectSchemaInterface extends SchemaInterface { - type: SchemaType.OBJECT; + type: 'object'; optionalProperties?: string[]; } From cbf0dd4dedeb67d421e38254cb3ba4e39216aac5 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 30 Jun 2025 11:36:12 -0700 Subject: [PATCH 2/3] Fix docs --- common/api-review/ai.api.md | 250 ++++++---- docs-devsite/ai.md | 545 ++++++++++++--------- docs-devsite/ai.objectschemainterface.md | 4 +- docs-devsite/ai.schema.md | 8 +- docs-devsite/ai.schemashared.md | 8 +- packages/ai/src/errors.ts | 2 +- packages/ai/src/requests/schema-builder.ts | 6 +- packages/ai/src/types/error.ts | 37 +- packages/ai/src/types/imagen/requests.ts | 2 +- packages/ai/src/types/imagen/responses.ts | 4 +- packages/ai/src/types/schema.ts | 8 +- 11 files changed, 513 insertions(+), 361 deletions(-) diff --git a/common/api-review/ai.api.md b/common/api-review/ai.api.md index ab79447798f..8b1c385d57f 100644 --- a/common/api-review/ai.api.md +++ b/common/api-review/ai.api.md @@ -27,21 +27,24 @@ export class AIError extends FirebaseError { } // @public -const enum AIErrorCode { - API_NOT_ENABLED = "api-not-enabled", - ERROR = "error", - FETCH_ERROR = "fetch-error", - INVALID_CONTENT = "invalid-content", - INVALID_SCHEMA = "invalid-schema", - NO_API_KEY = "no-api-key", - NO_APP_ID = "no-app-id", - NO_MODEL = "no-model", - NO_PROJECT_ID = "no-project-id", - PARSE_FAILED = "parse-failed", - REQUEST_ERROR = "request-error", - RESPONSE_ERROR = "response-error", - UNSUPPORTED = "unsupported" -} +const AIErrorCode: { + readonly ERROR: "error"; + readonly REQUEST_ERROR: "request-error"; + readonly RESPONSE_ERROR: "response-error"; + readonly FETCH_ERROR: "fetch-error"; + readonly INVALID_CONTENT: "invalid-content"; + readonly API_NOT_ENABLED: "api-not-enabled"; + readonly INVALID_SCHEMA: "invalid-schema"; + readonly NO_API_KEY: "no-api-key"; + readonly NO_APP_ID: "no-app-id"; + readonly NO_MODEL: "no-model"; + readonly NO_PROJECT_ID: "no-project-id"; + readonly PARSE_FAILED: "parse-failed"; + readonly UNSUPPORTED: "unsupported"; +}; + +// @public +type AIErrorCode = (typeof AIErrorCode)[keyof typeof AIErrorCode]; export { AIErrorCode } @@ -98,12 +101,15 @@ export interface BaseParams { } // @public -export enum BlockReason { - BLOCKLIST = "BLOCKLIST", - OTHER = "OTHER", - PROHIBITED_CONTENT = "PROHIBITED_CONTENT", - SAFETY = "SAFETY" -} +export const BlockReason: { + readonly SAFETY: "SAFETY"; + readonly OTHER: "OTHER"; + readonly BLOCKLIST: "BLOCKLIST"; + readonly PROHIBITED_CONTENT: "PROHIBITED_CONTENT"; +}; + +// @public +export type BlockReason = (typeof BlockReason)[keyof typeof BlockReason]; // @public export class BooleanSchema extends Schema { @@ -230,17 +236,20 @@ export interface FileDataPart { } // @public -export enum FinishReason { - BLOCKLIST = "BLOCKLIST", - MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL", - MAX_TOKENS = "MAX_TOKENS", - OTHER = "OTHER", - PROHIBITED_CONTENT = "PROHIBITED_CONTENT", - RECITATION = "RECITATION", - SAFETY = "SAFETY", - SPII = "SPII", - STOP = "STOP" -} +export const FinishReason: { + readonly STOP: "STOP"; + readonly MAX_TOKENS: "MAX_TOKENS"; + readonly SAFETY: "SAFETY"; + readonly RECITATION: "RECITATION"; + readonly OTHER: "OTHER"; + readonly BLOCKLIST: "BLOCKLIST"; + readonly PROHIBITED_CONTENT: "PROHIBITED_CONTENT"; + readonly SPII: "SPII"; + readonly MALFORMED_FUNCTION_CALL: "MALFORMED_FUNCTION_CALL"; +}; + +// @public +export type FinishReason = (typeof FinishReason)[keyof typeof FinishReason]; // @public export interface FunctionCall { @@ -259,11 +268,14 @@ export interface FunctionCallingConfig { } // @public (undocumented) -export enum FunctionCallingMode { - ANY = "ANY", - AUTO = "AUTO", - NONE = "NONE" -} +export const FunctionCallingMode: { + readonly AUTO: "AUTO"; + readonly ANY: "ANY"; + readonly NONE: "NONE"; +}; + +// @public (undocumented) +export type FunctionCallingMode = (typeof FunctionCallingMode)[keyof typeof FunctionCallingMode]; // @public export interface FunctionCallPart { @@ -509,57 +521,71 @@ export interface GroundingMetadata { } // @public -export enum HarmBlockMethod { - PROBABILITY = "PROBABILITY", - SEVERITY = "SEVERITY" -} +export const HarmBlockMethod: { + readonly SEVERITY: "SEVERITY"; + readonly PROBABILITY: "PROBABILITY"; +}; // @public -export enum HarmBlockThreshold { - BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE", - BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE", - BLOCK_NONE = "BLOCK_NONE", - BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH", - OFF = "OFF" -} +export type HarmBlockMethod = (typeof HarmBlockMethod)[keyof typeof HarmBlockMethod]; // @public -export enum HarmCategory { - // (undocumented) - HARM_CATEGORY_DANGEROUS_CONTENT = "HARM_CATEGORY_DANGEROUS_CONTENT", - // (undocumented) - HARM_CATEGORY_HARASSMENT = "HARM_CATEGORY_HARASSMENT", - // (undocumented) - HARM_CATEGORY_HATE_SPEECH = "HARM_CATEGORY_HATE_SPEECH", - // (undocumented) - HARM_CATEGORY_SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT" -} +export const HarmBlockThreshold: { + readonly BLOCK_LOW_AND_ABOVE: "BLOCK_LOW_AND_ABOVE"; + readonly BLOCK_MEDIUM_AND_ABOVE: "BLOCK_MEDIUM_AND_ABOVE"; + readonly BLOCK_ONLY_HIGH: "BLOCK_ONLY_HIGH"; + readonly BLOCK_NONE: "BLOCK_NONE"; + readonly OFF: "OFF"; +}; // @public -export enum HarmProbability { - HIGH = "HIGH", - LOW = "LOW", - MEDIUM = "MEDIUM", - NEGLIGIBLE = "NEGLIGIBLE" -} +export type HarmBlockThreshold = (typeof HarmBlockThreshold)[keyof typeof HarmBlockThreshold]; // @public -export enum HarmSeverity { - HARM_SEVERITY_HIGH = "HARM_SEVERITY_HIGH", - HARM_SEVERITY_LOW = "HARM_SEVERITY_LOW", - HARM_SEVERITY_MEDIUM = "HARM_SEVERITY_MEDIUM", - HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE", - HARM_SEVERITY_UNSUPPORTED = "HARM_SEVERITY_UNSUPPORTED" -} +export const HarmCategory: { + readonly HARM_CATEGORY_HATE_SPEECH: "HARM_CATEGORY_HATE_SPEECH"; + readonly HARM_CATEGORY_SEXUALLY_EXPLICIT: "HARM_CATEGORY_SEXUALLY_EXPLICIT"; + readonly HARM_CATEGORY_HARASSMENT: "HARM_CATEGORY_HARASSMENT"; + readonly HARM_CATEGORY_DANGEROUS_CONTENT: "HARM_CATEGORY_DANGEROUS_CONTENT"; +}; + +// @public +export type HarmCategory = (typeof HarmCategory)[keyof typeof HarmCategory]; + +// @public +export const HarmProbability: { + readonly NEGLIGIBLE: "NEGLIGIBLE"; + readonly LOW: "LOW"; + readonly MEDIUM: "MEDIUM"; + readonly HIGH: "HIGH"; +}; + +// @public +export type HarmProbability = (typeof HarmProbability)[keyof typeof HarmProbability]; + +// @public +export const HarmSeverity: { + readonly HARM_SEVERITY_NEGLIGIBLE: "HARM_SEVERITY_NEGLIGIBLE"; + readonly HARM_SEVERITY_LOW: "HARM_SEVERITY_LOW"; + readonly HARM_SEVERITY_MEDIUM: "HARM_SEVERITY_MEDIUM"; + readonly HARM_SEVERITY_HIGH: "HARM_SEVERITY_HIGH"; + readonly HARM_SEVERITY_UNSUPPORTED: "HARM_SEVERITY_UNSUPPORTED"; +}; + +// @public +export type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeverity]; // @beta -export enum ImagenAspectRatio { - LANDSCAPE_16x9 = "16:9", - LANDSCAPE_3x4 = "3:4", - PORTRAIT_4x3 = "4:3", - PORTRAIT_9x16 = "9:16", - SQUARE = "1:1" -} +export const ImagenAspectRatio: { + readonly SQUARE: "1:1"; + readonly LANDSCAPE_3x4: "3:4"; + readonly PORTRAIT_4x3: "4:3"; + readonly LANDSCAPE_16x9: "16:9"; + readonly PORTRAIT_9x16: "9:16"; +}; + +// @beta +export type ImagenAspectRatio = (typeof ImagenAspectRatio)[keyof typeof ImagenAspectRatio]; // @public export interface ImagenGCSImage { @@ -616,19 +642,25 @@ export interface ImagenModelParams { } // @beta -export enum ImagenPersonFilterLevel { - ALLOW_ADULT = "allow_adult", - ALLOW_ALL = "allow_all", - BLOCK_ALL = "dont_allow" -} +export const ImagenPersonFilterLevel: { + readonly BLOCK_ALL: "dont_allow"; + readonly ALLOW_ADULT: "allow_adult"; + readonly ALLOW_ALL: "allow_all"; +}; // @beta -export enum ImagenSafetyFilterLevel { - BLOCK_LOW_AND_ABOVE = "block_low_and_above", - BLOCK_MEDIUM_AND_ABOVE = "block_medium_and_above", - BLOCK_NONE = "block_none", - BLOCK_ONLY_HIGH = "block_only_high" -} +export type ImagenPersonFilterLevel = (typeof ImagenPersonFilterLevel)[keyof typeof ImagenPersonFilterLevel]; + +// @beta +export const ImagenSafetyFilterLevel: { + readonly BLOCK_LOW_AND_ABOVE: "block_low_and_above"; + readonly BLOCK_MEDIUM_AND_ABOVE: "block_medium_and_above"; + readonly BLOCK_ONLY_HIGH: "block_only_high"; + readonly BLOCK_NONE: "block_none"; +}; + +// @beta +export type ImagenSafetyFilterLevel = (typeof ImagenSafetyFilterLevel)[keyof typeof ImagenSafetyFilterLevel]; // @beta export interface ImagenSafetySettings { @@ -655,14 +687,17 @@ export class IntegerSchema extends Schema { } // @public -export enum Modality { - AUDIO = "AUDIO", - DOCUMENT = "DOCUMENT", - IMAGE = "IMAGE", - MODALITY_UNSPECIFIED = "MODALITY_UNSPECIFIED", - TEXT = "TEXT", - VIDEO = "VIDEO" -} +export const Modality: { + readonly MODALITY_UNSPECIFIED: "MODALITY_UNSPECIFIED"; + readonly TEXT: "TEXT"; + readonly IMAGE: "IMAGE"; + readonly VIDEO: "VIDEO"; + readonly AUDIO: "AUDIO"; + readonly DOCUMENT: "DOCUMENT"; +}; + +// @public +export type Modality = (typeof Modality)[keyof typeof Modality]; // @public export interface ModalityTokenCount { @@ -707,7 +742,7 @@ export interface ObjectSchemaInterface extends SchemaInterface { // (undocumented) optionalProperties?: string[]; // (undocumented) - type: SchemaType.OBJECT; + type: 'object'; } // @public @@ -849,14 +884,17 @@ export interface SchemaShared { } // @public -export enum SchemaType { - ARRAY = "array", - BOOLEAN = "boolean", - INTEGER = "integer", - NUMBER = "number", - OBJECT = "object", - STRING = "string" -} +export const SchemaType: { + readonly STRING: "string"; + readonly NUMBER: "number"; + readonly INTEGER: "integer"; + readonly BOOLEAN: "boolean"; + readonly ARRAY: "array"; + readonly OBJECT: "object"; +}; + +// @public +export type SchemaType = (typeof SchemaType)[keyof typeof SchemaType]; // @public (undocumented) export interface Segment { diff --git a/docs-devsite/ai.md b/docs-devsite/ai.md index 286c8351fd7..e579fc02d12 100644 --- a/docs-devsite/ai.md +++ b/docs-devsite/ai.md @@ -44,25 +44,6 @@ The Firebase AI Web SDK. | [StringSchema](./ai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | | [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. | -## Enumerations - -| Enumeration | Description | -| --- | --- | -| [AIErrorCode](./ai.md#aierrorcode) | Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. | -| [BlockReason](./ai.md#blockreason) | Reason that a prompt was blocked. | -| [FinishReason](./ai.md#finishreason) | Reason that a candidate finished. | -| [FunctionCallingMode](./ai.md#functioncallingmode) | | -| [HarmBlockMethod](./ai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). | -| [HarmBlockThreshold](./ai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | -| [HarmCategory](./ai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | -| [HarmProbability](./ai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | -| [HarmSeverity](./ai.md#harmseverity) | Harm severity levels. | -| [ImagenAspectRatio](./ai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | -| [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | -| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | -| [Modality](./ai.md#modality) | Content part modality. | -| [SchemaType](./ai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | - ## Interfaces | Interface | Description | @@ -129,9 +110,23 @@ The Firebase AI Web SDK. | Variable | Description | | --- | --- | +| [AIErrorCode](./ai.md#aierrorcode) | Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. | | [BackendType](./ai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | +| [BlockReason](./ai.md#blockreason) | Reason that a prompt was blocked. | +| [FinishReason](./ai.md#finishreason) | Reason that a candidate finished. | +| [FunctionCallingMode](./ai.md#functioncallingmode) | | +| [HarmBlockMethod](./ai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). | +| [HarmBlockThreshold](./ai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | +| [HarmCategory](./ai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | +| [HarmProbability](./ai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | +| [HarmSeverity](./ai.md#harmseverity) | Harm severity levels. | +| [ImagenAspectRatio](./ai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | +| [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | +| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | +| [Modality](./ai.md#modality) | Content part modality. | | [POSSIBLE\_ROLES](./ai.md#possible_roles) | Possible roles. | | [ResponseModality](./ai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | +| [SchemaType](./ai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | | [VertexAIError](./ai.md#vertexaierror) | | | [VertexAIModel](./ai.md#vertexaimodel) | | @@ -139,10 +134,24 @@ The Firebase AI Web SDK. | Type Alias | Description | | --- | --- | +| [AIErrorCode](./ai.md#aierrorcode) | Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. | | [BackendType](./ai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | +| [BlockReason](./ai.md#blockreason) | Reason that a prompt was blocked. | +| [FinishReason](./ai.md#finishreason) | Reason that a candidate finished. | +| [FunctionCallingMode](./ai.md#functioncallingmode) | | +| [HarmBlockMethod](./ai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). | +| [HarmBlockThreshold](./ai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | +| [HarmCategory](./ai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | +| [HarmProbability](./ai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | +| [HarmSeverity](./ai.md#harmseverity) | Harm severity levels. | +| [ImagenAspectRatio](./ai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | +| [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | +| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | +| [Modality](./ai.md#modality) | Content part modality. | | [Part](./ai.md#part) | Content part - includes text, image/video, or function call/response part types. | | [ResponseModality](./ai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | | [Role](./ai.md#role) | Role is the producer of the content. | +| [SchemaType](./ai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | | [Tool](./ai.md#tool) | Defines a tool that model can call to access external knowledge. | | [TypedSchema](./ai.md#typedschema) | A type that includes all specific Schema types. | | [VertexAI](./ai.md#vertexai) | | @@ -279,6 +288,30 @@ export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, r If the `apiKey` or `projectId` fields are missing in your Firebase config. +## AIErrorCode + +Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. + +Signature: + +```typescript +AIErrorCode: { + readonly ERROR: "error"; + readonly REQUEST_ERROR: "request-error"; + readonly RESPONSE_ERROR: "response-error"; + readonly FETCH_ERROR: "fetch-error"; + readonly INVALID_CONTENT: "invalid-content"; + readonly API_NOT_ENABLED: "api-not-enabled"; + readonly INVALID_SCHEMA: "invalid-schema"; + readonly NO_API_KEY: "no-api-key"; + readonly NO_APP_ID: "no-app-id"; + readonly NO_MODEL: "no-model"; + readonly NO_PROJECT_ID: "no-project-id"; + readonly PARSE_FAILED: "parse-failed"; + readonly UNSUPPORTED: "unsupported"; +} +``` + ## BackendType An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with. @@ -294,138 +327,279 @@ BackendType: { } ``` -## POSSIBLE\_ROLES +## BlockReason -Possible roles. +Reason that a prompt was blocked. Signature: ```typescript -POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] +BlockReason: { + readonly SAFETY: "SAFETY"; + readonly OTHER: "OTHER"; + readonly BLOCKLIST: "BLOCKLIST"; + readonly PROHIBITED_CONTENT: "PROHIBITED_CONTENT"; +} ``` -## ResponseModality +## FinishReason -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> +Reason that a candidate finished. + +Signature: + +```typescript +FinishReason: { + readonly STOP: "STOP"; + readonly MAX_TOKENS: "MAX_TOKENS"; + readonly SAFETY: "SAFETY"; + readonly RECITATION: "RECITATION"; + readonly OTHER: "OTHER"; + readonly BLOCKLIST: "BLOCKLIST"; + readonly PROHIBITED_CONTENT: "PROHIBITED_CONTENT"; + readonly SPII: "SPII"; + readonly MALFORMED_FUNCTION_CALL: "MALFORMED_FUNCTION_CALL"; +} +``` + +## FunctionCallingMode -Generation modalities to be returned in generation responses. Signature: ```typescript -ResponseModality: { - readonly TEXT: "TEXT"; - readonly IMAGE: "IMAGE"; +FunctionCallingMode: { + readonly AUTO: "AUTO"; + readonly ANY: "ANY"; + readonly NONE: "NONE"; } ``` -## VertexAIError +## HarmBlockMethod -> Warning: This API is now obsolete. -> -> Use the new [AIError](./ai.aierror.md#aierror_class) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). -> -> Error class for the Firebase AI SDK. -> +This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). Signature: ```typescript -VertexAIError: typeof AIError +HarmBlockMethod: { + readonly SEVERITY: "SEVERITY"; + readonly PROBABILITY: "PROBABILITY"; +} ``` -## VertexAIModel +## HarmBlockThreshold -> Warning: This API is now obsolete. -> -> Use the new [AIModel](./ai.aimodel.md#aimodel_class) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). -> -> Base class for Firebase AI model APIs. -> +Threshold above which a prompt or candidate will be blocked. Signature: ```typescript -VertexAIModel: typeof AIModel +HarmBlockThreshold: { + readonly BLOCK_LOW_AND_ABOVE: "BLOCK_LOW_AND_ABOVE"; + readonly BLOCK_MEDIUM_AND_ABOVE: "BLOCK_MEDIUM_AND_ABOVE"; + readonly BLOCK_ONLY_HIGH: "BLOCK_ONLY_HIGH"; + readonly BLOCK_NONE: "BLOCK_NONE"; + readonly OFF: "OFF"; +} ``` -## BackendType +## HarmCategory -Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. +Harm categories that would cause prompts or candidates to be blocked. Signature: ```typescript -export type BackendType = (typeof BackendType)[keyof typeof BackendType]; +HarmCategory: { + readonly HARM_CATEGORY_HATE_SPEECH: "HARM_CATEGORY_HATE_SPEECH"; + readonly HARM_CATEGORY_SEXUALLY_EXPLICIT: "HARM_CATEGORY_SEXUALLY_EXPLICIT"; + readonly HARM_CATEGORY_HARASSMENT: "HARM_CATEGORY_HARASSMENT"; + readonly HARM_CATEGORY_DANGEROUS_CONTENT: "HARM_CATEGORY_DANGEROUS_CONTENT"; +} ``` -## Part +## HarmProbability -Content part - includes text, image/video, or function call/response part types. +Probability that a prompt or candidate matches a harm category. Signature: ```typescript -export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; +HarmProbability: { + readonly NEGLIGIBLE: "NEGLIGIBLE"; + readonly LOW: "LOW"; + readonly MEDIUM: "MEDIUM"; + readonly HIGH: "HIGH"; +} ``` -## ResponseModality +## HarmSeverity + +Harm severity levels. + +Signature: + +```typescript +HarmSeverity: { + readonly HARM_SEVERITY_NEGLIGIBLE: "HARM_SEVERITY_NEGLIGIBLE"; + readonly HARM_SEVERITY_LOW: "HARM_SEVERITY_LOW"; + readonly HARM_SEVERITY_MEDIUM: "HARM_SEVERITY_MEDIUM"; + readonly HARM_SEVERITY_HIGH: "HARM_SEVERITY_HIGH"; + readonly HARM_SEVERITY_UNSUPPORTED: "HARM_SEVERITY_UNSUPPORTED"; +} +``` + +## ImagenAspectRatio > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > -Generation modalities to be returned in generation responses. +Aspect ratios for Imagen images. + +To specify an aspect ratio for generated images, set the `aspectRatio` property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface). + +See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. Signature: ```typescript -export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality]; +ImagenAspectRatio: { + readonly SQUARE: "1:1"; + readonly LANDSCAPE_3x4: "3:4"; + readonly PORTRAIT_4x3: "4:3"; + readonly LANDSCAPE_16x9: "16:9"; + readonly PORTRAIT_9x16: "9:16"; +} ``` -## Role +## ImagenPersonFilterLevel -Role is the producer of the content. +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +A filter level controlling whether generation of images containing people or faces is allowed. + +See the personGeneration documentation for more details. Signature: ```typescript -export type Role = (typeof POSSIBLE_ROLES)[number]; +ImagenPersonFilterLevel: { + readonly BLOCK_ALL: "dont_allow"; + readonly ALLOW_ADULT: "allow_adult"; + readonly ALLOW_ALL: "allow_all"; +} ``` -## Tool +## ImagenSafetyFilterLevel -Defines a tool that model can call to access external knowledge. +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +A filter level controlling how aggressively to filter sensitive content. + +Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. Signature: ```typescript -export declare type Tool = FunctionDeclarationsTool; +ImagenSafetyFilterLevel: { + readonly BLOCK_LOW_AND_ABOVE: "block_low_and_above"; + readonly BLOCK_MEDIUM_AND_ABOVE: "block_medium_and_above"; + readonly BLOCK_ONLY_HIGH: "block_only_high"; + readonly BLOCK_NONE: "block_none"; +} ``` -## TypedSchema +## Modality -A type that includes all specific Schema types. +Content part modality. Signature: ```typescript -export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; +Modality: { + readonly MODALITY_UNSPECIFIED: "MODALITY_UNSPECIFIED"; + readonly TEXT: "TEXT"; + readonly IMAGE: "IMAGE"; + readonly VIDEO: "VIDEO"; + readonly AUDIO: "AUDIO"; + readonly DOCUMENT: "DOCUMENT"; +} ``` -## VertexAI +## POSSIBLE\_ROLES + +Possible roles. + +Signature: + +```typescript +POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] +``` + +## ResponseModality + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Generation modalities to be returned in generation responses. + +Signature: + +```typescript +ResponseModality: { + readonly TEXT: "TEXT"; + readonly IMAGE: "IMAGE"; +} +``` + +## SchemaType + +Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) + +Signature: + +```typescript +SchemaType: { + readonly STRING: "string"; + readonly NUMBER: "number"; + readonly INTEGER: "integer"; + readonly BOOLEAN: "boolean"; + readonly ARRAY: "array"; + readonly OBJECT: "object"; +} +``` + +## VertexAIError > Warning: This API is now obsolete. > -> Use the new [AI](./ai.ai.md#ai_interface) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> Use the new [AIError](./ai.aierror.md#aierror_class) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). > -> An instance of the Firebase AI SDK. +> Error class for the Firebase AI SDK. > Signature: ```typescript -export type VertexAI = AI; +VertexAIError: typeof AIError +``` + +## VertexAIModel + +> Warning: This API is now obsolete. +> +> Use the new [AIModel](./ai.aimodel.md#aimodel_class) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> +> Base class for Firebase AI model APIs. +> + +Signature: + +```typescript +VertexAIModel: typeof AIModel ``` ## AIErrorCode @@ -435,26 +609,18 @@ Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. Signature: ```typescript -export declare const enum AIErrorCode +export type AIErrorCode = (typeof AIErrorCode)[keyof typeof AIErrorCode]; ``` -## Enumeration Members +## BackendType + +Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. -| Member | Value | Description | -| --- | --- | --- | -| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | -| ERROR | "error" | A generic error occurred. | -| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | -| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | -| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | -| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | -| NO\_APP\_ID | "no-app-id" | An error occurred due to a missing Firebase app ID. | -| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | -| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | -| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | -| REQUEST\_ERROR | "request-error" | An error occurred in a request. | -| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | -| UNSUPPORTED | "unsupported" | An error occurred due an attempt to use an unsupported feature. | +Signature: + +```typescript +export type BackendType = (typeof BackendType)[keyof typeof BackendType]; +``` ## BlockReason @@ -463,18 +629,9 @@ Reason that a prompt was blocked. Signature: ```typescript -export declare enum BlockReason +export type BlockReason = (typeof BlockReason)[keyof typeof BlockReason]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCKLIST | "BLOCKLIST" | Content was blocked because it contained terms from the terminology blocklist. | -| OTHER | "OTHER" | Content was blocked, but the reason is uncategorized. | -| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | Content was blocked due to prohibited content. | -| SAFETY | "SAFETY" | Content was blocked by safety settings. | - ## FinishReason Reason that a candidate finished. @@ -482,40 +639,17 @@ Reason that a candidate finished. Signature: ```typescript -export declare enum FinishReason +export type FinishReason = (typeof FinishReason)[keyof typeof FinishReason]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCKLIST | "BLOCKLIST" | The candidate content contained forbidden terms. | -| MALFORMED\_FUNCTION\_CALL | "MALFORMED_FUNCTION_CALL" | The function call generated by the model was invalid. | -| MAX\_TOKENS | "MAX_TOKENS" | The maximum number of tokens as specified in the request was reached. | -| OTHER | "OTHER" | Unknown reason. | -| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | The candidate content potentially contained prohibited content. | -| RECITATION | "RECITATION" | The candidate content was flagged for recitation reasons. | -| SAFETY | "SAFETY" | The candidate content was flagged for safety reasons. | -| SPII | "SPII" | The candidate content potentially contained Sensitive Personally Identifiable Information (SPII). | -| STOP | "STOP" | Natural stop point of the model or provided stop sequence. | - ## FunctionCallingMode - Signature: ```typescript -export declare enum FunctionCallingMode +export type FunctionCallingMode = (typeof FunctionCallingMode)[keyof typeof FunctionCallingMode]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ANY | "ANY" | Model is constrained to always predicting a function call only. If allowed_function_names is set, the predicted function call will be limited to any one of allowed_function_names, else the predicted function call will be any one of the provided function_declarations. | -| AUTO | "AUTO" | Default model behavior; model decides to predict either a function call or a natural language response. | -| NONE | "NONE" | Model will not predict any function call. Model behavior is same as when not passing any function declarations. | - ## HarmBlockMethod This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). @@ -523,16 +657,9 @@ This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ Signature: ```typescript -export declare enum HarmBlockMethod +export type HarmBlockMethod = (typeof HarmBlockMethod)[keyof typeof HarmBlockMethod]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| PROBABILITY | "PROBABILITY" | The harm block method uses the probability score. | -| SEVERITY | "SEVERITY" | The harm block method uses both probability and severity scores. | - ## HarmBlockThreshold Threshold above which a prompt or candidate will be blocked. @@ -540,19 +667,9 @@ Threshold above which a prompt or candidate will be blocked. Signature: ```typescript -export declare enum HarmBlockThreshold +export type HarmBlockThreshold = (typeof HarmBlockThreshold)[keyof typeof HarmBlockThreshold]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCK\_LOW\_AND\_ABOVE | "BLOCK_LOW_AND_ABOVE" | Content with NEGLIGIBLE will be allowed. | -| BLOCK\_MEDIUM\_AND\_ABOVE | "BLOCK_MEDIUM_AND_ABOVE" | Content with NEGLIGIBLE and LOW will be allowed. | -| BLOCK\_NONE | "BLOCK_NONE" | All content will be allowed. | -| BLOCK\_ONLY\_HIGH | "BLOCK_ONLY_HIGH" | Content with NEGLIGIBLE, LOW, and MEDIUM will be allowed. | -| OFF | "OFF" | All content will be allowed. This is the same as BLOCK_NONE, but the metadata corresponding to the [HarmCategory](./ai.md#harmcategory) will not be present in the response. | - ## HarmCategory Harm categories that would cause prompts or candidates to be blocked. @@ -560,18 +677,9 @@ Harm categories that would cause prompts or candidates to be blocked. Signature: ```typescript -export declare enum HarmCategory +export type HarmCategory = (typeof HarmCategory)[keyof typeof HarmCategory]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HARM\_CATEGORY\_DANGEROUS\_CONTENT | "HARM_CATEGORY_DANGEROUS_CONTENT" | | -| HARM\_CATEGORY\_HARASSMENT | "HARM_CATEGORY_HARASSMENT" | | -| HARM\_CATEGORY\_HATE\_SPEECH | "HARM_CATEGORY_HATE_SPEECH" | | -| HARM\_CATEGORY\_SEXUALLY\_EXPLICIT | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | | - ## HarmProbability Probability that a prompt or candidate matches a harm category. @@ -579,18 +687,9 @@ Probability that a prompt or candidate matches a harm category. Signature: ```typescript -export declare enum HarmProbability +export type HarmProbability = (typeof HarmProbability)[keyof typeof HarmProbability]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HIGH | "HIGH" | Content has a high chance of being unsafe. | -| LOW | "LOW" | Content has a low chance of being unsafe. | -| MEDIUM | "MEDIUM" | Content has a medium chance of being unsafe. | -| NEGLIGIBLE | "NEGLIGIBLE" | Content has a negligible chance of being unsafe. | - ## HarmSeverity Harm severity levels. @@ -598,19 +697,9 @@ Harm severity levels. Signature: ```typescript -export declare enum HarmSeverity +export type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeverity]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HARM\_SEVERITY\_HIGH | "HARM_SEVERITY_HIGH" | High level of harm severity. | -| HARM\_SEVERITY\_LOW | "HARM_SEVERITY_LOW" | Low level of harm severity. | -| HARM\_SEVERITY\_MEDIUM | "HARM_SEVERITY_MEDIUM" | Medium level of harm severity. | -| HARM\_SEVERITY\_NEGLIGIBLE | "HARM_SEVERITY_NEGLIGIBLE" | Negligible level of harm severity. | -| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. | - ## ImagenAspectRatio > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. @@ -625,19 +714,9 @@ See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-i Signature: ```typescript -export declare enum ImagenAspectRatio +export type ImagenAspectRatio = (typeof ImagenAspectRatio)[keyof typeof ImagenAspectRatio]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| LANDSCAPE\_16x9 | "16:9" | (Public Preview) Landscape (16:9) aspect ratio. | -| LANDSCAPE\_3x4 | "3:4" | (Public Preview) Landscape (3:4) aspect ratio. | -| PORTRAIT\_4x3 | "4:3" | (Public Preview) Portrait (4:3) aspect ratio. | -| PORTRAIT\_9x16 | "9:16" | (Public Preview) Portrait (9:16) aspect ratio. | -| SQUARE | "1:1" | (Public Preview) Square (1:1) aspect ratio. | - ## ImagenPersonFilterLevel > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. @@ -650,17 +729,9 @@ See the pers Signature: ```typescript -export declare enum ImagenPersonFilterLevel +export type ImagenPersonFilterLevel = (typeof ImagenPersonFilterLevel)[keyof typeof ImagenPersonFilterLevel]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ALLOW\_ADULT | "allow_adult" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | -| ALLOW\_ALL | "allow_all" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | -| BLOCK\_ALL | "dont_allow" | (Public Preview) Disallow generation of images containing people or faces; images of people are filtered out. | - ## ImagenSafetyFilterLevel > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. @@ -673,18 +744,9 @@ Text prompts provided as inputs and images (generated or uploaded) through Image Signature: ```typescript -export declare enum ImagenSafetyFilterLevel +export type ImagenSafetyFilterLevel = (typeof ImagenSafetyFilterLevel)[keyof typeof ImagenSafetyFilterLevel]; ``` -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCK\_LOW\_AND\_ABOVE | "block_low_and_above" | (Public Preview) The most aggressive filtering level; most strict blocking. | -| BLOCK\_MEDIUM\_AND\_ABOVE | "block_medium_and_above" | (Public Preview) Blocks some sensitive prompts and responses. | -| BLOCK\_NONE | "block_none" | (Public Preview) The least aggressive filtering level; blocks very few sensitive prompts and responses.Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. | -| BLOCK\_ONLY\_HIGH | "block_only_high" | (Public Preview) Blocks few sensitive prompts and responses. | - ## Modality Content part modality. @@ -692,19 +754,41 @@ Content part modality. Signature: ```typescript -export declare enum Modality +export type Modality = (typeof Modality)[keyof typeof Modality]; ``` -## Enumeration Members +## Part -| Member | Value | Description | -| --- | --- | --- | -| AUDIO | "AUDIO" | Audio. | -| DOCUMENT | "DOCUMENT" | Document (for example, PDF). | -| IMAGE | "IMAGE" | Image. | -| MODALITY\_UNSPECIFIED | "MODALITY_UNSPECIFIED" | Unspecified modality. | -| TEXT | "TEXT" | Plain text. | -| VIDEO | "VIDEO" | Video. | +Content part - includes text, image/video, or function call/response part types. + +Signature: + +```typescript +export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; +``` + +## ResponseModality + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Generation modalities to be returned in generation responses. + +Signature: + +```typescript +export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality]; +``` + +## Role + +Role is the producer of the content. + +Signature: + +```typescript +export type Role = (typeof POSSIBLE_ROLES)[number]; +``` ## SchemaType @@ -713,17 +797,40 @@ Contains the list of OpenAPI data types as defined by the [OpenAPI specification Signature: ```typescript -export declare enum SchemaType +export type SchemaType = (typeof SchemaType)[keyof typeof SchemaType]; ``` -## Enumeration Members +## Tool -| Member | Value | Description | -| --- | --- | --- | -| ARRAY | "array" | Array type. | -| BOOLEAN | "boolean" | Boolean type. | -| INTEGER | "integer" | Integer type. | -| NUMBER | "number" | Number type. | -| OBJECT | "object" | Object type. | -| STRING | "string" | String type. | +Defines a tool that model can call to access external knowledge. + +Signature: + +```typescript +export declare type Tool = FunctionDeclarationsTool; +``` + +## TypedSchema + +A type that includes all specific Schema types. +Signature: + +```typescript +export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; +``` + +## VertexAI + +> Warning: This API is now obsolete. +> +> Use the new [AI](./ai.ai.md#ai_interface) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> +> An instance of the Firebase AI SDK. +> + +Signature: + +```typescript +export type VertexAI = AI; +``` diff --git a/docs-devsite/ai.objectschemainterface.md b/docs-devsite/ai.objectschemainterface.md index 15b1a97f40d..8036491dd25 100644 --- a/docs-devsite/ai.objectschemainterface.md +++ b/docs-devsite/ai.objectschemainterface.md @@ -24,7 +24,7 @@ export interface ObjectSchemaInterface extends SchemaInterface | Property | Type | Description | | --- | --- | --- | | [optionalProperties](./ai.objectschemainterface.md#objectschemainterfaceoptionalproperties) | string\[\] | | -| [type](./ai.objectschemainterface.md#objectschemainterfacetype) | [SchemaType.OBJECT](./ai.md#schematypeobject_enummember) | | +| [type](./ai.objectschemainterface.md#objectschemainterfacetype) | 'object' | | ## ObjectSchemaInterface.optionalProperties @@ -39,5 +39,5 @@ optionalProperties?: string[]; Signature: ```typescript -type: SchemaType.OBJECT; +type: 'object'; ``` diff --git a/docs-devsite/ai.schema.md b/docs-devsite/ai.schema.md index fa1225c91e5..6cc28c761b5 100644 --- a/docs-devsite/ai.schema.md +++ b/docs-devsite/ai.schema.md @@ -33,8 +33,8 @@ export declare abstract class Schema implements SchemaInterface | [example](./ai.schema.md#schemaexample) | | unknown | Optional. The example of the property. | | [format](./ai.schema.md#schemaformat) | | string | Optional. The format of the property. Supported formats:
  • for NUMBER type: "float", "double"
  • for INTEGER type: "int32", "int64"
  • for STRING type: "email", "byte", etc
| | [items](./ai.schema.md#schemaitems) | | [SchemaInterface](./ai.schemainterface.md#schemainterface_interface) | Optional. The items of the property. | -| [maxItems](./ai.schema.md#schemamaxitems) | | number | The maximum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). | -| [minItems](./ai.schema.md#schemaminitems) | | number | The minimum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). | +| [maxItems](./ai.schema.md#schemamaxitems) | | number | The maximum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) array. | +| [minItems](./ai.schema.md#schemaminitems) | | number | The minimum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) array. | | [nullable](./ai.schema.md#schemanullable) | | boolean | Optional. Whether the property is nullable. Defaults to false. | | [type](./ai.schema.md#schematype) | | [SchemaType](./ai.md#schematype) | Optional. The type of the property. [SchemaType](./ai.md#schematype). | @@ -108,7 +108,7 @@ items?: SchemaInterface; ## Schema.maxItems -The maximum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). +The maximum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) `array`. Signature: @@ -118,7 +118,7 @@ maxItems?: number; ## Schema.minItems -The minimum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). +The minimum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) `array`. Signature: diff --git a/docs-devsite/ai.schemashared.md b/docs-devsite/ai.schemashared.md index fb75fc50841..b68cb180144 100644 --- a/docs-devsite/ai.schemashared.md +++ b/docs-devsite/ai.schemashared.md @@ -28,9 +28,9 @@ export interface SchemaShared | [format](./ai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this must be either 'enum' or 'date-time', otherwise requests will fail. | | [items](./ai.schemashared.md#schemashareditems) | T | Optional. The items of the property. | | [maximum](./ai.schemashared.md#schemasharedmaximum) | number | The maximum value of a numeric type. | -| [maxItems](./ai.schemashared.md#schemasharedmaxitems) | number | The maximum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). | +| [maxItems](./ai.schemashared.md#schemasharedmaxitems) | number | The maximum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) array. | | [minimum](./ai.schemashared.md#schemasharedminimum) | number | The minimum value of a numeric type. | -| [minItems](./ai.schemashared.md#schemasharedminitems) | number | The minimum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). | +| [minItems](./ai.schemashared.md#schemasharedminitems) | number | The minimum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) array. | | [nullable](./ai.schemashared.md#schemasharednullable) | boolean | Optional. Whether the property is nullable. | | [properties](./ai.schemashared.md#schemasharedproperties) | { \[k: string\]: T; } | Optional. Map of Schema objects. | | [propertyOrdering](./ai.schemashared.md#schemasharedpropertyordering) | string\[\] | A hint suggesting the order in which the keys should appear in the generated JSON string. | @@ -98,7 +98,7 @@ maximum?: number; ## SchemaShared.maxItems -The maximum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). +The maximum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) `array`. Signature: @@ -118,7 +118,7 @@ minimum?: number; ## SchemaShared.minItems -The minimum number of items (elements) in a schema of type [SchemaType.ARRAY](./ai.md#schematypearray_enummember). +The minimum number of items (elements) in a schema of [SchemaType](./ai.md#schematype) `array`. Signature: diff --git a/packages/ai/src/errors.ts b/packages/ai/src/errors.ts index 2e9787d0bf2..8190510d0d8 100644 --- a/packages/ai/src/errors.ts +++ b/packages/ai/src/errors.ts @@ -28,7 +28,7 @@ export class AIError extends FirebaseError { /** * Constructs a new instance of the `AIError` class. * - * @param code - The error code from {@link AIErrorCode}. + * @param code - The error code from {@link (AIErrorCode:type)}. * @param message - A human-readable message describing the error. * @param customErrorData - Optional error data. */ diff --git a/packages/ai/src/requests/schema-builder.ts b/packages/ai/src/requests/schema-builder.ts index 7d9ece462b3..0084d6f7ba3 100644 --- a/packages/ai/src/requests/schema-builder.ts +++ b/packages/ai/src/requests/schema-builder.ts @@ -35,7 +35,7 @@ import { export abstract class Schema implements SchemaInterface { /** * Optional. The type of the property. {@link - * SchemaType}. + * (SchemaType:type)}. */ type: SchemaType; /** Optional. The format of the property. @@ -51,9 +51,9 @@ export abstract class Schema implements SchemaInterface { description?: string; /** Optional. The items of the property. */ items?: SchemaInterface; - /** The minimum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */ + /** The minimum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */ minItems?: number; - /** The maximum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */ + /** The maximum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */ maxItems?: number; /** Optional. Whether the property is nullable. Defaults to false. */ nullable: boolean; diff --git a/packages/ai/src/types/error.ts b/packages/ai/src/types/error.ts index 84a30f4e872..d6ed22e047c 100644 --- a/packages/ai/src/types/error.ts +++ b/packages/ai/src/types/error.ts @@ -62,43 +62,50 @@ export interface CustomErrorData { * * @public */ -export const enum AIErrorCode { +export const AIErrorCode = { /** A generic error occurred. */ - ERROR = 'error', + ERROR: 'error', /** An error occurred in a request. */ - REQUEST_ERROR = 'request-error', + REQUEST_ERROR: 'request-error', /** An error occurred in a response. */ - RESPONSE_ERROR = 'response-error', + RESPONSE_ERROR: 'response-error', /** An error occurred while performing a fetch. */ - FETCH_ERROR = 'fetch-error', + FETCH_ERROR: 'fetch-error', /** An error associated with a Content object. */ - INVALID_CONTENT = 'invalid-content', + INVALID_CONTENT: 'invalid-content', /** An error due to the Firebase API not being enabled in the Console. */ - API_NOT_ENABLED = 'api-not-enabled', + API_NOT_ENABLED: 'api-not-enabled', /** An error due to invalid Schema input. */ - INVALID_SCHEMA = 'invalid-schema', + INVALID_SCHEMA: 'invalid-schema', /** An error occurred due to a missing Firebase API key. */ - NO_API_KEY = 'no-api-key', + NO_API_KEY: 'no-api-key', /** An error occurred due to a missing Firebase app ID. */ - NO_APP_ID = 'no-app-id', + NO_APP_ID: 'no-app-id', /** An error occurred due to a model name not being specified during initialization. */ - NO_MODEL = 'no-model', + NO_MODEL: 'no-model', /** An error occurred due to a missing project ID. */ - NO_PROJECT_ID = 'no-project-id', + NO_PROJECT_ID: 'no-project-id', /** An error occurred while parsing. */ - PARSE_FAILED = 'parse-failed', + PARSE_FAILED: 'parse-failed', /** An error occurred due an attempt to use an unsupported feature. */ - UNSUPPORTED = 'unsupported' -} + UNSUPPORTED: 'unsupported' +} as const; + +/** + * Standardized error codes that {@link AIError} can have. + * + * @public + */ +export type AIErrorCode = (typeof AIErrorCode)[keyof typeof AIErrorCode]; diff --git a/packages/ai/src/types/imagen/requests.ts b/packages/ai/src/types/imagen/requests.ts index 24c8370ea09..2818ab91fd5 100644 --- a/packages/ai/src/types/imagen/requests.ts +++ b/packages/ai/src/types/imagen/requests.ts @@ -73,7 +73,7 @@ export interface ImagenGenerationConfig { numberOfImages?: number; /** * The aspect ratio of the generated images. The default value is square 1:1. - * Supported aspect ratios depend on the Imagen model, see {@link ImagenAspectRatio} + * Supported aspect ratios depend on the Imagen model, see {@link (ImagenAspectRatio:type)} * for more details. */ aspectRatio?: ImagenAspectRatio; diff --git a/packages/ai/src/types/imagen/responses.ts b/packages/ai/src/types/imagen/responses.ts index 4b093fd550f..4e4496e6b36 100644 --- a/packages/ai/src/types/imagen/responses.ts +++ b/packages/ai/src/types/imagen/responses.ts @@ -72,8 +72,8 @@ export interface ImagenGenerationResponse< * The reason that images were filtered out. This property will only be defined if one * or more images were filtered. * - * Images may be filtered out due to the {@link ImagenSafetyFilterLevel}, - * {@link ImagenPersonFilterLevel}, or filtering included in the model. + * Images may be filtered out due to the {@link (ImagenSafetyFilterLevel:type)}, + * {@link (ImagenPersonFilterLevel:type)}, or filtering included in the model. * The filter levels may be adjusted in your {@link ImagenSafetySettings}. * * See the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen | Responsible AI and usage guidelines for Imagen} diff --git a/packages/ai/src/types/schema.ts b/packages/ai/src/types/schema.ts index 2bd94c53f6d..9a1e47626df 100644 --- a/packages/ai/src/types/schema.ts +++ b/packages/ai/src/types/schema.ts @@ -65,9 +65,9 @@ export interface SchemaShared { title?: string; /** Optional. The items of the property. */ items?: T; - /** The minimum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */ + /** The minimum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */ minItems?: number; - /** The maximum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */ + /** The maximum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */ maxItems?: number; /** Optional. Map of `Schema` objects. */ properties?: { @@ -102,7 +102,7 @@ export interface SchemaParams extends SchemaShared {} export interface SchemaRequest extends SchemaShared { /** * The type of the property. {@link - * SchemaType}. + * (SchemaType:type)}. */ type: SchemaType; /** Optional. Array of required property. */ @@ -116,7 +116,7 @@ export interface SchemaRequest extends SchemaShared { export interface SchemaInterface extends SchemaShared { /** * The type of the property. {@link - * SchemaType}. + * (SchemaType:type)}. */ type: SchemaType; } From cf320ab34b178477f80b0a2a91af39c1e9a6c633 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 30 Jun 2025 11:46:57 -0700 Subject: [PATCH 3/3] TS does not like include --- packages/ai/src/requests/response-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ai/src/requests/response-helpers.ts b/packages/ai/src/requests/response-helpers.ts index 20678eeea68..2505b5c9276 100644 --- a/packages/ai/src/requests/response-helpers.ts +++ b/packages/ai/src/requests/response-helpers.ts @@ -229,7 +229,7 @@ const badFinishReasons = [FinishReason.RECITATION, FinishReason.SAFETY]; function hadBadFinishReason(candidate: GenerateContentCandidate): boolean { return ( !!candidate.finishReason && - badFinishReasons.includes(candidate.finishReason) + badFinishReasons.some(reason => reason === candidate.finishReason) ); }