Skip to content

Commit

Permalink
Update input and reference schema types in DatasetSchema to match tho…
Browse files Browse the repository at this point in the history
…se in ActionSchema
  • Loading branch information
shrutip90 committed Nov 13, 2024
1 parent 9c5840b commit 4800b08
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
3 changes: 3 additions & 0 deletions genkit-tools/common/src/eval/localFileDatasetStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class LocalFileDatasetStore implements DatasetStore {
req: CreateDatasetRequest
): Promise<DatasetMetadata> {
const { data, datasetId, schema, targetAction } = req;

console.log("Schema set to", schema);
const id = await this.generateDatasetId(datasetId);
const filePath = path.resolve(this.storeRoot, this.generateFileName(id));

Expand All @@ -96,6 +98,7 @@ export class LocalFileDatasetStore implements DatasetStore {
updateTime: now,
};

console.log("Dataset metadata set to", schema);
let metadataMap = await this.getMetadataMap();
metadataMap[id] = metadata;

Expand Down
15 changes: 5 additions & 10 deletions genkit-tools/common/src/types/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { z } from 'zod';
import { CustomAnySchema, JSONSchema7Schema } from './action';
import {
CreateDatasetRequest,
ListEvalKeysRequest,
Expand Down Expand Up @@ -160,16 +161,10 @@ export interface EvalStore {
list(query?: ListEvalKeysRequest): Promise<ListEvalKeysResponse>;
}

export const DatasetSchemaSchema = z.object({
inputSchema: z
.record(z.any())
.describe('Valid JSON Schema for the `input` field of dataset entry.')
.optional(),
referenceSchema: z
.record(z.any())
.describe('Valid JSON Schema for the `reference` field of dataset entry.')
.optional(),
});
export const DatasetSchemaSchema = z
.record(z.string(), CustomAnySchema)
.describe('Schema objects related to the dataset.')
.nullish();

/**
* Metadata for Dataset objects containing version, create and update time, etc.
Expand Down
53 changes: 29 additions & 24 deletions genkit-tools/common/tests/eval/localFileDatasetStore_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,30 @@ const CREATE_DATASET_REQUEST = CreateDatasetRequestSchema.parse({
data: { samples: SAMPLE_DATASET_1_V1 },
});

const INPUT_SCHEMA = {
"type": "string",
"$schema": "http://json-schema.org/draft-07/schema#"
};

const REFERENCE_SCHEMA = {
"type": "object",
"properties": {
"output": {
"type": "string"
},
},
"required": [
"output",
],
"additionalProperties": true,
"$schema": "http://json-schema.org/draft-07/schema#"
};

const CREATE_DATASET_REQUEST_WITH_SCHEMA = CreateDatasetRequestSchema.parse({
data: { samples: SAMPLE_DATASET_1_V1 },
schema: {
inputSchema: {
type: 'string',
$schema: 'http://json-schema.org/draft-07/schema#',
},
referenceSchema: {
type: 'number',
$schema: 'http://json-schema.org/draft-07/schema#',
},
"inputSchema": INPUT_SCHEMA,
"referenceSchema": REFERENCE_SCHEMA,
},
targetAction: '/flow/my-flow',
});
Expand Down Expand Up @@ -235,20 +248,16 @@ describe('localFileDatasetStore', () => {
...s,
}));

console.log("CREATE_DATASET_REQUEST_WITH_SCHEMA schema", CREATE_DATASET_REQUEST_WITH_SCHEMA.schema);

const datasetMetadata = await DatasetStore.createDataset({
...CREATE_DATASET_REQUEST_WITH_SCHEMA,
datasetId: SAMPLE_DATASET_ID_1,
});

expect(datasetMetadata.schema).toMatchObject({
inputSchema: {
type: 'string',
$schema: 'http://json-schema.org/draft-07/schema#',
},
referenceSchema: {
type: 'number',
$schema: 'http://json-schema.org/draft-07/schema#',
},
inputSchema: INPUT_SCHEMA,
referenceSchema: REFERENCE_SCHEMA,
});
expect(datasetMetadata.targetAction).toEqual('/flow/my-flow');
});
Expand Down Expand Up @@ -415,19 +424,15 @@ describe('localFileDatasetStore', () => {
const datasetMetadata = await DatasetStore.updateDataset({
datasetId: SAMPLE_DATASET_ID_1,
schema: {
inputSchema: {
type: 'string',
$schema: 'http://json-schema.org/draft-07/schema#',
},
inputSchema: INPUT_SCHEMA,
referenceSchema: REFERENCE_SCHEMA,
},
targetAction: '/flow/my-flow-2',
});

expect(datasetMetadata.schema).toMatchObject({
inputSchema: {
type: 'string',
$schema: 'http://json-schema.org/draft-07/schema#',
},
inputSchema: INPUT_SCHEMA,
referenceSchema: REFERENCE_SCHEMA,
});
expect(datasetMetadata.targetAction).toEqual('/flow/my-flow-2');
});
Expand Down

0 comments on commit 4800b08

Please sign in to comment.