Class v1beta.PredictionServiceClient (3.7.0)

A service for online predictions and explanations. v1beta

Package

@google-ai/generativelanguage

Constructors

(constructor)(opts, gaxInstance)

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

Construct an instance of PredictionServiceClient.

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 PredictionServiceClient({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;
    };

operationsClient

operationsClient: gax.OperationsClient;

pathTemplates

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

port

static get port(): number;

The port for this API service.

predictionServiceStub

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

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

cachedContentPath(id)

cachedContentPath(id: string): string;

Return a fully-qualified cachedContent resource name string.

Parameter
Name Description
id string
Returns
Type Description
string

{string} Resource name string.

cancelOperation(request, optionsOrCallback, callback)

cancelOperation(request: protos.google.longrunning.CancelOperationRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>, callback?: Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>): Promise<protos.google.protobuf.Empty>;

Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED. Clients can use or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an value with a of 1, corresponding to Code.CANCELLED.

Parameters
Name Description
request CancelOperationRequest

The request object that will be sent.

optionsOrCallback CallOptions | Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>
callback Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>

The function which will be called with the result of the API call. {Promise} - The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Returns
Type Description
Promise<protos.google.protobuf.Empty>
Example

const client = longrunning.operationsClient();
await client.cancelOperation({name: ''});

checkPredictLongRunningProgress(name)

checkPredictLongRunningProgress(name: string): Promise<LROperation<protos.google.ai.generativelanguage.v1beta.PredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.PredictLongRunningMetadata>>;

Check the status of the long running operation returned by predictLongRunning().

Parameter
Name Description
name string

The operation name that will be passed.

Returns
Type Description
Promise<LROperation<protos.google.ai.generativelanguage.v1beta.PredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.PredictLongRunningMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. 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 name of the model for prediction.
   *  Format: `name=models/{model}`.
   */
  // const model = 'abc123'
  /**
   *  Required. The instances that are the input to the prediction call.
   */
  // const instances = [1,2,3,4]
  /**
   *  Optional. The parameters that govern the prediction call.
   */
  // const parameters = {}

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

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

  async function callPredictLongRunning() {
    // Construct request
    const request = {
      model,
      instances,
    };

    // Run request
    const [operation] = await generativelanguageClient.predictLongRunning(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callPredictLongRunning();

chunkPath(corpus, document, chunk)

chunkPath(corpus: string, document: string, chunk: string): string;

Return a fully-qualified chunk resource name string.

Parameters
Name Description
corpus string
document string
chunk string
Returns
Type Description
string

{string} Resource name string.

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.

corpusPath(corpus)

corpusPath(corpus: string): string;

Return a fully-qualified corpus resource name string.

Parameter
Name Description
corpus string
Returns
Type Description
string

{string} Resource name string.

corpusPermissionsPath(corpus, permission)

corpusPermissionsPath(corpus: string, permission: string): string;

Return a fully-qualified corpusPermissions resource name string.

Parameters
Name Description
corpus string
permission string
Returns
Type Description
string

{string} Resource name string.

deleteOperation(request, optionsOrCallback, callback)

deleteOperation(request: protos.google.longrunning.DeleteOperationRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>): Promise<protos.google.protobuf.Empty>;

Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED.

Parameters
Name Description
request DeleteOperationRequest

The request object that will be sent.

optionsOrCallback CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>
callback Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>

The function which will be called with the result of the API call. {Promise} - The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Returns
Type Description
Promise<protos.google.protobuf.Empty>
Example

const client = longrunning.operationsClient();
await client.deleteOperation({name: ''});

documentPath(corpus, document)

documentPath(corpus: string, document: string): string;

Return a fully-qualified document resource name string.

Parameters
Name Description
corpus string
document string
Returns
Type Description
string

{string} Resource name string.

filePath(file)

filePath(file: string): string;

Return a fully-qualified file resource name string.

Parameter
Name Description
file string
Returns
Type Description
string

{string} Resource name string.

getOperation(request, optionsOrCallback, callback)

getOperation(request: protos.google.longrunning.GetOperationRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>): Promise<[protos.google.longrunning.Operation]>;

Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service.

Parameters
Name Description
request GetOperationRequest

The request object that will be sent.

optionsOrCallback CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>
callback Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing . {Promise} - The promise which resolves to an array. The first element of the array is an object representing . The promise has a method named "cancel" which cancels the ongoing API call.

Returns
Type Description
Promise<[protos.google.longrunning.Operation]>
Example

const client = longrunning.operationsClient();
const name = '';
const [response] = await client.getOperation({name});
// doThingsWith(response)

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.

listOperationsAsync(request, options)

listOperationsAsync(request: protos.google.longrunning.ListOperationsRequest, options?: gax.CallOptions): AsyncIterable<protos.google.longrunning.IOperation>;

Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns UNIMPLEMENTED. Returns an iterable object.

For-await-of syntax is used with the iterable to recursively get response element on-demand.

Parameters
Name Description
request ListOperationsRequest

The request object that will be sent.

options CallOptions

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Returns
Type Description
AsyncIterable<protos.google.longrunning.IOperation>

{Object} An iterable Object that conforms to iteration protocols.

Example

const client = longrunning.operationsClient();
for await (const response of client.listOperationsAsync(request));
// doThingsWith(response)

matchChunkFromChunkName(chunkName)

matchChunkFromChunkName(chunkName: string): string | number;

Parse the chunk from Chunk resource.

Parameter
Name Description
chunkName string

A fully-qualified path representing Chunk resource.

Returns
Type Description
string | number

{string} A string representing the chunk.

matchCorpusFromChunkName(chunkName)

matchCorpusFromChunkName(chunkName: string): string | number;

Parse the corpus from Chunk resource.

Parameter
Name Description
chunkName string

A fully-qualified path representing Chunk resource.

Returns
Type Description
string | number

{string} A string representing the corpus.

matchCorpusFromCorpusName(corpusName)

matchCorpusFromCorpusName(corpusName: string): string | number;

Parse the corpus from Corpus resource.

Parameter
Name Description
corpusName string

A fully-qualified path representing Corpus resource.

Returns
Type Description
string | number

{string} A string representing the corpus.

matchCorpusFromCorpusPermissionsName(corpusPermissionsName)

matchCorpusFromCorpusPermissionsName(corpusPermissionsName: string): string | number;

Parse the corpus from CorpusPermissions resource.

Parameter
Name Description
corpusPermissionsName string

A fully-qualified path representing corpus_permissions resource.

Returns
Type Description
string | number

{string} A string representing the corpus.

matchCorpusFromDocumentName(documentName)

matchCorpusFromDocumentName(documentName: string): string | number;

Parse the corpus from Document resource.

Parameter
Name Description
documentName string

A fully-qualified path representing Document resource.

Returns
Type Description
string | number

{string} A string representing the corpus.

matchDocumentFromChunkName(chunkName)

matchDocumentFromChunkName(chunkName: string): string | number;

Parse the document from Chunk resource.

Parameter
Name Description
chunkName string

A fully-qualified path representing Chunk resource.

Returns
Type Description
string | number

{string} A string representing the document.

matchDocumentFromDocumentName(documentName)

matchDocumentFromDocumentName(documentName: string): string | number;

Parse the document from Document resource.

Parameter
Name Description
documentName string

A fully-qualified path representing Document resource.

Returns
Type Description
string | number

{string} A string representing the document.

matchFileFromFileName(fileName)

matchFileFromFileName(fileName: string): string | number;

Parse the file from File resource.

Parameter
Name Description
fileName string

A fully-qualified path representing File resource.

Returns
Type Description
string | number

{string} A string representing the file.

matchIdFromCachedContentName(cachedContentName)

matchIdFromCachedContentName(cachedContentName: string): string | number;

Parse the id from CachedContent resource.

Parameter
Name Description
cachedContentName string

A fully-qualified path representing CachedContent resource.

Returns
Type Description
string | number

{string} A string representing the id.

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.

matchPermissionFromCorpusPermissionsName(corpusPermissionsName)

matchPermissionFromCorpusPermissionsName(corpusPermissionsName: string): string | number;

Parse the permission from CorpusPermissions resource.

Parameter
Name Description
corpusPermissionsName string

A fully-qualified path representing corpus_permissions resource.

Returns
Type Description
string | number

{string} A string representing the permission.

matchPermissionFromTunedModelPermissionsName(tunedModelPermissionsName)

matchPermissionFromTunedModelPermissionsName(tunedModelPermissionsName: string): string | number;

Parse the permission from TunedModelPermissions resource.

Parameter
Name Description
tunedModelPermissionsName string

A fully-qualified path representing tuned_model_permissions resource.

Returns
Type Description
string | number

{string} A string representing the permission.

matchTunedModelFromTunedModelName(tunedModelName)

matchTunedModelFromTunedModelName(tunedModelName: string): string | number;

Parse the tuned_model from TunedModel resource.

Parameter
Name Description
tunedModelName string

A fully-qualified path representing TunedModel resource.

Returns
Type Description
string | number

{string} A string representing the tuned_model.

matchTunedModelFromTunedModelPermissionsName(tunedModelPermissionsName)

matchTunedModelFromTunedModelPermissionsName(tunedModelPermissionsName: string): string | number;

Parse the tuned_model from TunedModelPermissions resource.

Parameter
Name Description
tunedModelPermissionsName string

A fully-qualified path representing tuned_model_permissions resource.

Returns
Type Description
string | number

{string} A string representing the tuned_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.

predict(request, options)

predict(request?: protos.google.ai.generativelanguage.v1beta.IPredictRequest, options?: CallOptions): Promise<[
        protos.google.ai.generativelanguage.v1beta.IPredictResponse,
        protos.google.ai.generativelanguage.v1beta.IPredictRequest | undefined,
        {} | undefined
    ]>;

Performs a prediction request.

Parameters
Name Description
request IPredictRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.ai.generativelanguage.v1beta.IPredictResponse, protos.google.ai.generativelanguage.v1beta.IPredictRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing PredictResponse. 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 name of the model for prediction.
   *  Format: `name=models/{model}`.
   */
  // const model = 'abc123'
  /**
   *  Required. The instances that are the input to the prediction call.
   */
  // const instances = [1,2,3,4]
  /**
   *  Optional. The parameters that govern the prediction call.
   */
  // const parameters = {}

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

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

  async function callPredict() {
    // Construct request
    const request = {
      model,
      instances,
    };

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

  callPredict();

predict(request, options, callback)

predict(request: protos.google.ai.generativelanguage.v1beta.IPredictRequest, options: CallOptions, callback: Callback<protos.google.ai.generativelanguage.v1beta.IPredictResponse, protos.google.ai.generativelanguage.v1beta.IPredictRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IPredictRequest
options CallOptions
callback Callback<protos.google.ai.generativelanguage.v1beta.IPredictResponse, protos.google.ai.generativelanguage.v1beta.IPredictRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

predict(request, callback)

predict(request: protos.google.ai.generativelanguage.v1beta.IPredictRequest, callback: Callback<protos.google.ai.generativelanguage.v1beta.IPredictResponse, protos.google.ai.generativelanguage.v1beta.IPredictRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IPredictRequest
callback Callback<protos.google.ai.generativelanguage.v1beta.IPredictResponse, protos.google.ai.generativelanguage.v1beta.IPredictRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

predictLongRunning(request, options)

predictLongRunning(request?: protos.google.ai.generativelanguage.v1beta.IPredictLongRunningRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.ai.generativelanguage.v1beta.IPredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.IPredictLongRunningMetadata>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Same as Predict but returns an LRO.

Parameters
Name Description
request IPredictLongRunningRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ LROperation<protos.google.ai.generativelanguage.v1beta.IPredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.IPredictLongRunningMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. 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 name of the model for prediction.
   *  Format: `name=models/{model}`.
   */
  // const model = 'abc123'
  /**
   *  Required. The instances that are the input to the prediction call.
   */
  // const instances = [1,2,3,4]
  /**
   *  Optional. The parameters that govern the prediction call.
   */
  // const parameters = {}

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

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

  async function callPredictLongRunning() {
    // Construct request
    const request = {
      model,
      instances,
    };

    // Run request
    const [operation] = await generativelanguageClient.predictLongRunning(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callPredictLongRunning();

predictLongRunning(request, options, callback)

predictLongRunning(request: protos.google.ai.generativelanguage.v1beta.IPredictLongRunningRequest, options: CallOptions, callback: Callback<LROperation<protos.google.ai.generativelanguage.v1beta.IPredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.IPredictLongRunningMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IPredictLongRunningRequest
options CallOptions
callback Callback<LROperation<protos.google.ai.generativelanguage.v1beta.IPredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.IPredictLongRunningMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
Type Description
void

predictLongRunning(request, callback)

predictLongRunning(request: protos.google.ai.generativelanguage.v1beta.IPredictLongRunningRequest, callback: Callback<LROperation<protos.google.ai.generativelanguage.v1beta.IPredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.IPredictLongRunningMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IPredictLongRunningRequest
callback Callback<LROperation<protos.google.ai.generativelanguage.v1beta.IPredictLongRunningResponse, protos.google.ai.generativelanguage.v1beta.IPredictLongRunningMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
Type Description
void

tunedModelPath(tunedModel)

tunedModelPath(tunedModel: string): string;

Return a fully-qualified tunedModel resource name string.

Parameter
Name Description
tunedModel string
Returns
Type Description
string

{string} Resource name string.

tunedModelPermissionsPath(tunedModel, permission)

tunedModelPermissionsPath(tunedModel: string, permission: string): string;

Return a fully-qualified tunedModelPermissions resource name string.

Parameters
Name Description
tunedModel string
permission string
Returns
Type Description
string

{string} Resource name string.