Skip to content

Commit

Permalink
fix: fix ESM for ollama and google cloud plugin, added tests for ESM …
Browse files Browse the repository at this point in the history
…compatibility (#1379)

* fix: fix ESM for ollama and google cloud plugin, added tests for ESM compatibility

* format

* remove google auth from top level

* skip checks

* some more fixes
  • Loading branch information
pavelgj authored Nov 22, 2024
1 parent 3eff171 commit 1058511
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 32 deletions.
10 changes: 5 additions & 5 deletions js/genkit/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ export {
GenkitSpanProcessorWrapper,
InstrumentationLibrarySchema,
LinkSchema,
PathMetadata,
PathMetadataSchema,
SPAN_TYPE_ATTR,
SpanContextSchema,
SpanData,
SpanDataSchema,
SpanMetadata,
SpanMetadataSchema,
SpanStatusSchema,
TimeEventSchema,
TraceData,
TraceDataSchema,
TraceMetadata,
TraceMetadataSchema,
TraceServerExporter,
appendSpan,
Expand All @@ -46,4 +41,9 @@ export {
spanMetadataAls,
toDisplayPath,
traceMetadataAls,
type PathMetadata,
type SpanData,
type SpanMetadata,
type TraceData,
type TraceMetadata,
} from '@genkit-ai/core/tracing';
3 changes: 2 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"pack:ai": "cd ai && pnpm pack --pack-destination ../../dist",
"pack:genkit": "cd genkit && pnpm pack --pack-destination ../../dist",
"pack:plugins": "for i in plugins/*/; do cd $i && pnpm pack --pack-destination ../../../dist && cd ../..; done",
"test:all": "pnpm -r --workspace-concurrency 0 -F \"./(ai|core|plugins|genkit)/**\" test",
"test:all": "pnpm -r --workspace-concurrency 0 -F \"./(ai|core|plugins|genkit)/**\" test && pnpm test:esm",
"test:esm": "cd testapps/esm && pnpm test",
"gendocs": "pnpm build && pnpm typedoc",
"typedoc-html": "typedoc --options typedoc.json"
},
Expand Down
1 change: 0 additions & 1 deletion js/plugins/google-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"winston": "^3.12.0"
},
"peerDependencies": {
"@genkit-ai/core": "workspace:*",
"genkit": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion js/plugins/google-cloud/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { logger } from 'genkit/logging';
import { auth, GoogleAuth } from 'google-auth-library';
import { GcpPrincipal, GcpTelemetryConfig } from './types';
import { GcpPrincipal, GcpTelemetryConfig } from './types.js';

/**
* Allows Google Cloud credentials to be to passed in "raw" as an environment
Expand Down
4 changes: 2 additions & 2 deletions js/plugins/google-cloud/src/gcpLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { LoggingWinston } from '@google-cloud/logging-winston';
import { getCurrentEnv } from 'genkit';
import { logger } from 'genkit/logging';
import { Writable } from 'stream';
import { GcpTelemetryConfig } from './types';
import { loggingDenied, loggingDeniedHelpText } from './utils';
import { GcpTelemetryConfig } from './types.js';
import { loggingDenied, loggingDeniedHelpText } from './utils.js';

/**
* Additional streams for writing log data to. Useful for unit testing.
Expand Down
6 changes: 3 additions & 3 deletions js/plugins/google-cloud/src/gcpOpenTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { logger } from '@genkit-ai/core/logging';
import {
ExporterOptions,
MetricExporter,
Expand Down Expand Up @@ -50,20 +49,21 @@ import {
SpanExporter,
} from '@opentelemetry/sdk-trace-base';
import { GENKIT_VERSION } from 'genkit';
import { logger } from 'genkit/logging';
import { PathMetadata } from 'genkit/tracing';
import { actionTelemetry } from './telemetry/action.js';
import { engagementTelemetry } from './telemetry/engagement.js';
import { featuresTelemetry } from './telemetry/feature.js';
import { generateTelemetry } from './telemetry/generate.js';
import { pathsTelemetry } from './telemetry/path.js';
import { GcpTelemetryConfig } from './types';
import { GcpTelemetryConfig } from './types.js';
import {
extractErrorName,
metricsDenied,
metricsDeniedHelpText,
tracingDenied,
tracingDeniedHelpText,
} from './utils';
} from './utils.js';

let metricExporter: PushMetricExporter;
let spanProcessor: BatchSpanProcessor;
Expand Down
2 changes: 1 addition & 1 deletion js/plugins/google-cloud/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ async function configureGcpPlugin(

export * from './gcpLogger.js';
export * from './gcpOpenTelemetry.js';
export { GcpTelemetryConfigOptions } from './types.js';
export { type GcpTelemetryConfigOptions } from './types.js';
2 changes: 1 addition & 1 deletion js/plugins/google-cloud/src/telemetry/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
createCommonLogAttributes,
extractErrorName,
extractOuterFeatureNameFromPath,
} from '../utils';
} from '../utils.js';

class ActionTelemetry implements Telemetry {
/**
Expand Down
2 changes: 1 addition & 1 deletion js/plugins/google-cloud/src/telemetry/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';
import { isDevEnv } from 'genkit';
import { GcpTelemetryConfig, GcpTelemetryConfigOptions } from '../types';
import { GcpTelemetryConfig, GcpTelemetryConfigOptions } from '../types.js';

/** Consolidated defaults for telemetry configuration. */

Expand Down
4 changes: 2 additions & 2 deletions js/plugins/google-cloud/src/telemetry/engagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
MetricCounter,
Telemetry,
internalMetricNamespaceWrap,
} from '../metrics';
import { createCommonLogAttributes } from '../utils';
} from '../metrics.js';
import { createCommonLogAttributes } from '../utils.js';

class EngagementTelemetry implements Telemetry {
/**
Expand Down
4 changes: 2 additions & 2 deletions js/plugins/google-cloud/src/telemetry/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
MetricHistogram,
Telemetry,
internalMetricNamespaceWrap,
} from '../metrics';
import { createCommonLogAttributes, extractErrorName } from '../utils';
} from '../metrics.js';
import { createCommonLogAttributes, extractErrorName } from '../utils.js';

class FeaturesTelemetry implements Telemetry {
/**
Expand Down
4 changes: 2 additions & 2 deletions js/plugins/google-cloud/src/telemetry/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import {
MetricCounter,
MetricHistogram,
Telemetry,
} from '../metrics';
} from '../metrics.js';
import {
createCommonLogAttributes,
extractErrorName,
extractOuterFeatureNameFromPath,
} from '../utils';
} from '../utils.js';

type SharedDimensions = {
modelName?: string;
Expand Down
4 changes: 2 additions & 2 deletions js/plugins/google-cloud/src/telemetry/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import {
MetricHistogram,
Telemetry,
internalMetricNamespaceWrap,
} from '../metrics';
} from '../metrics.js';
import {
createCommonLogAttributes,
extractErrorMessage,
extractErrorName,
extractErrorStack,
} from '../utils';
} from '../utils.js';

class PathsTelemetry implements Telemetry {
/**
Expand Down
2 changes: 1 addition & 1 deletion js/plugins/google-cloud/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { TraceFlags } from '@opentelemetry/api';
import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
import { resolveCurrentPrincipal } from './auth';
import { resolveCurrentPrincipal } from './auth.js';

export function extractOuterFlowNameFromPath(path: string) {
if (!path || path === '<unknown>') {
Expand Down
4 changes: 2 additions & 2 deletions js/plugins/ollama/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import {
MessageData,
} from 'genkit/model';
import { GenkitPlugin, genkitPlugin } from 'genkit/plugin';
import { defineOllamaEmbedder } from './embeddings';
import { defineOllamaEmbedder } from './embeddings.js';
import {
ApiType,
ModelDefinition,
OllamaPluginParams,
RequestHeaders,
} from './types';
} from './types.js';

export { defineOllamaEmbedder };

Expand Down
2 changes: 1 addition & 1 deletion js/plugins/vertexai/src/evaluation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getDerivedParams } from '../common/index.js';
import { vertexEvaluators } from './evaluation.js';
import { PluginOptions } from './types.js';
export { VertexAIEvaluationMetricType } from './types.js';
export { PluginOptions };
export { type PluginOptions };

/**
* Add Google Cloud Vertex AI Rerankers API to Genkit.
Expand Down
3 changes: 2 additions & 1 deletion js/plugins/vertexai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
imagen3Fast,
imagenModel,
} from './imagen.js';
export type { PluginOptions } from './common/types.js';
export { type PluginOptions } from './common/types.js';
export {
gemini10Pro,
gemini15Flash,
Expand All @@ -53,6 +53,7 @@ export {
textEmbeddingGeckoMultilingual001,
textMultilingualEmbedding002,
};

/**
* Add Google Cloud Vertex AI to Genkit. Includes Gemini and Imagen models and text embedder.
*/
Expand Down
61 changes: 58 additions & 3 deletions js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/testapps/esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.genkit
Binary file added js/testapps/esm/docs/flume-java.pdf
Binary file not shown.
42 changes: 42 additions & 0 deletions js/testapps/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "rag",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"type": "module",
"scripts": {
"start": "node lib/index.js",
"dev": "tsx --watch src/index.ts",
"genkit:dev": "cross-env GENKIT_ENV=dev pnpm dev",
"compile": "tsc",
"build": "pnpm build:clean && pnpm compile",
"build:clean": "rimraf ./lib",
"build:watch": "tsc --watch",
"test": "pnpm build && node lib/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@genkit-ai/checks": "workspace:*",
"@genkit-ai/dev-local-vectorstore": "workspace:*",
"@genkit-ai/evaluator": "workspace:*",
"@genkit-ai/firebase": "workspace:*",
"@genkit-ai/google-cloud": "workspace:*",
"@genkit-ai/googleai": "workspace:*",
"@genkit-ai/vertexai": "workspace:*",
"firebase-admin": ">=12.2",
"genkit": "workspace:*",
"genkitx-chromadb": "workspace:*",
"genkitx-ollama": "workspace:*",
"genkitx-pinecone": "workspace:*",
"google-auth-library": "^9.6.3"
},
"devDependencies": {
"@types/pdf-parse": "^1.1.4",
"cross-env": "^7.0.3",
"rimraf": "^6.0.1",
"tsx": "^4.19.1",
"typescript": "^5.3.3"
}
}
1 change: 1 addition & 0 deletions js/testapps/esm/prompts/myPrompt.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ role "system" }} your name is {{ @state.userName }}, always introduce yourself)
46 changes: 46 additions & 0 deletions js/testapps/esm/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { checks } from '@genkit-ai/checks';
import { devLocalVectorstore } from '@genkit-ai/dev-local-vectorstore';
import { genkitEval } from '@genkit-ai/evaluator';
import { enableFirebaseTelemetry } from '@genkit-ai/firebase';
import { enableGoogleCloudTelemetry } from '@genkit-ai/google-cloud';
import { googleAI } from '@genkit-ai/googleai';
import { vertexAI } from '@genkit-ai/vertexai';
import { vertexAIEvaluation } from '@genkit-ai/vertexai/evaluation';
import { vertexAIModelGarden } from '@genkit-ai/vertexai/modelgarden';
import { vertexAIRerankers } from '@genkit-ai/vertexai/rerankers';
import { genkit } from 'genkit';
import { chroma } from 'genkitx-chromadb';
import { ollama } from 'genkitx-ollama';
import { pinecone } from 'genkitx-pinecone';

enableFirebaseTelemetry;
enableGoogleCloudTelemetry;
checks;
googleAI;
vertexAI;
vertexAIModelGarden;
vertexAIEvaluation;
vertexAIRerankers;
ollama;
pinecone;
chroma;
devLocalVectorstore;
genkitEval;

export const ai = genkit({});
Loading

0 comments on commit 1058511

Please sign in to comment.