Class v1beta.GenerativeServiceClient (2.4.0)

API for using Large Models that generate multimodal content and have additional capabilities beyond text generation. v1beta

Package

@google-ai/generativelanguage

Constructors

(constructor)(opts, gaxInstance)

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

Construct an instance of GenerativeServiceClient.

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 GenerativeServiceClient({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;

generativeServiceStub

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

innerApiCalls

innerApiCalls: {
        [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

batchEmbedContents(request, options)

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

Generates multiple embeddings from the model given input text in a synchronous call.

Parameters
Name Description
request IBatchEmbedContentsRequest

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.IBatchEmbedContentsResponse, (protos.google.ai.generativelanguage.v1beta.IBatchEmbedContentsRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing BatchEmbedContentsResponse. 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 model's resource name. This serves as an ID for the Model to
   *  use.
   *  This name should match a model name returned by the `ListModels` method.
   *  Format: `models/{model}`
   */
  // const model = 'abc123'
  /**
   *  Required. Embed requests for the batch. The model in each of these requests
   *  must match the model specified `BatchEmbedContentsRequest.model`.
   */
  // const requests = [1,2,3,4]

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

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

  async function callBatchEmbedContents() {
    // Construct request
    const request = {
      model,
      requests,
    };

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

  callBatchEmbedContents();

batchEmbedContents(request, options, callback)

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

batchEmbedContents(request, callback)

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

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.

corpusPermissionPath(corpus, permission)

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

Return a fully-qualified corpusPermission resource name string.

Parameters
Name Description
corpus string
permission string
Returns
Type Description
string

{string} Resource name string.

countTokens(request, options)

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

Runs a model's tokenizer on input content and returns the token count.

Parameters
Name Description
request ICountTokensRequest

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.ICountTokensResponse, (protos.google.ai.generativelanguage.v1beta.ICountTokensRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing CountTokensResponse. 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 model's resource name. This serves as an ID for the Model to
   *  use.
   *  This name should match a model name returned by the `ListModels` method.
   *  Format: `models/{model}`
   */
  // const model = 'abc123'
  /**
   *  Optional. The input given to the model as a prompt.
   */
  // const contents = [1,2,3,4]
  /**
   *  Optional. The overall input given to the model. CountTokens will count
   *  prompt, function calling, etc.
   */
  // const generateContentRequest = {}

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

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

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

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

  callCountTokens();

countTokens(request, options, callback)

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

countTokens(request, callback)

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

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.

embedContent(request, options)

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

Generates an embedding from the model given an input Content.

Parameters
Name Description
request IEmbedContentRequest

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.IEmbedContentResponse, (protos.google.ai.generativelanguage.v1beta.IEmbedContentRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing EmbedContentResponse. 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 model's resource name. This serves as an ID for the Model to
   *  use.
   *  This name should match a model name returned by the `ListModels` method.
   *  Format: `models/{model}`
   */
  // const model = 'abc123'
  /**
   *  Required. The content to embed. Only the `parts.text` fields will be
   *  counted.
   */
  // const content = {}
  /**
   *  Optional. Optional task type for which the embeddings will be used. Can
   *  only be set for `models/embedding-001`.
   */
  // const taskType = {}
  /**
   *  Optional. An optional title for the text. Only applicable when TaskType is
   *  `RETRIEVAL_DOCUMENT`.
   *  Note: Specifying a `title` for `RETRIEVAL_DOCUMENT` provides better quality
   *  embeddings for retrieval.
   */
  // const title = 'abc123'
  /**
   *  Optional. Optional reduced dimension for the output embedding. If set,
   *  excessive values in the output embedding are truncated from the end.
   *  Supported by newer models since 2024, and the earlier model
   *  (`models/embedding-001`) cannot specify this value.
   */
  // const outputDimensionality = 1234

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

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

  async function callEmbedContent() {
    // Construct request
    const request = {
      model,
      content,
    };

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

  callEmbedContent();

embedContent(request, options, callback)

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

embedContent(request, callback)

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

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.

generateAnswer(request, options)

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

Generates a grounded answer from the model given an input GenerateAnswerRequest.

Parameters
Name Description
request IGenerateAnswerRequest

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.IGenerateAnswerResponse, (protos.google.ai.generativelanguage.v1beta.IGenerateAnswerRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . 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.
   */
  /**
   *  Passages provided inline with the request.
   */
  // const inlinePassages = {}
  /**
   *  Content retrieved from resources created via the Semantic Retriever
   *  API.
   */
  // const semanticRetriever = {}
  /**
   *  Required. The name of the `Model` to use for generating the grounded
   *  response.
   *  Format: `model=models/{model}`.
   */
  // const model = 'abc123'
  /**
   *  Required. The content of the current conversation with the model. For
   *  single-turn queries, this is a single question to answer. For multi-turn
   *  queries, this is a repeated field that contains conversation history and
   *  the last `Content` in the list containing the question.
   *  Note: GenerateAnswer currently only supports queries in English.
   */
  // const contents = [1,2,3,4]
  /**
   *  Required. Style in which answers should be returned.
   */
  // const answerStyle = {}
  /**
   *  Optional. A list of unique `SafetySetting` instances for blocking unsafe
   *  content.
   *  This will be enforced on the `GenerateAnswerRequest.contents` and
   *  `GenerateAnswerResponse.candidate`. There should not be more than one
   *  setting for each `SafetyCategory` type. The API will block any contents and
   *  responses that fail to meet the thresholds set by these settings. This list
   *  overrides the default settings for each `SafetyCategory` specified in the
   *  safety_settings. If there is no `SafetySetting` for a given
   *  `SafetyCategory` provided in the list, the API will use the default safety
   *  setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH,
   *  HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT,
   *  HARM_CATEGORY_HARASSMENT are supported.
   */
  // const safetySettings = [1,2,3,4]
  /**
   *  Optional. Controls the randomness of the output.
   *  Values can range from 0.0,1.0, inclusive. A value closer to 1.0 will
   *  produce responses that are more varied and creative, while a value closer
   *  to 0.0 will typically result in more straightforward responses from the
   *  model. A low temperature (~0.2) is usually recommended for
   *  Attributed-Question-Answering use cases.
   */
  // const temperature = 1234

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

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

  async function callGenerateAnswer() {
    // Construct request
    const request = {
      model,
      contents,
      answerStyle,
    };

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

  callGenerateAnswer();

generateAnswer(request, options, callback)

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

generateAnswer(request, callback)

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

generateContent(request, options)

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

Generates a response from the model given an input GenerateContentRequest.

Input capabilities differ between models, including tuned models. See the [model guide](https://ai.google.dev/models/gemini) and [tuning guide](https://ai.google.dev/docs/model_tuning_guidance) for details.

Parameters
Name Description
request IGenerateContentRequest

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.IGenerateContentResponse, (protos.google.ai.generativelanguage.v1beta.IGenerateContentRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . 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` to use for generating the completion.
   *  Format: `name=models/{model}`.
   */
  // const model = 'abc123'
  /**
   *  Optional. Developer set system instruction. Currently, text only.
   */
  // const systemInstruction = {}
  /**
   *  Required. The content of the current conversation with the model.
   *  For single-turn queries, this is a single instance. For multi-turn queries,
   *  this is a repeated field that contains conversation history + latest
   *  request.
   */
  // const contents = [1,2,3,4]
  /**
   *  Optional. A list of `Tools` the model may use to generate the next
   *  response.
   *  A `Tool` is a piece of code that enables the system to interact with
   *  external systems to perform an action, or set of actions, outside of
   *  knowledge and scope of the model. The only supported tool is currently
   *  `Function`.
   */
  // const tools = [1,2,3,4]
  /**
   *  Optional. Tool configuration for any `Tool` specified in the request.
   */
  // const toolConfig = {}
  /**
   *  Optional. A list of unique `SafetySetting` instances for blocking unsafe
   *  content.
   *  This will be enforced on the `GenerateContentRequest.contents` and
   *  `GenerateContentResponse.candidates`. There should not be more than one
   *  setting for each `SafetyCategory` type. The API will block any contents and
   *  responses that fail to meet the thresholds set by these settings. This list
   *  overrides the default settings for each `SafetyCategory` specified in the
   *  safety_settings. If there is no `SafetySetting` for a given
   *  `SafetyCategory` provided in the list, the API will use the default safety
   *  setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH,
   *  HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT,
   *  HARM_CATEGORY_HARASSMENT are supported.
   */
  // const safetySettings = [1,2,3,4]
  /**
   *  Optional. Configuration options for model generation and outputs.
   */
  // const generationConfig = {}

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

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

  async function callGenerateContent() {
    // Construct request
    const request = {
      model,
      contents,
    };

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

  callGenerateContent();

generateContent(request, options, callback)

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

generateContent(request, callback)

generateContent(request: protos.google.ai.generativelanguage.v1beta.IGenerateContentRequest, callback: Callback<protos.google.ai.generativelanguage.v1beta.IGenerateContentResponse, protos.google.ai.generativelanguage.v1beta.IGenerateContentRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IGenerateContentRequest
callback Callback<protos.google.ai.generativelanguage.v1beta.IGenerateContentResponse, protos.google.ai.generativelanguage.v1beta.IGenerateContentRequest | 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.

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.

matchCorpusFromCorpusPermissionName(corpusPermissionName)

matchCorpusFromCorpusPermissionName(corpusPermissionName: string): string | number;

Parse the corpus from CorpusPermission resource.

Parameter
Name Description
corpusPermissionName string

A fully-qualified path representing corpus_permission 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.

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.

matchPermissionFromCorpusPermissionName(corpusPermissionName)

matchPermissionFromCorpusPermissionName(corpusPermissionName: string): string | number;

Parse the permission from CorpusPermission resource.

Parameter
Name Description
corpusPermissionName string

A fully-qualified path representing corpus_permission resource.

Returns
Type Description
string | number

{string} A string representing the permission.

matchPermissionFromTunedModelPermissionName(tunedModelPermissionName)

matchPermissionFromTunedModelPermissionName(tunedModelPermissionName: string): string | number;

Parse the permission from TunedModelPermission resource.

Parameter
Name Description
tunedModelPermissionName string

A fully-qualified path representing tuned_model_permission 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.

matchTunedModelFromTunedModelPermissionName(tunedModelPermissionName)

matchTunedModelFromTunedModelPermissionName(tunedModelPermissionName: string): string | number;

Parse the tuned_model from TunedModelPermission resource.

Parameter
Name Description
tunedModelPermissionName string

A fully-qualified path representing tuned_model_permission 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.

streamGenerateContent(request, options)

streamGenerateContent(request?: protos.google.ai.generativelanguage.v1beta.IGenerateContentRequest, options?: CallOptions): gax.CancellableStream;

Generates a streamed response from the model given an input GenerateContentRequest.

Parameters
Name Description
request IGenerateContentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
gax.CancellableStream

{Stream} An object stream which emits on 'data' event. 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` to use for generating the completion.
   *  Format: `name=models/{model}`.
   */
  // const model = 'abc123'
  /**
   *  Optional. Developer set system instruction. Currently, text only.
   */
  // const systemInstruction = {}
  /**
   *  Required. The content of the current conversation with the model.
   *  For single-turn queries, this is a single instance. For multi-turn queries,
   *  this is a repeated field that contains conversation history + latest
   *  request.
   */
  // const contents = [1,2,3,4]
  /**
   *  Optional. A list of `Tools` the model may use to generate the next
   *  response.
   *  A `Tool` is a piece of code that enables the system to interact with
   *  external systems to perform an action, or set of actions, outside of
   *  knowledge and scope of the model. The only supported tool is currently
   *  `Function`.
   */
  // const tools = [1,2,3,4]
  /**
   *  Optional. Tool configuration for any `Tool` specified in the request.
   */
  // const toolConfig = {}
  /**
   *  Optional. A list of unique `SafetySetting` instances for blocking unsafe
   *  content.
   *  This will be enforced on the `GenerateContentRequest.contents` and
   *  `GenerateContentResponse.candidates`. There should not be more than one
   *  setting for each `SafetyCategory` type. The API will block any contents and
   *  responses that fail to meet the thresholds set by these settings. This list
   *  overrides the default settings for each `SafetyCategory` specified in the
   *  safety_settings. If there is no `SafetySetting` for a given
   *  `SafetyCategory` provided in the list, the API will use the default safety
   *  setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH,
   *  HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT,
   *  HARM_CATEGORY_HARASSMENT are supported.
   */
  // const safetySettings = [1,2,3,4]
  /**
   *  Optional. Configuration options for model generation and outputs.
   */
  // const generationConfig = {}

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

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

  async function callStreamGenerateContent() {
    // Construct request
    const request = {
      model,
      contents,
    };

    // Run request
    const stream = await generativelanguageClient.streamGenerateContent(request);
    stream.on('data', (response) => { console.log(response) });
    stream.on('error', (err) => { throw(err) });
    stream.on('end', () => { /* API call completed */ });
  }

  callStreamGenerateContent();

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.

tunedModelPermissionPath(tunedModel, permission)

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

Return a fully-qualified tunedModelPermission resource name string.

Parameters
Name Description
tunedModel string
permission string
Returns
Type Description
string

{string} Resource name string.