Skip to content

Commit

Permalink
remove unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbleigh committed Oct 22, 2024
1 parent 7efc9f0 commit de8012e
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 172 deletions.
4 changes: 2 additions & 2 deletions js/ai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export {
type EvaluatorReference,
} from './evaluator.js';
export {
generate,
GenerateResponse,
generateStream,
GenerationBlockedError,
GenerationResponseError,
Message,
generate,
generateStream,
toGenerateRequest,
type GenerateOptions,
type GenerateStreamOptions,
Expand Down
4 changes: 2 additions & 2 deletions js/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export * from './action.js';
export { getFlowAuth } from './auth.js';
export { GenkitError } from './error.js';
export {
defineFlow,
defineStreamingFlow,
Flow,
FlowServer,
defineFlow,
defineStreamingFlow,
run,
type CallableFlow,
type FlowAuthPolicy,
Expand Down
36 changes: 18 additions & 18 deletions js/genkit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
*/

export {
asTool,
Document,
DocumentDataSchema,
embedderRef,
evaluatorRef,
GenerationBlockedError,
GenerationCommonConfigSchema,
GenerationResponseError,
indexerRef,
LlmResponseSchema,
LlmStatsSchema,
Message,
Expand All @@ -32,12 +28,16 @@ export {
ModelRequestSchema,
ModelResponseSchema,
PartSchema,
rerankerRef,
retrieverRef,
RoleSchema,
toGenerateRequest,
ToolCallSchema,
ToolSchema,
asTool,
embedderRef,
evaluatorRef,
indexerRef,
rerankerRef,
retrieverRef,
toGenerateRequest,
toToolWireFormat,
type BaseDataPointSchema,
type CommonLlmOptions,
Expand Down Expand Up @@ -100,29 +100,29 @@ export {
type ToolResponsePart,
} from '@genkit-ai/ai';
export {
defineFlow,
defineJsonSchema,
defineSchema,
defineStreamingFlow,
deleteUndefinedProps,
FlowActionInputSchema,
FlowErrorSchema,
FlowInvokeEnvelopeMessageSchema,
flowMetadataPrefix,
FlowServer,
GenkitError,
GENKIT_CLIENT_HEADER,
GENKIT_VERSION,
GenkitError,
ReflectionServer,
RunActionResponseSchema,
StatusCodes,
StatusSchema,
defineFlow,
defineJsonSchema,
defineSchema,
defineStreamingFlow,
deleteUndefinedProps,
flowMetadataPrefix,
getCurrentEnv,
getFlowAuth,
getStreamingCallback,
isDevEnv,
ReflectionServer,
run,
RunActionResponseSchema,
runWithStreamingCallback,
StatusCodes,
StatusSchema,
z,
type Action,
type ActionMetadata,
Expand Down
4 changes: 2 additions & 2 deletions js/plugins/googleai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"genai",
"generative-ai"
],
"version": "0.9.0-dev.1",
"version": "0.6.0-dev.2",
"type": "commonjs",
"scripts": {
"check": "tsc",
Expand All @@ -31,7 +31,7 @@
"author": "genkit",
"license": "Apache-2.0",
"dependencies": {
"@google/generative-ai": "^0.21.0",
"@google/generative-ai": "^0.16.0",
"google-auth-library": "^9.6.3",
"node-fetch": "^3.3.2"
},
Expand Down
42 changes: 12 additions & 30 deletions js/plugins/googleai/src/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { EmbedContentRequest, GoogleGenerativeAI } from '@google/generative-ai';
import { EmbedderReference, Genkit, z } from 'genkit';
import { Genkit, z } from 'genkit';
import { embedderRef } from 'genkit/embedder';
import { PluginOptions } from './index.js';

Expand All @@ -28,21 +28,22 @@ export const TaskTypeSchema = z.enum([
]);
export type TaskType = z.infer<typeof TaskTypeSchema>;

export const GeminiEmbeddingConfigSchema = z.object({
export const TextEmbeddingGeckoConfigSchema = z.object({
/**
* The `task_type` parameter is defined as the intended downstream application to help the model
* produce better quality embeddings.
**/
taskType: TaskTypeSchema.optional(),
title: z.string().optional(),
version: z.string().optional(),
});

export type GeminiEmbeddingConfig = z.infer<typeof GeminiEmbeddingConfigSchema>;
export type TextEmbeddingGeckoConfig = z.infer<
typeof TextEmbeddingGeckoConfigSchema
>;

export const textEmbeddingGecko001 = embedderRef({
name: 'googleai/embedding-001',
configSchema: GeminiEmbeddingConfigSchema,
configSchema: TextEmbeddingGeckoConfigSchema,
info: {
dimensions: 768,
label: 'Google Gen AI - Text Embedding Gecko (Legacy)',
Expand All @@ -56,7 +57,7 @@ export const SUPPORTED_MODELS = {
'embedding-001': textEmbeddingGecko001,
};

export function defineGoogleAIEmbedder(
export function textEmbeddingGeckoEmbedder(
ai: Genkit,
name: string,
options: PluginOptions
Expand All @@ -70,36 +71,17 @@ export function defineGoogleAIEmbedder(
'Please pass in the API key or set either GOOGLE_GENAI_API_KEY or GOOGLE_API_KEY environment variable.\n' +
'For more details see https://firebase.google.com/docs/genkit/plugins/google-genai'
);
const embedder: EmbedderReference =
SUPPORTED_MODELS[name] ??
embedderRef({
name: name,
configSchema: GeminiEmbeddingConfigSchema,
info: {
dimensions: 768,
label: `Google AI - ${name}`,
supports: {
input: ['text'],
},
},
});
const apiModelName = embedder.name.startsWith('googleai/')
? embedder.name.substring('googleai/'.length)
: embedder.name;
const client = new GoogleGenerativeAI(apiKey).getGenerativeModel({
model: name,
});
const embedder = SUPPORTED_MODELS[name];
return ai.defineEmbedder(
{
name: embedder.name,
configSchema: GeminiEmbeddingConfigSchema,
configSchema: TextEmbeddingGeckoConfigSchema,
info: embedder.info!,
},
async (input, options) => {
const client = new GoogleGenerativeAI(apiKey!).getGenerativeModel({
model:
options?.version ||
embedder.config?.version ||
embedder.version ||
apiModelName,
});
const embeddings = await Promise.all(
input.map(async (doc) => {
const response = await client.embedContent({
Expand Down
Loading

0 comments on commit de8012e

Please sign in to comment.