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
2 changes: 1 addition & 1 deletion genkit-tools/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "genkit",
"name": "genkit-cli",
"version": "0.6.0-dev.1",
"description": "CLI for interacting with the Google GenKit AI framework",
"license": "Apache-2.0",
Expand Down
3 changes: 1 addition & 2 deletions js/ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"colorette": "^2.0.20",
"json5": "^2.2.3",
"node-fetch": "^3.3.2",
"partial-json": "^0.1.7",
"zod": "^3.22.4"
"partial-json": "^0.1.7"
},
"devDependencies": {
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import z from 'zod';
import { z } from '@genkit-ai/core';

const EmptyPartSchema = z.object({
text: z.never().optional(),
Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { Action, defineAction } from '@genkit-ai/core';
import { Action, defineAction, z } from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import * as z from 'zod';
import { Document, DocumentData, DocumentDataSchema } from './document.js';

export type EmbeddingBatch = { embedding: number[] }[];
Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import { Action, defineAction } from '@genkit-ai/core';
import { Action, defineAction, z } from '@genkit-ai/core';
import { logger } from '@genkit-ai/core/logging';
import { lookupAction } from '@genkit-ai/core/registry';
import { SPAN_TYPE_ATTR, runInNewSpan } from '@genkit-ai/core/tracing';
import * as z from 'zod';

export const ATTR_PREFIX = 'genkit';
export const SPAN_STATE_ATTR = ATTR_PREFIX + ':state';
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
GenkitError,
runWithStreamingCallback,
StreamingCallback,
z,
} from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import { toJsonSchema, validateSchema } from '@genkit-ai/core/schema';
import { z } from 'zod';
import { DocumentData } from './document.js';
import { extractJson } from './extract.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/generateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getStreamingCallback,
Middleware,
runWithStreamingCallback,
z,
} from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import {
Expand All @@ -27,7 +28,6 @@ import {
validateSchema,
} from '@genkit-ai/core/schema';
import { runInNewSpan, SPAN_TYPE_ATTR } from '@genkit-ai/core/tracing';
import { z } from 'zod';
import { DocumentDataSchema } from './document.js';
import {
Candidate,
Expand Down
33 changes: 32 additions & 1 deletion js/ai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
* limitations under the License.
*/

export { Document, DocumentData, DocumentDataSchema } from './document.js';
export {
embed,
embedderRef,
type EmbedderAction,
type EmbedderArgument,
type EmbedderInfo,
type EmbedderReference,
} from './embedder.js';
export {
evaluate,
evaluatorRef,
Expand All @@ -39,22 +48,44 @@ export {
GenerateResponseData,
GenerationUsage,
MediaPart,
MessageData,
MessageSchema,
ModelArgument,
ModelReference,
Part,
PartSchema,
Role,
RoleSchema,
ToolRequestPart,
ToolResponsePart,
} from './model.js';
export { definePrompt, renderPrompt, type PromptAction } from './prompt.js';
export {
rerank,
rerankerRef,
type RerankerAction,
type RerankerArgument,
type RerankerInfo,
type RerankerReference,
} from './reranker.js';
export {
index,
indexerRef,
retrieve,
retrieverRef,
type IndexerAction,
type IndexerArgument,
type IndexerInfo,
type IndexerReference,
type RetrieverAction,
type RetrieverArgument,
type RetrieverInfo,
type RetrieverReference,
} from './retriever.js';
export { asTool, defineTool, type ToolAction } from './tool.js';
export {
asTool,
defineTool,
type ToolAction,
type ToolArgument,
} from './tool.js';
export * from './types.js';
2 changes: 1 addition & 1 deletion js/ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import {
getStreamingCallback,
Middleware,
StreamingCallback,
z,
} from '@genkit-ai/core';
import { toJsonSchema } from '@genkit-ai/core/schema';
import * as clc from 'colorette';
import { performance } from 'node:perf_hooks';
import { z } from 'zod';
import { DocumentDataSchema } from './document.js';
import {
augmentWithContext,
Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { Action, defineAction, JSONSchema7 } from '@genkit-ai/core';
import { Action, defineAction, JSONSchema7, z } from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import z from 'zod';
import { DocumentData } from './document.js';
import { GenerateOptions } from './generate.js';
import {
Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/reranker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { Action, defineAction } from '@genkit-ai/core';
import { Action, defineAction, z } from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import * as z from 'zod';
import { Part, PartSchema } from './document.js';
import { Document, DocumentData, DocumentDataSchema } from './retriever.js';

Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { Action, GenkitError, defineAction } from '@genkit-ai/core';
import { Action, GenkitError, defineAction, z } from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import * as z from 'zod';
import { Document, DocumentData, DocumentDataSchema } from './document.js';
import { EmbedderInfo } from './embedder.js';

Expand Down
32 changes: 16 additions & 16 deletions js/ai/src/testing/model-tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import { z } from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import { runInNewSpan } from '@genkit-ai/core/tracing';
import assert from 'node:assert';
import z from 'zod';
import { generate } from '../generate';
import { ModelAction } from '../model';
import { defineTool } from '../tool';
Expand Down Expand Up @@ -128,7 +128,7 @@ const tests: Record<string, TestCase> = {
const response = await generate({
model,
prompt: 'what is a gablorken of 2? use provided tool',
tools: [gablorkenTool],
tools: ['gablorkenTool'],
});

const got = response.text().trim();
Expand All @@ -151,21 +151,21 @@ type TestReport = {

type TestCase = (model: string) => Promise<void>;

const gablorkenTool = defineTool(
{
name: 'gablorkenTool',
description: 'use when need to calculate a gablorken',
inputSchema: z.object({
value: z.number(),
}),
outputSchema: z.number(),
},
async (input) => {
return Math.pow(input.value, 3) + 1.407;
}
);

export async function testModels(models: string[]): Promise<TestReport> {
const gablorkenTool = defineTool(
{
name: 'gablorkenTool',
description: 'use when need to calculate a gablorken',
inputSchema: z.object({
value: z.number(),
}),
outputSchema: z.number(),
},
async (input) => {
return Math.pow(input.value, 3) + 1.407;
}
);

return await runInNewSpan({ metadata: { name: 'testModels' } }, async () => {
const report: TestReport = [];
for (const test of Object.keys(tests)) {
Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import { Action, defineAction, JSONSchema7 } from '@genkit-ai/core';
import { Action, defineAction, JSONSchema7, z } from '@genkit-ai/core';
import { lookupAction } from '@genkit-ai/core/registry';
import { toJsonSchema } from '@genkit-ai/core/schema';
import { setCustomMetadataAttributes } from '@genkit-ai/core/tracing';
import z from 'zod';
import { ToolDefinition } from './model.js';

export type ToolAction<
Expand Down
3 changes: 1 addition & 2 deletions js/ai/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { Action } from '@genkit-ai/core';
import { Action, z } from '@genkit-ai/core';
import { toJsonSchema } from '@genkit-ai/core/schema';
import { z } from 'zod';

export const ModelIdSchema = z.object({
modelProvider: z.string().readonly(),
Expand Down
2 changes: 1 addition & 1 deletion js/ai/tests/generate/generate_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import { z } from '@genkit-ai/core';
import { Registry, runWithRegistry } from '@genkit-ai/core/registry';
import assert from 'node:assert';
import { beforeEach, describe, it } from 'node:test';
import { z } from 'zod';
import { GenerateResponseChunk } from '../../lib/generate.js';
import { GenerateResponseChunkData } from '../../lib/model.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion js/ai/tests/prompt/prompt_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import { z } from '@genkit-ai/core';
import { Registry, runWithRegistry } from '@genkit-ai/core/registry';
import assert from 'node:assert';
import { describe, it } from 'node:test';
import * as z from 'zod';
import { definePrompt, renderPrompt } from '../../src/prompt.ts';

describe('prompt', () => {
Expand Down
3 changes: 1 addition & 2 deletions js/ai/tests/reranker/reranker_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import { GenkitError } from '@genkit-ai/core';
import { GenkitError, z } from '@genkit-ai/core';
import { Registry, runWithRegistry } from '@genkit-ai/core/registry';
import assert from 'node:assert';
import { beforeEach, describe, it } from 'node:test';
import * as z from 'zod';
import { defineReranker, rerank } from '../../src/reranker';
import { Document } from '../../src/retriever';

Expand Down
8 changes: 1 addition & 7 deletions js/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"express": "^4.19.2",
"get-port": "^5.1.0",
"json-schema": "^0.4.0",
"zod": "^3.22.4",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.22.4"
},
"devDependencies": {
Expand All @@ -60,12 +60,6 @@
"import": "./lib/index.mjs",
"default": "./lib/index.js"
},
"./metrics": {
"types": "./lib/metrics.d.ts",
"require": "./lib/metrics.js",
"import": "./lib/metrics.mjs",
"default": "./lib/metrics.js"
},
"./registry": {
"types": "./lib/registry.d.ts",
"require": "./lib/registry.js",
Expand Down
2 changes: 1 addition & 1 deletion js/core/src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cors, { CorsOptions } from 'cors';
import express from 'express';
import getPort, { makeRange } from 'get-port';
import { Server } from 'http';
import * as z from 'zod';
import { z } from 'zod';
import {
Action,
defineAction,
Expand Down
1 change: 1 addition & 0 deletions js/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { version } from './__codegen/version.js';
export const GENKIT_VERSION = version;
export const GENKIT_CLIENT_HEADER = `genkit-node/${GENKIT_VERSION} gl-node/${process.versions.node}`;

export { z } from 'zod';
export * from './action.js';
export { getFlowAuth } from './auth.js';
export { GenkitError } from './error.js';
Expand Down
6 changes: 6 additions & 0 deletions js/core/src/reflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import getPort, { makeRange } from 'get-port';
import { Server } from 'http';
import z from 'zod';
import { Status, StatusCodes, runWithStreamingCallback } from './action.js';
import { GENKIT_VERSION } from './index.js';
import { logger } from './logging.js';
import { Registry, runWithRegistry } from './registry.js';
import { toJsonSchema } from './schema.js';
Expand Down Expand Up @@ -102,6 +103,11 @@ export class ReflectionServer {
const server = express();

server.use(express.json({ limit: this.options.bodyLimit }));
server.use(function (req, res, next) {
res.header('x-genkit-version', GENKIT_VERSION);
next();
});

server.use((req: Request, res: Response, next: NextFunction) => {
runWithRegistry(this.registry, async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion js/core/tests/flow_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import { z } from '@genkit-ai/core';
import assert from 'node:assert';
import { beforeEach, describe, it } from 'node:test';
import { z } from 'zod';
import { Genkit, genkit } from '../src/genkit.js';

function createTestFlow(ai: Genkit) {
Expand Down
Empty file added js/genkit/.npmignore
Empty file.
Loading