Skip to content

Commit

Permalink
Fix Schema type to reference itself in its child properties (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 authored Aug 12, 2024
1 parent 27e2f97 commit 3b5daae
Show file tree
Hide file tree
Showing 41 changed files with 190 additions and 139 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-scissors-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@google/generative-ai": minor
---

Fix `Schema` type to reference itself and not a derived type in its `items` array and `properties` map.
34 changes: 19 additions & 15 deletions common/api-review/generative-ai-server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,13 @@ export interface FunctionDeclarationSchema {
[k: string]: FunctionDeclarationSchemaProperty;
};
required?: string[];
type: FunctionDeclarationSchemaType;
type: SchemaType;
}

// @public
export interface FunctionDeclarationSchemaProperty extends Schema {
}

// @public
export enum FunctionDeclarationSchemaType {
ARRAY = "ARRAY",
BOOLEAN = "BOOLEAN",
INTEGER = "INTEGER",
NUMBER = "NUMBER",
OBJECT = "OBJECT",
STRING = "STRING"
}

// @public
export interface FunctionDeclarationsTool {
functionDeclarations?: FunctionDeclaration[];
Expand Down Expand Up @@ -356,7 +346,6 @@ export class GoogleAIFileManager {
apiKey: string;
deleteFile(fileId: string): Promise<void>;
getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise<FileMetadataResponse>;
// Warning: (ae-forgotten-export) The symbol "SingleRequestOptions" needs to be exported by the entry point index.d.ts
listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise<ListFilesResponse>;
uploadFile(filePath: string, fileMetadata: FileMetadata): Promise<UploadFileResponse>;
}
Expand Down Expand Up @@ -440,13 +429,28 @@ export interface Schema {
enum?: string[];
example?: unknown;
format?: string;
items?: FunctionDeclarationSchema;
items?: Schema;
nullable?: boolean;
properties?: {
[k: string]: FunctionDeclarationSchema;
[k: string]: Schema;
};
required?: string[];
type?: FunctionDeclarationSchemaType;
type?: SchemaType;
}

// @public
export enum SchemaType {
ARRAY = "ARRAY",
BOOLEAN = "BOOLEAN",
INTEGER = "INTEGER",
NUMBER = "NUMBER",
OBJECT = "OBJECT",
STRING = "STRING"
}

// @public
export interface SingleRequestOptions extends RequestOptions {
signal?: AbortSignal;
}

// @public
Expand Down
28 changes: 14 additions & 14 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,23 +329,13 @@ export interface FunctionDeclarationSchema {
[k: string]: FunctionDeclarationSchemaProperty;
};
required?: string[];
type: FunctionDeclarationSchemaType;
type: SchemaType;
}

// @public
export interface FunctionDeclarationSchemaProperty extends Schema {
}

// @public
export enum FunctionDeclarationSchemaType {
ARRAY = "ARRAY",
BOOLEAN = "BOOLEAN",
INTEGER = "INTEGER",
NUMBER = "NUMBER",
OBJECT = "OBJECT",
STRING = "STRING"
}

