Class v1.ModelServiceClient (2.4.0)

Provides methods for getting metadata information about Generative Models. v1

Package

@google-ai/generativelanguage

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of ModelServiceClient.

Parameters
Name Description
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new ModelServiceClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

modelServiceStub

modelServiceStub?: Promise<{
        [name: string]: Function;
    }>;

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): never[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

universeDomain

get universeDomain(): string;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
Type Description
Promise<void>

{Promise} A promise that resolves when the client is closed.

getModel(request, options)

getModel(request?: protos.google.ai.generativelanguage.v1.IGetModelRequest, options?: CallOptions): Promise<[
        protos.google.ai.generativelanguage.v1.IModel,
        protos.google.ai.generativelanguage.v1.IGetModelRequest | undefined,
        {} | undefined
    ]>;

Gets information about a specific Model.

Parameters
Name Description
request IGetModelRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.ai.generativelanguage.v1.IModel, protos.google.ai.generativelanguage.v1.IGetModelRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing Model. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the model.
   *  This name should match a model name returned by the `ListModels` method.
   *  Format: `models/{model}`
   */
  // const name = 'abc123'

  // Imports the Generativelanguage library
  const {ModelServiceClient} = require('@google-ai/generativelanguage').v1;

  // Instantiates a client
  const generativelanguageClient = new ModelServiceClient();

  async function callGetModel() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const response = await generativelanguageClient.getModel(request);
    console.log(response);
  }

  callGetModel();

getModel(request, options, callback)

getModel(request: protos.google.ai.generativelanguage.v1.IGetModelRequest, options: CallOptions, callback: Callback<protos.google.ai.generativelanguage.v1.IModel, protos.google.ai.generativelanguage.v1.IGetModelRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IGetModelRequest
options CallOptions
callback Callback<protos.google.ai.generativelanguage.v1.IModel, protos.google.ai.generativelanguage.v1.IGetModelRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

getModel(request, callback)

getModel(request: protos.google.ai.generativelanguage.v1.IGetModelRequest, callback: Callback<protos.google.ai.generativelanguage.v1.IModel, protos.google.ai.generativelanguage.v1.IGetModelRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IGetModelRequest
callback Callback<protos.google.ai.generativelanguage.v1.IModel, protos.google.ai.generativelanguage.v1.IGetModelRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

getProjectId()

getProjectId(): Promise<string>;
Returns
Type Description
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
Name Description
callback Callback<string, undefined, undefined>
Returns
Type Description
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
Type Description
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

listModels(request, options)

listModels(request?: protos.google.ai.generativelanguage.v1.IListModelsRequest, options?: CallOptions): Promise<[
        protos.google.ai.generativelanguage.v1.IModel[],
        protos.google.ai.generativelanguage.v1.IListModelsRequest | null,
        protos.google.ai.generativelanguage.v1.IListModelsResponse
    ]>;

Lists models available through the API.

Parameters
Name Description
request IListModelsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.ai.generativelanguage.v1.IModel[], protos.google.ai.generativelanguage.v1.IListModelsRequest | null, protos.google.ai.generativelanguage.v1.IListModelsResponse ]>

{Promise} - The promise which resolves to an array. The first element of the array is Array of Model. The client library will perform auto-pagination by default: it will call the API as many times as needed and will merge results from all the pages into this array. Note that it can affect your quota. We recommend using listModelsAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

listModels(request, options, callback)

listModels(request: protos.google.ai.generativelanguage.v1.IListModelsRequest, options: CallOptions, callback: PaginationCallback<protos.google.ai.generativelanguage.v1.IListModelsRequest, protos.google.ai.generativelanguage.v1.IListModelsResponse | null | undefined, protos.google.ai.generativelanguage.v1.IModel>): void;
Parameters
Name Description
request IListModelsRequest
options CallOptions
callback PaginationCallback<protos.google.ai.generativelanguage.v1.IListModelsRequest, protos.google.ai.generativelanguage.v1.IListModelsResponse | null | undefined, protos.google.ai.generativelanguage.v1.IModel>
Returns
Type Description
void

listModels(request, callback)

listModels(request: protos.google.ai.generativelanguage.v1.IListModelsRequest, callback: PaginationCallback<protos.google.ai.generativelanguage.v1.IListModelsRequest, protos.google.ai.generativelanguage.v1.IListModelsResponse | null | undefined, protos.google.ai.generativelanguage.v1.IModel>): void;
Parameters
Name Description
request IListModelsRequest
callback PaginationCallback<protos.google.ai.generativelanguage.v1.IListModelsRequest, protos.google.ai.generativelanguage.v1.IListModelsResponse | null | undefined, protos.google.ai.generativelanguage.v1.IModel>
Returns
Type Description
void

listModelsAsync(request, options)

listModelsAsync(request?: protos.google.ai.generativelanguage.v1.IListModelsRequest, options?: CallOptions): AsyncIterable<protos.google.ai.generativelanguage.v1.IModel>;

Equivalent to listModels, but returns an iterable object.

for-await-of syntax is used with the iterable to get response elements on-demand.

Parameters
Name Description
request IListModelsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
AsyncIterable<protos.google.ai.generativelanguage.v1.IModel>

{Object} An iterable Object that allows async iteration. When you iterate the returned iterable, each element will be an object representing Model. The API will be called under the hood as needed, once per the page, so you can stop the iteration when you don't need more results. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  The maximum number of `Models` to return (per page).
   *  The service may return fewer models.
   *  If unspecified, at most 50 models will be returned per page.
   *  This method returns at most 1000 models per page, even if you pass a larger
   *  page_size.
   */
  // const pageSize = 1234
  /**
   *  A page token, received from a previous `ListModels` call.
   *  Provide the `page_token` returned by one request as an argument to the next
   *  request to retrieve the next page.
   *  When paginating, all other parameters provided to `ListModels` must match
   *  the call that provided the page token.
   */
  // const pageToken = 'abc123'

  // Imports the Generativelanguage library
  const {ModelServiceClient} = require('@google-ai/generativelanguage').v1;

  // Instantiates a client
  const generativelanguageClient = new ModelServiceClient();

  async function callListModels() {
    // Construct request
    const request = {
    };

    // Run request
    const iterable = generativelanguageClient.listModelsAsync(request);
    for await (const response of iterable) {
        console.log(response);
    }
  }

  callListModels();

listModelsStream(request, options)

listModelsStream(request?: protos.google.ai.generativelanguage.v1.IListModelsRequest, options?: CallOptions): Transform;

Equivalent to method.name.toCamelCase(), but returns a NodeJS Stream object.

Parameters
Name Description
request IListModelsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Transform

{Stream} An object stream which emits an object representing Model on 'data' event. The client library will perform auto-pagination by default: it will call the API as many times as needed. Note that it can affect your quota. We recommend using listModelsAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

matchModelFromModelName(modelName)

matchModelFromModelName(modelName: string): string | number;

Parse the model from Model resource.

Parameter
Name Description
modelName string

A fully-qualified path representing Model resource.

Returns
Type Description
string | number

{string} A string representing the model.

modelPath(model)

modelPath(model: string): string;

Return a fully-qualified model resource name string.

Parameter
Name Description
model string
Returns
Type Description
string

{string} Resource name string.