Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions js/plugins/google-genai/src/googleai/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ import {
/**
* See https://ai.google.dev/gemini-api/docs/safety-settings#safety-filters.
*/
const SafetySettingsSchema = z.object({
category: z.enum([
'HARM_CATEGORY_UNSPECIFIED',
'HARM_CATEGORY_HATE_SPEECH',
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
'HARM_CATEGORY_HARASSMENT',
'HARM_CATEGORY_DANGEROUS_CONTENT',
]),
threshold: z.enum([
'BLOCK_LOW_AND_ABOVE',
'BLOCK_MEDIUM_AND_ABOVE',
'BLOCK_ONLY_HIGH',
'BLOCK_NONE',
]),
});
const SafetySettingsSchema = z
.object({
category: z.enum([
'HARM_CATEGORY_UNSPECIFIED',
'HARM_CATEGORY_HATE_SPEECH',
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
'HARM_CATEGORY_HARASSMENT',
'HARM_CATEGORY_DANGEROUS_CONTENT',
]),
threshold: z.enum([
'BLOCK_LOW_AND_ABOVE',
'BLOCK_MEDIUM_AND_ABOVE',
'BLOCK_ONLY_HIGH',
'BLOCK_NONE',
]),
})
.passthrough();

const VoiceConfigSchema = z
.object({
Expand Down Expand Up @@ -169,6 +171,7 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
'predict a function call and guarantee function schema adherence. ' +
'With NONE, the model is prohibited from making function calls.'
)
.passthrough()
.optional(),
responseModalities: z
.array(z.enum(['TEXT', 'IMAGE', 'AUDIO']))
Expand Down Expand Up @@ -225,6 +228,7 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
)
.optional(),
})
.passthrough()
.optional(),
}).passthrough();
export type GeminiConfigSchemaType = typeof GeminiConfigSchema;
Expand Down
124 changes: 67 additions & 57 deletions js/plugins/google-genai/src/vertexai/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,63 +61,70 @@ import {
modelName,
} from './utils.js';

export const SafetySettingsSchema = z.object({
category: z.enum([
/** The harm category is unspecified. */
'HARM_CATEGORY_UNSPECIFIED',
/** The harm category is hate speech. */
'HARM_CATEGORY_HATE_SPEECH',
/** The harm category is dangerous content. */
'HARM_CATEGORY_DANGEROUS_CONTENT',
/** The harm category is harassment. */
'HARM_CATEGORY_HARASSMENT',
/** The harm category is sexually explicit content. */
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
]),
threshold: z.enum([
'BLOCK_LOW_AND_ABOVE',
'BLOCK_MEDIUM_AND_ABOVE',
'BLOCK_ONLY_HIGH',
'BLOCK_NONE',
]),
});

const VertexRetrievalSchema = z.object({
datastore: z
.object({
projectId: z.string().describe('Google Cloud Project ID.').optional(),
location: z
.string()
.describe('Google Cloud region e.g. us-central1.')
.optional(),
dataStoreId: z
.string()
.describe(
'The data store id, when project id and location are provided as ' +
'separate options. Alternatively, the full path to the data ' +
'store should be provided in the form: "projects/{project}/' +
'locations/{location}/collections/default_collection/dataStores/{data_store}".'
),
})
.describe('Vertex AI Search data store details'),
disableAttribution: z
.boolean()
.describe(
'Disable using the search data in detecting grounding attribution. This ' +
'does not affect how the result is given to the model for generation.'
)
.optional(),
});

const GoogleSearchRetrievalSchema = z.object({
disableAttribution: z
.boolean()
.describe(
'Disable using the search data in detecting grounding attribution. This ' +
'does not affect how the result is given to the model for generation.'
)
.optional(),
});
export const SafetySettingsSchema = z
.object({
category: z.enum([
/** The harm category is unspecified. */
'HARM_CATEGORY_UNSPECIFIED',
/** The harm category is hate speech. */
'HARM_CATEGORY_HATE_SPEECH',
/** The harm category is dangerous content. */
'HARM_CATEGORY_DANGEROUS_CONTENT',
/** The harm category is harassment. */
'HARM_CATEGORY_HARASSMENT',
/** The harm category is sexually explicit content. */
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
]),
threshold: z.enum([
'BLOCK_LOW_AND_ABOVE',
'BLOCK_MEDIUM_AND_ABOVE',
'BLOCK_ONLY_HIGH',
'BLOCK_NONE',
]),
})
.passthrough();

const VertexRetrievalSchema = z
.object({
datastore: z
.object({
projectId: z.string().describe('Google Cloud Project ID.').optional(),
location: z
.string()
.describe('Google Cloud region e.g. us-central1.')
.optional(),
dataStoreId: z
.string()
.describe(
'The data store id, when project id and location are provided as ' +
'separate options. Alternatively, the full path to the data ' +
'store should be provided in the form: "projects/{project}/' +
'locations/{location}/collections/default_collection/dataStores/{data_store}".'
),
})
.describe('Vertex AI Search data store details')
.passthrough(),
disableAttribution: z
.boolean()
.describe(
'Disable using the search data in detecting grounding attribution. This ' +
'does not affect how the result is given to the model for generation.'
)
.optional(),
})
.passthrough();

const GoogleSearchRetrievalSchema = z
.object({
disableAttribution: z
.boolean()
.describe(
'Disable using the search data in detecting grounding attribution. This ' +
'does not affect how the result is given to the model for generation.'
)
.optional(),
})
.passthrough();

/**
* Zod schema of Gemini model options.
Expand Down Expand Up @@ -254,6 +261,7 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
'predict a function call and guarantee function schema adherence. ' +
'With NONE, the model is prohibited from making function calls.'
)
.passthrough()
.optional(),
/**
* Retrieval config for search grounding and maps grounding
Expand All @@ -276,6 +284,7 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
*/
languageCode: z.string().optional(),
})
.passthrough()
.optional(),
thinkingConfig: z
.object({
Expand All @@ -302,6 +311,7 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
)
.optional(),
})
.passthrough()
.optional(),
}).passthrough();
export type GeminiConfigSchemaType = typeof GeminiConfigSchema;
Expand Down
2 changes: 2 additions & 0 deletions js/plugins/google-genai/src/vertexai/imagen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const ImagenConfigSchema = GenerationCommonConfigSchema.extend({
'needing to provide one. Consequently, when you provide ' +
'this parameter you can omit a mask object.'
)
.passthrough()
.optional(),
maskDilation: z
.number()
Expand Down Expand Up @@ -158,6 +159,7 @@ export const ImagenConfigSchema = GenerationCommonConfigSchema.extend({
.describe('The factor to upscale the image.'),
})
.describe('Configuration for upscaling.')
.passthrough()
.optional(),
}).passthrough();
export type ImagenConfigSchemaType = typeof ImagenConfigSchema;
Expand Down