// @public
export interface FunctionDeclarationsTool {
functionDeclarations?: FunctionDeclaration[];
Expand Down Expand Up @@ -656,13 +646,23 @@ export interface Schema {
enum?: string[];
example?: unknown;
format?: string;
items?: FunctionDeclarationSchema;
items?: Schema;
nullable?: boolean;
properties?: {
[k: string]: FunctionDeclarationSchema;
[k: string]: Schema;
};
required?: string[];
type?: FunctionDeclarationSchemaType;
type?: SchemaType;
}

// @public
export enum SchemaType {
ARRAY = "ARRAY",
BOOLEAN = "BOOLEAN",
INTEGER = "INTEGER",
NUMBER = "NUMBER",
OBJECT = "OBJECT",
STRING = "STRING"
}

// @public
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/main/generative-ai.chatsession.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ export declare class ChatSession
| Method | Modifiers | Description |
| --- | --- | --- |
| [getHistory()](./generative-ai.chatsession.gethistory.md) | | Gets the chat history so far. Blocked prompts are not added to history. Blocked candidates are not added to history, nor are the prompts that generated them. |
| [sendMessage(request, requestOptions)](./generative-ai.chatsession.sendmessage.md) | | <p>Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md)<!-- -->.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [sendMessageStream(request, requestOptions)](./generative-ai.chatsession.sendmessagestream.md) | | <p>Sends a chat message and receives the response as a [GenerateContentStreamResult](./generative-ai.generatecontentstreamresult.md) containing an iterable stream and a response promise.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [sendMessage(request, requestOptions)](./generative-ai.chatsession.sendmessage.md) | | <p>Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md)<!-- -->.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |
| [sendMessageStream(request, requestOptions)](./generative-ai.chatsession.sendmessagestream.md) | | <p>Sends a chat message and receives the response as a [GenerateContentStreamResult](./generative-ai.generatecontentstreamresult.md) containing an iterable stream and a response promise.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md)<!-- -->.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Sends a chat message and receives the response as a [GenerateContentStreamResult](./generative-ai.generatecontentstreamresult.md) containing an iterable stream and a response promise.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export interface FunctionDeclarationSchema
| [description?](./generative-ai.functiondeclarationschema.description.md) | | string | _(Optional)_ Optional. Description of the parameter. |
| [properties](./generative-ai.functiondeclarationschema.properties.md) | | { \[k: string\]: [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md)<!-- -->; } | The format of the parameter. |
| [required?](./generative-ai.functiondeclarationschema.required.md) | | string\[\] | _(Optional)_ Optional. Array of required parameters. |
| [type](./generative-ai.functiondeclarationschema.type.md) | | [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | The type of the parameter. |
| [type](./generative-ai.functiondeclarationschema.type.md) | | [SchemaType](./generative-ai.schematype.md) | The type of the parameter. |

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The type of the parameter.
**Signature:**

```typescript
type: FunctionDeclarationSchemaType;
type: SchemaType;
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Embeds an array of [EmbedContentRequest](./generative-ai.embedcontentrequest.md)<!-- -->s.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Counts the tokens in the provided request.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Embeds the provided content.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./generative-ai.generatecontentresponse.md)<!-- -->.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.
Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.

**Signature:**

Expand Down
10 changes: 5 additions & 5 deletions docs/reference/main/generative-ai.generativemodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export declare class GenerativeModel

| Method | Modifiers | Description |
| --- | --- | --- |
| [batchEmbedContents(batchEmbedContentRequest, requestOptions)](./generative-ai.generativemodel.batchembedcontents.md) | | <p>Embeds an array of [EmbedContentRequest](./generative-ai.embedcontentrequest.md)<!-- -->s.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [countTokens(request, requestOptions)](./generative-ai.generativemodel.counttokens.md) | | <p>Counts the tokens in the provided request.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [embedContent(request, requestOptions)](./generative-ai.generativemodel.embedcontent.md) | | <p>Embeds the provided content.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [generateContent(request, requestOptions)](./generative-ai.generativemodel.generatecontent.md) | | <p>Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./generative-ai.generatecontentresponse.md)<!-- -->.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [generateContentStream(request, requestOptions)](./generative-ai.generativemodel.generatecontentstream.md) | | <p>Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [batchEmbedContents(batchEmbedContentRequest, requestOptions)](./generative-ai.generativemodel.batchembedcontents.md) | | <p>Embeds an array of [EmbedContentRequest](./generative-ai.embedcontentrequest.md)<!-- -->s.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |
| [countTokens(request, requestOptions)](./generative-ai.generativemodel.counttokens.md) | | <p>Counts the tokens in the provided request.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |
| [embedContent(request, requestOptions)](./generative-ai.generativemodel.embedcontent.md) | | <p>Embeds the provided content.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |
| [generateContent(request, requestOptions)](./generative-ai.generativemodel.generatecontent.md) | | <p>Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./generative-ai.generatecontentresponse.md)<!-- -->.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |
| [generateContentStream(request, requestOptions)](./generative-ai.generativemodel.generatecontentstream.md) | | <p>Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md)<!-- -->.</p> |
| [startChat(startChatParams)](./generative-ai.generativemodel.startchat.md) | | Gets a new [ChatSession](./generative-ai.chatsession.md) instance which can be used for multi-turn chats. |

2 changes: 1 addition & 1 deletion docs/reference/main/generative-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
| [ExecutableCodeLanguage](./generative-ai.executablecodelanguage.md) | |
| [FinishReason](./generative-ai.finishreason.md) | Reason that a candidate finished. |
| [FunctionCallingMode](./generative-ai.functioncallingmode.md) | |
| [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ |
| [HarmBlockThreshold](./generative-ai.harmblockthreshold.md) | Threshold above which a prompt or candidate will be blocked. |
| [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
4 changes: 2 additions & 2 deletions docs/reference/main/generative-ai.schema.items.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

## Schema.items property

Optional. The items of the property. [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md)
Optional. The items of the property.

**Signature:**

```typescript
items?: FunctionDeclarationSchema;
items?: Schema;
```
Loading

0 comments on commit 3b5daae

Please sign in to comment.