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

Fix a type definitions for response_schema and function calling #193

Closed

Conversation

ashphy
Copy link

@ashphy ashphy commented Jul 2, 2024

Description

This PR fixes the type definitions of response schema for JSON output and function calling parameters.

Background

The current type definition cannot represent all the schemas defined in the API. For example, the following schema definition results in a type error.

const generationConfig: GenerationConfig = {
  responseMimeType: "application/json",
  responseSchema: {
    type: FunctionDeclarationSchemaType.OBJECT,
    properties: {
      list: {
        type: FunctionDeclarationSchemaType.ARRAY,
        items: {
        // error TS2353: Object literal may only specify known properties, 
        // and 'items' does not exist in type 'FunctionDeclarationSchema'
          type: FunctionDeclarationSchemaType.STRING,
        },
      },
    },
    required: ["list"],
  },
};

Problem

The type definition of Schema does not match the API.

export interface Schema {
/**
* Optional. The type of the property. {@link
* FunctionDeclarationSchemaType}.
*/
type?: FunctionDeclarationSchemaType;
/** Optional. The format of the property. */
format?: string;
/** Optional. The description of the property. */
description?: string;
/** Optional. Whether the property is nullable. */
nullable?: boolean;
/** Optional. The items of the property. {@link FunctionDeclarationSchema} */
items?: FunctionDeclarationSchema;
/** Optional. The enum of the property. */
enum?: string[];
/** Optional. Map of {@link FunctionDeclarationSchema}. */
properties?: { [k: string]: FunctionDeclarationSchema };
/** Optional. Array of required property. */
required?: string[];
/** Optional. The example of the property. */
example?: unknown;
}

items and properties should be the Schema itself.
FunctionDeclarationSchema has no items parameter.

export interface FunctionDeclarationSchema {
/** The type of the parameter. */
type: FunctionDeclarationSchemaType;
/** The format of the parameter. */
properties: { [k: string]: FunctionDeclarationSchemaProperty };
/** Optional. Description of the parameter. */
description?: string;
/** Optional. Array of required parameters. */
required?: string[];
}

Schema definitions

The type definitions refer to the following specifications:

Both parameters refer to the Schema object:

How Has This Been Tested?

Added a test case

References

@ashphy ashphy changed the title Fix a schema type for response_schema and function calling Fix a type definitions for response_schema and function calling Jul 2, 2024
@ashphy
Copy link
Author

ashphy commented Aug 14, 2024

Closed due to conflict with #222, The owners never did review this.

@ashphy ashphy closed this Aug 14, 2024
@ashphy ashphy deleted the ch-response-schema-type-fix branch August 14, 2024 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant