Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure genkit core libs by default don't output debug messages #982

Merged
merged 4 commits into from
Oct 1, 2024
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
7 changes: 7 additions & 0 deletions js/ai/src/generateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { lookupAction } from '@genkit-ai/core/registry';
import { toJsonSchema, validateSchema } from '@genkit-ai/core/schema';
import { runInNewSpan, SPAN_TYPE_ATTR } from '@genkit-ai/core/tracing';
import * as clc from 'colorette';
import { DocumentDataSchema } from './document.js';
import { GenerateResponse, GenerateResponseChunk } from './generate.js';
import {
Expand Down Expand Up @@ -106,6 +107,12 @@ async function generate(
if (!model) {
throw new Error(`Model ${rawRequest.model} not found`);
}
if (model.__action.metadata?.model.stage === 'deprecated') {
console.warn(
`${clc.bold(clc.yellow('Warning:'))} ` +
`Model '${model.__action.name}' is deprecated and may be removed in a future release.`
);
}

let tools: ToolAction[] | undefined;
if (rawRequest.tools?.length) {
Expand Down
14 changes: 0 additions & 14 deletions js/ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
z,
} from '@genkit-ai/core';
import { toJsonSchema } from '@genkit-ai/core/schema';
import * as clc from 'colorette';
import { performance } from 'node:perf_hooks';
import { DocumentDataSchema } from './document.js';
import {
Expand Down Expand Up @@ -392,22 +391,9 @@ export function modelRef<
>(
options: ModelReference<CustomOptionsSchema>
): ModelReference<CustomOptionsSchema> {
if (options.info?.stage === 'deprecated') {
deprecateModel({ name: options.name });
}
return { ...options };
}

/**
* Warns when a model is deprecated.
*/
function deprecateModel(options: { name: string }) {
console.warn(
`${clc.bold(clc.yellow('Warning:'))} ` +
`Model '${options.name}' is deprecated and may be removed in a future release.`
);
}

/** Container for counting usage stats for a single input/output {Part} */
type PartCounts = {
characters: number;
Expand Down
4 changes: 2 additions & 2 deletions js/core/src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export class FlowServer {

this.port = await this.findPort();
this.server = server.listen(this.port, () => {
logger.info(`Flow server running on http://localhost:${this.port}`);
logger.debug(`Flow server running on http://localhost:${this.port}`);
FlowServer.RUNNING_SERVERS.push(this);
});
}
Expand All @@ -525,7 +525,7 @@ export class FlowServer {
if (index > -1) {
FlowServer.RUNNING_SERVERS.splice(index, 1);
}
logger.info(
logger.debug(
`Flow server on port ${this.port} has successfully shut down.`
);
this.port = null;
Expand Down
6 changes: 4 additions & 2 deletions js/core/src/reflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export class ReflectionServer {

this.port = await this.findPort();
this.server = server.listen(this.port, () => {
logger.info(`Reflection server running on http://localhost:${this.port}`);
logger.debug(
`Reflection server running on http://localhost:${this.port}`
);
ReflectionServer.RUNNING_SERVERS.push(this);
});
}
Expand All @@ -270,7 +272,7 @@ export class ReflectionServer {
if (index > -1) {
ReflectionServer.RUNNING_SERVERS.splice(index, 1);
}
logger.info(
logger.debug(
`Reflection server on port ${this.port} has successfully shut down.`
);
this.port = null;
Expand Down
1 change: 1 addition & 0 deletions js/core/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export class Registry {
action: Action<I, O>
) {
const key = `/${type}/${action.__action.name}`;
logger.debug(`registering ${key}`);
if (this.actionsById.hasOwnProperty(key)) {
// TODO: Make this an error!
logger.warn(
Expand Down
4 changes: 2 additions & 2 deletions js/genkit/src/genkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class Genkit {
this.reflectionServer = new ReflectionServer(this.registry, {
configuredEnvs: [...this.configuredEnvs],
});
this.reflectionServer.start();
this.reflectionServer.start().catch((e) => logger.error);
}
if (this.options.flowServer) {
const flowServerOptions =
Expand Down Expand Up @@ -337,7 +337,7 @@ export class Genkit {
activeRegistry.registerPluginProvider(plugin.name, {
name: plugin.name,
async initializer() {
logger.info(`Initializing plugin ${plugin.name}:`);
logger.debug(`Initializing plugin ${plugin.name}:`);
return runWithRegistry(activeRegistry, () => plugin.initializer());
},
});
Expand Down
4 changes: 1 addition & 3 deletions js/plugins/google-cloud/src/gcpOpenTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ import {
} from '@opentelemetry/sdk-trace-base';
import { GENKIT_VERSION } from 'genkit';
import { PathMetadata } from 'genkit/tracing';

import { extractErrorName } from './utils';

import { actionTelemetry } from './telemetry/action.js';
import { flowsTelemetry } from './telemetry/flow.js';
import { generateTelemetry } from './telemetry/generate.js';
import { GcpTelemetryConfig } from './types';
import { extractErrorName } from './utils';

let metricExporter: PushMetricExporter;
let spanProcessor: BatchSpanProcessor;
Expand Down
10 changes: 5 additions & 5 deletions js/plugins/google-cloud/tests/traces_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

import {
__forceFlushSpansForTesting,
__getSpanExporterForTesting,
enableGoogleCloudTelemetry,
} from '@genkit-ai/google-cloud';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { Genkit, genkit, run, z } from 'genkit';
import assert from 'node:assert';
import { after, before, beforeEach, describe, it } from 'node:test';
import {
__forceFlushSpansForTesting,
__getSpanExporterForTesting,
} from '../src/gcpOpenTelemetry.js';
import { enableGoogleCloudTelemetry } from '../src/index.js';

describe('GoogleCloudTracing', () => {
let ai: Genkit;
Expand Down
Loading