Skip to content

Commit 480b59d

Browse files
CorieWcabljac
authored andcommitted
chore(plugins/vertexai): address feedback and format
1 parent 33cc9d3 commit 480b59d

File tree

14 files changed

+109
-85
lines changed

14 files changed

+109
-85
lines changed

js/plugins/vertexai/src/embedder.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import {
2020
type EmbedderAction,
2121
type EmbedderReference,
2222
} from 'genkit/embedder';
23+
import { embedder } from 'genkit/plugin';
2324
import type { GoogleAuth } from 'google-auth-library';
2425
import type { PluginOptions } from './common/types.js';
2526
import { predictModel, type PredictClient } from './predict.js';
26-
import { embedder } from 'genkit/plugin';
2727

2828
export const TaskTypeSchema = z.enum([
2929
'RETRIEVAL_DOCUMENT',
@@ -304,12 +304,15 @@ export function defineVertexAIEmbedder(
304304
configSchema: embedderRef.configSchema,
305305
info: embedderRef.info!,
306306
},
307-
async (input, options) => {
307+
async (request, options) => {
308308
const predictClient = predictClientFactory(embedderRef.config);
309309
const response = await predictClient(
310-
input.input.map((doc: Document) => {
310+
request.input.map((doc: Document) => {
311311
let instance: EmbeddingInstance;
312-
if (isMultiModal(embedderRef) && checkValidDocument(embedderRef, doc)) {
312+
if (
313+
isMultiModal(embedderRef) &&
314+
checkValidDocument(embedderRef, doc)
315+
) {
313316
instance = {};
314317
if (doc.text) {
315318
instance.text = doc.text;

js/plugins/vertexai/src/evaluation/evaluator_factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import { type Action, type z } from 'genkit';
1818
import type { BaseEvalDataPoint, Score } from 'genkit/evaluator';
19+
import { evaluator } from 'genkit/plugin';
1920
import { runInNewSpan } from 'genkit/tracing';
2021
import type { GoogleAuth } from 'google-auth-library';
2122
import { getGenkitClientHeader } from '../common/index.js';
2223
import type { VertexAIEvaluationMetricType } from './evaluation.js';
23-
import { evaluator } from 'genkit/plugin';
2424

2525
export class EvaluatorFactory {
2626
constructor(

js/plugins/vertexai/src/evaluation/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function vertexAIEvaluation(options: PluginOptions): GenkitPluginV2 {
2828
return genkitPluginV2({
2929
name: 'vertexAIEvaluation',
3030
init: async () => {
31-
const { projectId, location, authClient } = await getDerivedParams(options);
31+
const { projectId, location, authClient } =
32+
await getDerivedParams(options);
3233

3334
return vertexEvaluators(authClient, options.metrics, projectId, location);
3435
},

js/plugins/vertexai/src/gemini.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ import {
5656
downloadRequestMedia,
5757
simulateSystemPrompt,
5858
} from 'genkit/model/middleware';
59+
import { model } from 'genkit/plugin';
5960
import { runInNewSpan } from 'genkit/tracing';
6061
import { GoogleAuth } from 'google-auth-library';
6162
import { getGenkitClientHeader } from './common/index.js';
6263
import type { PluginOptions } from './common/types.js';
6364
import { handleCacheIfNeeded } from './context-caching/index.js';
6465
import { extractCacheConfig } from './context-caching/utils.js';
65-
import { model } from 'genkit/plugin';
6666

6767
// Extra type guard to keep the compiler happy and avoid a cast to any. The
6868
// legacy Gemini SDK is no longer maintained, and doesn't have updated types.

js/plugins/vertexai/src/imagen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { z, type Genkit } from 'genkit';
17+
import { z } from 'genkit';
1818
import {
1919
GenerationCommonConfigSchema,
20-
getBasicUsageStats,
2120
modelRef as createModelRef,
21+
getBasicUsageStats,
2222
type CandidateData,
2323
type GenerateRequest,
2424
type ModelAction,
2525
type ModelInfo,
2626
type ModelReference,
2727
} from 'genkit/model';
28+
import { model } from 'genkit/plugin';
2829
import type { GoogleAuth } from 'google-auth-library';
2930
import type { PluginOptions } from './common/types.js';
3031
import { predictModel, type PredictClient } from './predict.js';
31-
import { model } from 'genkit/plugin';
3232

3333
/**
3434
* See https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api.

js/plugins/vertexai/src/index.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import {
2828
type ModelReference,
2929
type z,
3030
} from 'genkit';
31-
import { genkitPluginV2, ResolvableAction, type GenkitPluginV2 } from 'genkit/plugin';
31+
import {
32+
ResolvableAction,
33+
genkitPluginV2,
34+
type GenkitPluginV2,
35+
} from 'genkit/plugin';
3236
import type { ActionType } from 'genkit/registry';
3337
import { getDerivedParams } from './common/index.js';
3438
import type { PluginOptions } from './common/types.js';
@@ -116,20 +120,22 @@ async function initializer(options?: PluginOptions) {
116120

117121
const actions: ResolvableAction[] = [];
118122

119-
Object.keys(SUPPORTED_IMAGEN_MODELS).map((name) =>
120-
actions.push(defineImagenModel(name, authClient, { projectId, location }))
121-
);
122-
Object.keys(SUPPORTED_GEMINI_MODELS).map((name) =>
123-
actions.push(defineGeminiKnownModel(
124-
name,
125-
vertexClientFactory,
126-
{
127-
projectId,
128-
location,
129-
},
130-
options?.experimental_debugTraces
131-
))
132-
);
123+
for (const name of Object.keys(SUPPORTED_IMAGEN_MODELS)) {
124+
actions.push(defineImagenModel(name, authClient, { projectId, location }));
125+
}
126+
for (const name of Object.keys(SUPPORTED_GEMINI_MODELS)) {
127+
actions.push(
128+
defineGeminiKnownModel(
129+
name,
130+
vertexClientFactory,
131+
{
132+
projectId,
133+
location,
134+
},
135+
options?.experimental_debugTraces
136+
)
137+
);
138+
}
133139
if (options?.models) {
134140
for (const modelOrRef of options?.models) {
135141
const modelName =
@@ -139,22 +145,26 @@ async function initializer(options?: PluginOptions) {
139145
modelOrRef.name.split('/')[1];
140146
const modelRef =
141147
typeof modelOrRef === 'string' ? gemini(modelOrRef) : modelOrRef;
142-
actions.push(defineGeminiModel({
143-
modelName: modelRef.name,
144-
version: modelName,
145-
modelInfo: modelRef.info,
146-
vertexClientFactory,
147-
options: {
148-
projectId,
149-
location,
150-
},
151-
debugTraces: options.experimental_debugTraces,
152-
}));
148+
actions.push(
149+
defineGeminiModel({
150+
modelName: modelRef.name,
151+
version: modelName,
152+
modelInfo: modelRef.info,
153+
vertexClientFactory,
154+
options: {
155+
projectId,
156+
location,
157+
},
158+
debugTraces: options.experimental_debugTraces,
159+
})
160+
);
153161
}
154162
}
155163

156164
Object.keys(SUPPORTED_EMBEDDER_MODELS).map((name) =>
157-
actions.push(defineVertexAIEmbedder(name, authClient, { projectId, location }))
165+
actions.push(
166+
defineVertexAIEmbedder(name, authClient, { projectId, location })
167+
)
158168
);
159169

160170
return actions;
@@ -185,8 +195,7 @@ async function resolveModel(
185195
await getDerivedParams(options);
186196

187197
if (actionName.startsWith('imagen')) {
188-
defineImagenModel(actionName, authClient, { projectId, location });
189-
return;
198+
return defineImagenModel(actionName, authClient, { projectId, location });
190199
}
191200

192201
const modelRef = gemini(actionName);
@@ -209,7 +218,10 @@ async function resolveEmbedder(
209218
): Promise<ResolvableAction | undefined> {
210219
const { projectId, location, authClient } = await getDerivedParams(options);
211220

212-
return defineVertexAIEmbedder(actionName, authClient, { projectId, location })
221+
return defineVertexAIEmbedder(actionName, authClient, {
222+
projectId,
223+
location,
224+
});
213225
}
214226

215227
// Vertex AI list models still returns these and the API does not indicate in any way
@@ -268,14 +280,14 @@ function vertexAIPlugin(options?: PluginOptions): GenkitPluginV2 {
268280
let listActionsCache;
269281
return genkitPluginV2({
270282
name: 'vertexai',
271-
init: async () => initializer(),
283+
init: async () => initializer(options),
272284
resolve: async (actionType: ActionType, actionName: string) =>
273-
await resolver(actionType, actionName),
285+
await resolver(actionType, actionName, options),
274286
list: async () => {
275287
if (listActionsCache) return listActionsCache;
276288
listActionsCache = await listActions(options);
277289
return listActionsCache;
278-
}
290+
},
279291
});
280292
}
281293

js/plugins/vertexai/src/modelgarden/anthropic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import {
4444
modelRef,
4545
type ModelAction,
4646
} from 'genkit/model';
47-
import { getGenkitClientHeader } from '../common/index.js';
4847
import { model } from 'genkit/plugin';
48+
import { getGenkitClientHeader } from '../common/index.js';
4949

5050
export const AnthropicConfigSchema = GenerationCommonConfigSchema.extend({
5151
location: z.string().optional(),

js/plugins/vertexai/src/modelgarden/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type { Action, Genkit } from 'genkit';
17+
import type { Action } from 'genkit';
1818
import { genkitPluginV2, type GenkitPluginV2 } from 'genkit/plugin';
1919
import { getDerivedParams } from '../common/index.js';
2020
import { SUPPORTED_ANTHROPIC_MODELS, anthropicModel } from './anthropic.js';
@@ -32,7 +32,8 @@ export function vertexAIModelGarden(options: PluginOptions): GenkitPluginV2 {
3232
return genkitPluginV2({
3333
name: 'vertexAIModelGarden',
3434
init: async () => {
35-
const { projectId, location, authClient } = await getDerivedParams(options);
35+
const { projectId, location, authClient } =
36+
await getDerivedParams(options);
3637

3738
const actions: Action[] = [];
3839

@@ -55,13 +56,15 @@ export function vertexAIModelGarden(options: PluginOptions): GenkitPluginV2 {
5556
([_, value]) => value.name === m.name
5657
);
5758
if (openaiModel) {
58-
actions.push(modelGardenOpenaiCompatibleModel(
59-
openaiModel[0],
60-
projectId,
61-
location,
62-
authClient,
63-
options.openAiBaseUrlTemplate
64-
));
59+
actions.push(
60+
modelGardenOpenaiCompatibleModel(
61+
openaiModel[0],
62+
projectId,
63+
location,
64+
authClient,
65+
options.openAiBaseUrlTemplate
66+
)
67+
);
6568
return;
6669
}
6770
throw new Error(`Unsupported model garden model: ${m.name}`);

js/plugins/vertexai/src/modelgarden/mistral.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import {
4545
modelRef,
4646
type ModelAction,
4747
} from 'genkit/model';
48-
import { getGenkitClientHeader } from '../common/index.js';
4948
import { model } from 'genkit/plugin';
49+
import { getGenkitClientHeader } from '../common/index.js';
5050

5151
/**
5252
* See https://docs.mistral.ai/api/#tag/chat/operation/chat_completion_v1_chat_completions_post

js/plugins/vertexai/src/rerankers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type { Genkit } from 'genkit';
1817
import { genkitPluginV2, type GenkitPluginV2 } from 'genkit/plugin';
1918
import type { CommonPluginOptions } from '../common/types.js';
2019
import type { RerankerOptions } from './types.js';
@@ -32,7 +31,8 @@ export function vertexAIRerankers(options: PluginOptions): GenkitPluginV2 {
3231
return genkitPluginV2({
3332
name: 'vertexAIRerankers',
3433
init: async () => {
35-
const { projectId, location, authClient } = await getDerivedParams(options);
34+
const { projectId, location, authClient } =
35+
await getDerivedParams(options);
3636

3737
return vertexAiRerankers({
3838
projectId,

0 commit comments

Comments
 (0)