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

Allow Schema types to be written as inline string literals. #295

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/lemon-kiwis-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@google/generative-ai": patch
---

Schema types can be written as either references to the enum, or as inline string literals, the type checker will now accept either.
19 changes: 11 additions & 8 deletions common/api-review/generative-ai-server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,17 @@ export interface RpcStatus {
export type Schema = StringSchema | NumberSchema | IntegerSchema | BooleanSchema | ArraySchema | ObjectSchema;

// @public
export enum SchemaType {
ARRAY = "array",
BOOLEAN = "boolean",
INTEGER = "integer",
NUMBER = "number",
OBJECT = "object",
STRING = "string"
}
export const SchemaType: {
readonly STRING: "string";
readonly NUMBER: "number";
readonly INTEGER: "integer";
readonly BOOLEAN: "boolean";
readonly ARRAY: "array";
readonly OBJECT: "object";
};

// @public (undocumented)
export type SchemaType = typeof SchemaType extends Record<string, infer R> ? R : never;

// @public
export interface SingleRequestOptions extends RequestOptions {
Expand Down
19 changes: 11 additions & 8 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -789,14 +789,17 @@ export interface SafetySetting {
export type Schema = StringSchema | NumberSchema | IntegerSchema | BooleanSchema | ArraySchema | ObjectSchema;

// @public
export enum SchemaType {
ARRAY = "array",
BOOLEAN = "boolean",
INTEGER = "integer",
NUMBER = "number",
OBJECT = "object",
STRING = "string"
}
export const SchemaType: {
readonly STRING: "string";
readonly NUMBER: "number";
readonly INTEGER: "integer";
readonly BOOLEAN: "boolean";
readonly ARRAY: "array";
readonly OBJECT: "object";
};

// @public (undocumented)
export type SchemaType = typeof SchemaType extends Record<string, infer R> ? R : never;

// @public
export interface SearchEntryPoint {
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.arrayschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export interface ArraySchema extends BaseSchema
| [items](./generative-ai.arrayschema.items.md) | | [Schema](./generative-ai.schema.md) | A schema describing the entries in the array. |
| [maxItems?](./generative-ai.arrayschema.maxitems.md) | | number | _(Optional)_ The maximum number of items in the array. |
| [minItems?](./generative-ai.arrayschema.minitems.md) | | number | _(Optional)_ The minimum number of items in the array. |
| [type](./generative-ai.arrayschema.type.md) | | typeof [SchemaType.ARRAY](./generative-ai.schematype.md) | |
| [type](./generative-ai.arrayschema.type.md) | | typeof SchemaType.ARRAY | |

2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.booleanschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface BooleanSchema extends BaseSchema

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [type](./generative-ai.booleanschema.type.md) | | typeof [SchemaType.BOOLEAN](./generative-ai.schematype.md) | |
| [type](./generative-ai.booleanschema.type.md) | | typeof SchemaType.BOOLEAN | |

2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.integerschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface IntegerSchema extends BaseSchema
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [format?](./generative-ai.integerschema.format.md) | | "int32" \| "int64" | _(Optional)_ Optional. The format of the number. |
| [type](./generative-ai.integerschema.type.md) | | typeof [SchemaType.INTEGER](./generative-ai.schematype.md) | |
| [type](./generative-ai.integerschema.type.md) | | typeof SchemaType.INTEGER | |

3 changes: 2 additions & 1 deletion docs/reference/main/generative-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
| [HarmCategory](./generative-ai.harmcategory.md) | Harm categories that would cause prompts or candidates to be blocked. |
| [HarmProbability](./generative-ai.harmprobability.md) | Probability that a prompt or candidate matches a harm category. |
| [Outcome](./generative-ai.outcome.md) | Possible outcomes of code execution. |
| [SchemaType](./generative-ai.schematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ |
| [TaskType](./generative-ai.tasktype.md) | Task type for embedding content. |

## Interfaces
Expand Down Expand Up @@ -109,6 +108,7 @@
| Variable | Description |
| --- | --- |
| [POSSIBLE\_ROLES](./generative-ai.possible_roles.md) | Possible roles. |
| [SchemaType](./generative-ai.schematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ |

## Type Aliases

Expand All @@ -118,5 +118,6 @@
| [Part](./generative-ai.part.md) | Content part - includes text or image part types. |
| [ResponseSchema](./generative-ai.responseschema.md) | Schema passed to <code>GenerationConfig.responseSchema</code> |
| [Schema](./generative-ai.schema.md) | Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object. More fields may be added in the future as needed. |
| [SchemaType](./generative-ai.schematype.md) | |
| [Tool](./generative-ai.tool.md) | Defines a tool that model can call to access external knowledge. |

2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.numberschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface NumberSchema extends BaseSchema
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [format?](./generative-ai.numberschema.format.md) | | "float" \| "double" | _(Optional)_ Optional. The format of the number. |
| [type](./generative-ai.numberschema.type.md) | | typeof [SchemaType.NUMBER](./generative-ai.schematype.md) | |
| [type](./generative-ai.numberschema.type.md) | | typeof SchemaType.NUMBER | |

2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.objectschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export interface ObjectSchema extends BaseSchema
| --- | --- | --- | --- |
| [properties](./generative-ai.objectschema.properties.md) | | { \[k: string\]: [Schema](./generative-ai.schema.md)<!-- -->; } | Describes the properties of the JSON object. Must not be empty. |
| [required?](./generative-ai.objectschema.required.md) | | string\[\] | _(Optional)_ A list of keys declared in the properties object. Required properties will always be present in the generated object. |
| [type](./generative-ai.objectschema.type.md) | | typeof [SchemaType.OBJECT](./generative-ai.schematype.md) | |
| [type](./generative-ai.objectschema.type.md) | | typeof SchemaType.OBJECT | |

23 changes: 9 additions & 14 deletions docs/reference/main/generative-ai.schematype.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [SchemaType](./generative-ai.schematype.md)

## SchemaType enum
## SchemaType variable

Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/

**Signature:**

```typescript
export declare enum SchemaType
SchemaType: {
readonly STRING: "string";
readonly NUMBER: "number";
readonly INTEGER: "integer";
readonly BOOLEAN: "boolean";
readonly ARRAY: "array";
readonly OBJECT: "object";
}
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| ARRAY | <code>&quot;array&quot;</code> | Array type. |
| BOOLEAN | <code>&quot;boolean&quot;</code> | Boolean type. |
| INTEGER | <code>&quot;integer&quot;</code> | Integer type. |
| NUMBER | <code>&quot;number&quot;</code> | Number type. |
| OBJECT | <code>&quot;object&quot;</code> | Object type. |
| STRING | <code>&quot;string&quot;</code> | String type. |

2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.stringschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface StringSchema extends BaseSchema
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [enum?](./generative-ai.stringschema.enum.md) | | string\[\] | _(Optional)_ If present, limits the result to one of the given values. |
| [type](./generative-ai.stringschema.type.md) | | typeof [SchemaType.STRING](./generative-ai.schematype.md) | |
| [type](./generative-ai.stringschema.type.md) | | typeof SchemaType.STRING | |

2 changes: 1 addition & 1 deletion docs/reference/server/generative-ai.arrayschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export interface ArraySchema extends BaseSchema
| [items](./generative-ai.arrayschema.items.md) | | [Schema](./generative-ai.schema.md) | A schema describing the entries in the array. |
| [maxItems?](./generative-ai.arrayschema.maxitems.md) | | number | _(Optional)_ The maximum number of items in the array. |
| [minItems?](./generative-ai.arrayschema.minitems.md) | | number | _(Optional)_ The minimum number of items in the array. |
| [type](./generative-ai.arrayschema.type.md) | | typeof [SchemaType.ARRAY](./generative-ai.schematype.md) | |
| [type](./generative-ai.arrayschema.type.md) | | typeof SchemaType.ARRAY | |

2 changes: 1 addition & 1 deletion docs/reference/server/generative-ai.booleanschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface BooleanSchema extends BaseSchema

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [type](./generative-ai.booleanschema.type.md) | | typeof [SchemaType.BOOLEAN](./generative-ai.schematype.md) | |
| [type](./generative-ai.booleanschema.type.md) | | typeof SchemaType.BOOLEAN | |

2 changes: 1 addition & 1 deletion docs/reference/server/generative-ai.integerschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface IntegerSchema extends BaseSchema
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [format?](./generative-ai.integerschema.format.md) | | "int32" \| "int64" | _(Optional)_ Optional. The format of the number. |
| [type](./generative-ai.integerschema.type.md) | | typeof [SchemaType.INTEGER](./generative-ai.schematype.md) | |
| [type](./generative-ai.integerschema.type.md) | | typeof SchemaType.INTEGER | |

8 changes: 7 additions & 1 deletion docs/reference/server/generative-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
| [FileState](./generative-ai.filestate.md) | Processing state of the <code>File</code>. |
| [FunctionCallingMode](./generative-ai.functioncallingmode.md) | |
| [Outcome](./generative-ai.outcome.md) | Possible outcomes of code execution. |
| [SchemaType](./generative-ai.schematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ |

## Interfaces

Expand Down Expand Up @@ -68,6 +67,12 @@
| [UploadFileResponse](./generative-ai.uploadfileresponse.md) | Response from calling [GoogleAIFileManager.uploadFile()](./generative-ai.googleaifilemanager.uploadfile.md) |
| [VideoMetadata](./generative-ai.videometadata.md) | Metadata populated when video has been processed. |

## Variables

| Variable | Description |
| --- | --- |
| [SchemaType](./generative-ai.schematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ |

## Type Aliases

| Type Alias | Description |
Expand All @@ -76,5 +81,6 @@
| [Part](./generative-ai.part.md) | Content part - includes text or image part types. |
| [ResponseSchema](./generative-ai.responseschema.md) | Schema passed to <code>GenerationConfig.responseSchema</code> |
| [Schema](./generative-ai.schema.md) | Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object. More fields may be added in the future as needed. |
| [SchemaType](./generative-ai.schematype.md) | |
| [Tool](./generative-ai.tool.md) | Defines a tool that model can call to access external knowledge. |

2 changes: 1 addition & 1 deletion docs/reference/server/generative-ai.numberschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface NumberSchema extends BaseSchema
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [format?](./generative-ai.numberschema.format.md) | | "float" \| "double" | _(Optional)_ Optional. The format of the number. |
| [type](./generative-ai.numberschema.type.md) | | typeof [SchemaType.NUMBER](./generative-ai.schematype.md) | |
| [type](./generative-ai.numberschema.type.md) | | typeof SchemaType.NUMBER | |

2 changes: 1 addition & 1 deletion docs/reference/server/generative-ai.objectschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export interface ObjectSchema extends BaseSchema
| --- | --- | --- | --- |
| [properties](./generative-ai.objectschema.properties.md) | | { \[k: string\]: [Schema](./generative-ai.schema.md)<!-- -->; } | Describes the properties of the JSON object. Must not be empty. |
| [required?](./generative-ai.objectschema.required.md) | | string\[\] | _(Optional)_ A list of keys declared in the properties object. Required properties will always be present in the generated object. |
| [type](./generative-ai.objectschema.type.md) | | typeof [SchemaType.OBJECT](./generative-ai.schematype.md) | |
| [type](./generative-ai.objectschema.type.md) | | typeof SchemaType.OBJECT | |

23 changes: 9 additions & 14 deletions docs/reference/server/generative-ai.schematype.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [SchemaType](./generative-ai.schematype.md)

## SchemaType enum
## SchemaType variable

Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/

**Signature:**

```typescript
export declare enum SchemaType
SchemaType: {
readonly STRING: "string";
readonly NUMBER: "number";
readonly INTEGER: "integer";
readonly BOOLEAN: "boolean";
readonly ARRAY: "array";
readonly OBJECT: "object";
}
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| ARRAY | <code>&quot;array&quot;</code> | Array type. |
| BOOLEAN | <code>&quot;boolean&quot;</code> | Boolean type. |
| INTEGER | <code>&quot;integer&quot;</code> | Integer type. |
| NUMBER | <code>&quot;number&quot;</code> | Number type. |
| OBJECT | <code>&quot;object&quot;</code> | Object type. |
| STRING | <code>&quot;string&quot;</code> | String type. |

2 changes: 1 addition & 1 deletion docs/reference/server/generative-ai.stringschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface StringSchema extends BaseSchema
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [enum?](./generative-ai.stringschema.enum.md) | | string\[\] | _(Optional)_ If present, limits the result to one of the given values. |
| [type](./generative-ai.stringschema.type.md) | | typeof [SchemaType.STRING](./generative-ai.schematype.md) | |
| [type](./generative-ai.stringschema.type.md) | | typeof SchemaType.STRING | |

19 changes: 11 additions & 8 deletions types/function-calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@ export declare interface FunctionDeclarationsTool {
* as defined by https://swagger.io/docs/specification/data-models/data-types/
* @public
*/
export enum SchemaType {
export const SchemaType = {
/** String type. */
STRING = "string",
STRING: "string",
/** Number type. */
NUMBER = "number",
NUMBER: "number",
/** Integer type. */
INTEGER = "integer",
INTEGER: "integer",
/** Boolean type. */
BOOLEAN = "boolean",
BOOLEAN: "boolean",
/** Array type. */
ARRAY = "array",
ARRAY: "array",
/** Object type. */
OBJECT = "object",
}
OBJECT: "object",
} as const;
export type SchemaType = typeof SchemaType extends Record<string, infer R>
? R
: never;

/**
* Schema is used to define the format of input/output data.
Expand Down