Skip to content

Commit 2dd7a8f

Browse files
committed
refine design
1 parent ded26b7 commit 2dd7a8f

File tree

4 files changed

+168
-64
lines changed

4 files changed

+168
-64
lines changed

common/api-review/vertexai-preview.api.md

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ import { FirebaseApp } from '@firebase/app';
99
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
1010
import { FirebaseError } from '@firebase/util';
1111

12+
// @public (undocumented)
13+
export class ArraySchema extends Schema {
14+
// Warning: (ae-forgotten-export) The symbol "SchemaParams" needs to be exported by the entry point index.d.ts
15+
constructor(schemaParams: SchemaParams, items: TypedSchema);
16+
// (undocumented)
17+
items: TypedSchema;
18+
// Warning: (ae-forgotten-export) The symbol "_SchemaRequest" needs to be exported by the entry point index.d.ts
19+
//
20+
// (undocumented)
21+
toJSON(): _SchemaRequest;
22+
}
23+
1224
// @public
1325
export interface BaseParams {
1426
// (undocumented)
@@ -27,6 +39,11 @@ export enum BlockReason {
2739
SAFETY = "SAFETY"
2840
}
2941

42+
// @public (undocumented)
43+
export class BooleanSchema extends Schema {
44+
constructor(schemaParams?: SchemaParams);
45+
}
46+
3047
// @public
3148
export class ChatSession {
3249
// Warning: (ae-forgotten-export) The symbol "ApiSettings" needs to be exported by the entry point index.d.ts
@@ -203,7 +220,6 @@ export interface FunctionCallPart {
203220
export interface FunctionDeclaration {
204221
description?: string;
205222
name: string;
206-
// Warning: (ae-forgotten-export) The symbol "ObjectSchema" needs to be exported by the entry point index.d.ts
207223
parameters?: ObjectSchema;
208224
}
209225

@@ -297,8 +313,6 @@ export interface GenerationConfig {
297313
// (undocumented)
298314
presencePenalty?: number;
299315
responseMimeType?: string;
300-
// Warning: (ae-forgotten-export) The symbol "TypedSchema" needs to be exported by the entry point index.d.ts
301-
//
302316
// (undocumented)
303317
responseSchema?: TypedSchema;
304318
// (undocumented)
@@ -448,6 +462,11 @@ export interface InlineDataPart {
448462
videoMetadata?: VideoMetadata;
449463
}
450464

465+
// @public (undocumented)
466+
export class IntegerSchema extends Schema {
467+
constructor(schemaParams?: SchemaParams);
468+
}
469+
451470
// @public
452471
export interface ModelParams extends BaseParams {
453472
// (undocumented)
@@ -460,6 +479,24 @@ export interface ModelParams extends BaseParams {
460479
tools?: Tool[];
461480
}
462481

482+
// @public (undocumented)
483+
export class NumberSchema extends Schema {
484+
constructor(schemaParams?: SchemaParams);
485+
}
486+
487+
// @public (undocumented)
488+
export class ObjectSchema extends Schema {
489+
constructor(schemaParams: SchemaParams, properties: {
490+
[k: string]: TypedSchema;
491+
});
492+
// (undocumented)
493+
properties: {
494+
[k: string]: TypedSchema;
495+
};
496+
// (undocumented)
497+
toJSON(): _SchemaRequest;
498+
}
499+
463500
// @public
464501
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
465502

@@ -519,6 +556,49 @@ export interface SafetySetting {
519556
threshold: HarmBlockThreshold;
520557
}
521558

559+
// Warning: (ae-forgotten-export) The symbol "SchemaInterface" needs to be exported by the entry point index.d.ts
560+
//
561+
// @public (undocumented)
562+
export abstract class Schema implements SchemaInterface {
563+
constructor(schemaParams: SchemaInterface);
564+
// (undocumented)
565+
static array(arrayParams: SchemaParams & {
566+
items: Schema;
567+
}): ArraySchema;
568+
// (undocumented)
569+
static boolean(booleanParams?: SchemaParams): BooleanSchema;
570+
description?: string;
571+
// (undocumented)
572+
static enumString(stringParams: SchemaParams & {
573+
enum: string[];
574+
}): StringSchema;
575+
example?: unknown;
576+
format?: string;
577+
// (undocumented)
578+
static functionDeclaration(objectParams: SchemaParams & {
579+
properties: {
580+
[k: string]: Schema;
581+
};
582+
}): ObjectSchema;
583+
// (undocumented)
584+
static integer(integerParams?: SchemaParams): IntegerSchema;
585+
nullable: boolean;
586+
// (undocumented)
587+
static number(numberParams?: SchemaParams): NumberSchema;
588+
// (undocumented)
589+
static object(objectParams: SchemaParams & {
590+
properties: {
591+
[k: string]: Schema;
592+
};
593+
}): ObjectSchema;
594+
required: boolean;
595+
// (undocumented)
596+
static string(stringParams?: SchemaParams): StringSchema;
597+
toJSON(): _SchemaRequest;
598+
// Warning: (ae-forgotten-export) The symbol "SchemaType" needs to be exported by the entry point index.d.ts
599+
type: SchemaType;
600+
}
601+
522602
// @public (undocumented)
523603
export interface Segment {
524604
// (undocumented)
@@ -541,6 +621,15 @@ export interface StartChatParams extends BaseParams {
541621
tools?: Tool[];
542622
}
543623

624+
// @public (undocumented)
625+
export class StringSchema extends Schema {
626+
constructor(schemaParams?: SchemaParams, enumValues?: string[]);
627+
// (undocumented)
628+
enum?: string[];
629+
// (undocumented)
630+
toJSON(): _SchemaRequest;
631+
}
632+
544633
// @public
545634
export interface TextPart {
546635
// (undocumented)
@@ -562,6 +651,9 @@ export interface ToolConfig {
562651
functionCallingConfig: FunctionCallingConfig;
563652
}
564653

654+
// @public (undocumented)
655+
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
656+
565657
// @public
566658
export interface UsageMetadata {
567659
// (undocumented)

packages/vertexai/src/requests/schema-builder.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,38 @@ use(sinonChai);
2323

2424
describe.only('Schema builder', () => {
2525
it('builds integer schema', () => {
26-
const schema = Schema.createInteger();
26+
const schema = Schema.integer();
2727
expect(schema.toJSON()).to.eql({
2828
type: 'integer',
2929
nullable: false
3030
});
3131
});
3232
it('builds number schema', () => {
33-
const schema = Schema.createNumber();
33+
const schema = Schema.number();
3434
expect(schema.toJSON()).to.eql({
3535
type: 'number',
3636
nullable: false
3737
});
3838
});
3939
it('builds boolean schema', () => {
40-
const schema = Schema.createBoolean();
40+
const schema = Schema.boolean();
4141
expect(schema.toJSON()).to.eql({
4242
type: 'boolean',
4343
nullable: false
4444
});
4545
});
4646
it('builds string schema', () => {
47-
const schema = Schema.createString({ description: 'hey' });
47+
const schema = Schema.string({ description: 'hey' });
4848
expect(schema.toJSON()).to.eql({
4949
type: 'string',
5050
description: 'hey',
5151
nullable: false
5252
});
5353
});
5454
it('builds enumString schema', () => {
55-
const schema = Schema.createEnumString({
55+
const schema = Schema.enumString({
5656
example: 'east',
57-
enumValues: ['east', 'west']
57+
enum: ['east', 'west']
5858
});
5959
expect(schema.toJSON()).to.eql({
6060
type: 'string',
@@ -64,9 +64,9 @@ describe.only('Schema builder', () => {
6464
});
6565
});
6666
it('builds functionDeclaration schema', () => {
67-
const schema = Schema.createFunctionDeclaration({
67+
const schema = Schema.functionDeclaration({
6868
properties: {
69-
'someInput': Schema.createString()
69+
'someInput': Schema.string()
7070
}
7171
});
7272
expect(schema.toJSON()).to.eql({
@@ -82,39 +82,39 @@ describe.only('Schema builder', () => {
8282
});
8383
});
8484
it('builds layered schema', () => {
85-
const schema = Schema.createArray({
86-
items: Schema.createObject({
85+
const schema = Schema.array({
86+
items: Schema.object({
8787
properties: {
88-
country: Schema.createString({
88+
country: Schema.string({
8989
description: 'some country',
9090
required: true
9191
}),
92-
population: Schema.createInteger(),
93-
coordinates: Schema.createObject({
92+
population: Schema.integer(),
93+
coordinates: Schema.object({
9494
properties: {
95-
latitude: Schema.createNumber({ format: 'float' }),
96-
longitude: Schema.createNumber({ format: 'double' })
95+
latitude: Schema.number({ format: 'float' }),
96+
longitude: Schema.number({ format: 'double' })
9797
}
9898
}),
99-
hemisphere: Schema.createObject({
99+
hemisphere: Schema.object({
100100
properties: {
101-
latitudinal: Schema.createEnumString({ enumValues: ['N', 'S'] }),
102-
longitudinal: Schema.createEnumString({ enumValues: ['E', 'W'] })
101+
latitudinal: Schema.enumString({ enum: ['N', 'S'] }),
102+
longitudinal: Schema.enumString({ enum: ['E', 'W'] })
103103
}
104104
}),
105-
isCapital: Schema.createBoolean()
105+
isCapital: Schema.boolean()
106106
}
107107
})
108108
});
109109

110110
expect(schema.toJSON()).to.eql(layeredSchemaOutput);
111111
});
112112
it('can override the "required" and "nullable" properties', () => {
113-
const schema = Schema.createObject({
113+
const schema = Schema.object({
114114
properties: {
115-
country: Schema.createString(),
116-
elevation: Schema.createNumber({ required: false }),
117-
population: Schema.createInteger({ nullable: true })
115+
country: Schema.string(),
116+
elevation: Schema.number({ required: false }),
117+
population: Schema.integer({ nullable: true })
118118
}
119119
});
120120
expect(schema.toJSON()).to.eql({

0 commit comments

Comments
 (0)