3.2.0 • Published 5 months ago
@google-ai/generativelanguage v3.2.0
Generative Language API: Node.js Client
Generative Language API client for Node.js
A comprehensive list of changes in each version may be found in the CHANGELOG.
- Generative Language API Node.js Client API Reference
- Generative Language API Documentation
- github.com/googleapis/google-cloud-node/packages/google-ai-generativelanguage
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
- Select or create a Cloud Platform project.
- Enable billing for your project.
- Enable the Generative Language API API.
- Set up authentication 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.
Sample | Source Code | Try it |
---|---|---|
Generative_service.batch_embed_contents | source code | |
Generative_service.count_tokens | source code | |
Generative_service.embed_content | source code | |
Generative_service.generate_content | source code | |
Generative_service.stream_generate_content | source code | |
Model_service.get_model | source code | |
Model_service.list_models | source code | |
Cache_service.create_cached_content | source code | |
Cache_service.delete_cached_content | source code | |
Cache_service.get_cached_content | source code | |
Cache_service.list_cached_contents | source code | |
Cache_service.update_cached_content | source code | |
Discuss_service.count_message_tokens | source code | |
Discuss_service.generate_message | source code | |
File_service.create_file | source code | |
File_service.delete_file | source code | |
File_service.get_file | source code | |
File_service.list_files | source code | |
Generative_service.batch_embed_contents | source code | |
Generative_service.bidi_generate_content | source code | |
Generative_service.count_tokens | source code | |
Generative_service.embed_content | source code | |
Generative_service.generate_answer | source code | |
Generative_service.generate_content | source code | |
Generative_service.stream_generate_content | source code | |
Model_service.create_tuned_model | source code | |
Model_service.delete_tuned_model | source code | |
Model_service.get_model | source code | |
Model_service.get_tuned_model | source code | |
Model_service.list_models | source code | |
Model_service.list_tuned_models | source code | |
Model_service.update_tuned_model | source code | |
Permission_service.create_permission | source code | |
Permission_service.delete_permission | source code | |
Permission_service.get_permission | source code | |
Permission_service.list_permissions | source code | |
Permission_service.transfer_ownership | source code | |
Permission_service.update_permission | source code | |
Prediction_service.predict | source code | |
Retriever_service.batch_create_chunks | source code | |
Retriever_service.batch_delete_chunks | source code | |
Retriever_service.batch_update_chunks | source code | |
Retriever_service.create_chunk | source code | |
Retriever_service.create_corpus | source code | |
Retriever_service.create_document | source code | |
Retriever_service.delete_chunk | source code | |
Retriever_service.delete_corpus | source code | |
Retriever_service.delete_document | source code | |
Retriever_service.get_chunk | source code | |
Retriever_service.get_corpus | source code | |
Retriever_service.get_document | source code | |
Retriever_service.list_chunks | source code | |
Retriever_service.list_corpora | source code | |
Retriever_service.list_documents | source code | |
Retriever_service.query_corpus | source code | |
Retriever_service.query_document | source code | |
Retriever_service.update_chunk | source code | |
Retriever_service.update_corpus | source code | |
Retriever_service.update_document | source code | |
Text_service.batch_embed_text | source code | |
Text_service.count_text_tokens | source code | |
Text_service.embed_text | source code | |
Text_service.generate_text | source code | |
Cache_service.create_cached_content | source code | |
Cache_service.delete_cached_content | source code | |
Cache_service.get_cached_content | source code | |
Cache_service.list_cached_contents | source code | |
Cache_service.update_cached_content | source code | |
Discuss_service.count_message_tokens | source code | |
Discuss_service.generate_message | source code | |
File_service.create_file | source code | |
File_service.delete_file | source code | |
File_service.download_file | source code | |
File_service.get_file | source code | |
File_service.list_files | source code | |
Generative_service.batch_embed_contents | source code | |
Generative_service.bidi_generate_content | source code | |
Generative_service.count_tokens | source code | |
Generative_service.embed_content | source code | |
Generative_service.generate_answer | source code | |
Generative_service.generate_content | source code | |
Generative_service.stream_generate_content | source code | |
Model_service.create_tuned_model | source code | |
Model_service.delete_tuned_model | source code | |
Model_service.get_model | source code | |
Model_service.get_tuned_model | source code | |
Model_service.list_models | source code | |
Model_service.list_tuned_models | source code | |
Model_service.update_tuned_model | source code | |
Permission_service.create_permission | source code | |
Permission_service.delete_permission | source code | |
Permission_service.get_permission | source code | |
Permission_service.list_permissions | source code | |
Permission_service.transfer_ownership | source code | |
Permission_service.update_permission | source code | |
Prediction_service.predict | source code | |
Prediction_service.predict_long_running | source code | |
Retriever_service.batch_create_chunks | source code | |
Retriever_service.batch_delete_chunks | source code | |
Retriever_service.batch_update_chunks | source code | |
Retriever_service.create_chunk | source code | |
Retriever_service.create_corpus | source code | |
Retriever_service.create_document | source code | |
Retriever_service.delete_chunk | source code | |
Retriever_service.delete_corpus | source code | |
Retriever_service.delete_document | source code | |
Retriever_service.get_chunk | source code | |
Retriever_service.get_corpus | source code | |
Retriever_service.get_document | source code | |
Retriever_service.list_chunks | source code | |
Retriever_service.list_corpora | source code | |
Retriever_service.list_documents | source code(https://github.com/googleapis/google-cloud-node/blob/main/pack |
2.9.0
9 months ago
2.8.0
11 months ago
3.2.0
5 months ago
3.1.0
7 months ago
2.9.1
8 months ago
3.0.0
7 months ago
2.7.0
1 year ago
2.5.0
1 year ago
2.6.0
1 year ago
2.4.0
1 year ago
2.3.0
2 years ago
2.2.0
2 years ago
2.1.1
2 years ago
2.1.0
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.1.0
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago