Socket
Socket
Sign inDemoInstall

@google-ai/generativelanguage

Package Overview
Dependencies
90
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @google-ai/generativelanguage

Generative Language API client for Node.js


Version published
Weekly downloads
25K
increased by3.34%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Google Cloud Platform logo

Generative Language API: Node.js Client

release level npm version

Generative Language API client for Node.js

A comprehensive list of changes in each version may be found in the CHANGELOG.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Generative Language API API.
  4. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

npm install @google-ai/generativelanguage

Using the client library

/**
 * 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 name to use with the format name=models/{model}.
 */
// const model = 'abc123'
/**
 *  Required. The free-form input text given to the model as a prompt.
 *  Given a prompt, the model will generate a TextCompletion response it
 *  predicts as the completion of the input text.
 */
// const prompt = {
//  text: 'abc123'
// }
/**
 *  Controls the randomness of the output.
 *  Note: The default value varies by model, see the `Model.temperature`
 *  attribute of the `Model` returned the `getModel` function.
 *  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.
 */
// const temperature = 1234
/**
 *  Number of generated responses to return.
 *  This value must be between 1, 8, inclusive. If unset, this will default
 *  to 1.
 */
// const candidateCount = 1234
/**
 *  The maximum number of tokens to include in a candidate.
 *  If unset, this will default to 64.
 */
// const maxOutputTokens = 1234
/**
 *  The maximum cumulative probability of tokens to consider when sampling.
 *  The model uses combined Top-k and nucleus sampling.
 *  Tokens are sorted based on their assigned probabilities so that only the
 *  most liekly tokens are considered. Top-k sampling directly limits the
 *  maximum number of tokens to consider, while Nucleus sampling limits number
 *  of tokens based on the cumulative probability.
 *  Note: The default value varies by model, see the `Model.top_p`
 *  attribute of the `Model` returned the `getModel` function.
 */
// const topP = 1234
/**
 *  The maximum number of tokens to consider when sampling.
 *  The model uses combined Top-k and nucleus sampling.
 *  Top-k sampling considers the set of `top_k` most probable tokens.
 *  Defaults to 40.
 *  Note: The default value varies by model, see the `Model.top_k`
 *  attribute of the `Model` returned the `getModel` function.
 */
// const topK = 1234
/**
 *  The set of character sequences (up to 5) that will stop output generation.
 *  If specified, the API will stop at the first appearance of a stop
 *  sequence. The stop sequence will not be included as part of the response.
 */
// const stopSequences = 'abc123'

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

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

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

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

callGenerateText();

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.

SampleSource CodeTry it
Generative_service.batch_embed_contentssource codeOpen in Cloud Shell
Generative_service.count_tokenssource codeOpen in Cloud Shell
Generative_service.embed_contentsource codeOpen in Cloud Shell
Generative_service.generate_contentsource codeOpen in Cloud Shell
Generative_service.stream_generate_contentsource codeOpen in Cloud Shell
Model_service.get_modelsource codeOpen in Cloud Shell
Model_service.list_modelssource codeOpen in Cloud Shell
Discuss_service.count_message_tokenssource codeOpen in Cloud Shell
Discuss_service.generate_messagesource codeOpen in Cloud Shell
File_service.create_filesource codeOpen in Cloud Shell
File_service.delete_filesource codeOpen in Cloud Shell
File_service.get_filesource codeOpen in Cloud Shell
File_service.list_filessource codeOpen in Cloud Shell
Generative_service.batch_embed_contentssource codeOpen in Cloud Shell
Generative_service.count_tokenssource codeOpen in Cloud Shell
Generative_service.embed_contentsource codeOpen in Cloud Shell
Generative_service.generate_answersource codeOpen in Cloud Shell
Generative_service.generate_contentsource codeOpen in Cloud Shell
Generative_service.stream_generate_contentsource codeOpen in Cloud Shell
Model_service.create_tuned_modelsource codeOpen in Cloud Shell
Model_service.delete_tuned_modelsource codeOpen in Cloud Shell
Model_service.get_modelsource codeOpen in Cloud Shell
Model_service.get_tuned_modelsource codeOpen in Cloud Shell
Model_service.list_modelssource codeOpen in Cloud Shell
Model_service.list_tuned_modelssource codeOpen in Cloud Shell
Model_service.update_tuned_modelsource codeOpen in Cloud Shell
Permission_service.create_permissionsource codeOpen in Cloud Shell
Permission_service.delete_permissionsource codeOpen in Cloud Shell
Permission_service.get_permissionsource codeOpen in Cloud Shell
Permission_service.list_permissionssource codeOpen in Cloud Shell
Permission_service.transfer_ownershipsource codeOpen in Cloud Shell
Permission_service.update_permissionsource codeOpen in Cloud Shell
Retriever_service.batch_create_chunkssource codeOpen in Cloud Shell
Retriever_service.batch_delete_chunkssource codeOpen in Cloud Shell
Retriever_service.batch_update_chunkssource codeOpen in Cloud Shell
Retriever_service.create_chunksource codeOpen in Cloud Shell
Retriever_service.create_corpussource codeOpen in Cloud Shell
Retriever_service.create_documentsource codeOpen in Cloud Shell
Retriever_service.delete_chunksource codeOpen in Cloud Shell
Retriever_service.delete_corpussource codeOpen in Cloud Shell
Retriever_service.delete_documentsource codeOpen in Cloud Shell
Retriever_service.get_chunksource codeOpen in Cloud Shell
Retriever_service.get_corpussource codeOpen in Cloud Shell
Retriever_service.get_documentsource codeOpen in Cloud Shell
Retriever_service.list_chunkssource codeOpen in Cloud Shell
Retriever_service.list_corporasource codeOpen in Cloud Shell
Retriever_service.list_documentssource codeOpen in Cloud Shell
Retriever_service.query_corpussource codeOpen in Cloud Shell
Retriever_service.query_documentsource codeOpen in Cloud Shell
Retriever_service.update_chunksource codeOpen in Cloud Shell
Retriever_service.update_corpussource codeOpen in Cloud Shell
Retriever_service.update_documentsource codeOpen in Cloud Shell
Text_service.batch_embed_textsource codeOpen in Cloud Shell
Text_service.count_text_tokenssource codeOpen in Cloud Shell
Text_service.embed_textsource codeOpen in Cloud Shell
Text_service.generate_textsource codeOpen in Cloud Shell
Discuss_service.count_message_tokenssource codeOpen in Cloud Shell
Discuss_service.generate_messagesource codeOpen in Cloud Shell
Model_service.get_modelsource codeOpen in Cloud Shell
Model_service.list_modelssource codeOpen in Cloud Shell
Text_service.embed_textsource codeOpen in Cloud Shell
Text_service.generate_textsource codeOpen in Cloud Shell
Discuss_service.count_message_tokenssource codeOpen in Cloud Shell
Discuss_service.generate_messagesource codeOpen in Cloud Shell
Model_service.create_tuned_modelsource codeOpen in Cloud Shell
Model_service.delete_tuned_modelsource codeOpen in Cloud Shell
Model_service.get_modelsource codeOpen in Cloud Shell
Model_service.get_tuned_modelsource codeOpen in Cloud Shell
Model_service.list_modelssource codeOpen in Cloud Shell
Model_service.list_tuned_modelssource codeOpen in Cloud Shell
Model_service.update_tuned_modelsource codeOpen in Cloud Shell
Permission_service.create_permissionsource codeOpen in Cloud Shell
Permission_service.delete_permissionsource codeOpen in Cloud Shell
Permission_service.get_permissionsource codeOpen in Cloud Shell
Permission_service.list_permissionssource codeOpen in Cloud Shell
Permission_service.transfer_ownershipsource codeOpen in Cloud Shell
Permission_service.update_permissionsource codeOpen in Cloud Shell
Text_service.batch_embed_textsource codeOpen in Cloud Shell
Text_service.count_text_tokenssource codeOpen in Cloud Shell
Text_service.embed_textsource codeOpen in Cloud Shell
Text_service.generate_textsource codeOpen in Cloud Shell
Quickstartsource codeOpen in Cloud Shell

The Generative Language API Node.js Client API Reference documentation also contains samples.

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.

Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:

  • Legacy versions are not tested in continuous integration.
  • Some security patches and features cannot be backported.
  • Dependencies cannot be kept up-to-date.

Client libraries targeting some end-of-life versions of Node.js are available, and can be installed through npm dist-tags. The dist-tags follow the naming convention legacy-(version). For example, npm install @google-ai/generativelanguage@legacy-8 installs client libraries for versions compatible with Node.js 8.

Versioning

This library follows Semantic Versioning.

This library is considered to be in preview. This means it is still a work-in-progress and under active development. Any release is subject to backwards-incompatible changes at any time.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

Please note that this README.md, the samples/README.md, and a variety of configuration files in this repository (including .nycrc and tsconfig.json) are generated from a central template. To edit one of these files, make an edit to its templates in directory.

License

Apache Version 2.0

See LICENSE

Keywords

FAQs

Last updated on 18 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc