Constructs an instance of WatsonxBaseService with passed in options and external configuration.
Optional options: UserOptions & WatsonXAI.Certificates & WatsonXAI.TokenAuthenticationOptionsThe parameters to send to the service.
URL required for watsonx inference endpoints
The version date for the API of the form YYYY-MM-DD.
URL required for dataplatform endpoints
Static PLATFORM_Static newConstructs an instance of WatsonXAI with passed in options and external configuration.
Ensuring backwards compatibility from v1.7.1. You can now use:
const service = new WatsonXAI(options);
Optional options: UserOptions & WatsonXAI.TokenAuthenticationOptions & WatsonXAI.CertificatesThe parameters to send to the service.
Create a new watsonx.ai deployment.
Create a new deployment, currently the only supported type is online.
If this is a deployment for a prompt tune then the asset object must exist and the id must
be the id of the model that was created after the prompt training.
If this is a deployment for a prompt template then the prompt_template object should exist
and the id must be the id of the prompt template to be deployed.
The parameters to send to the service.
A promise that resolves to the response with deployment's data
Delete the deployment.
Delete the deployment with the specified identifier.
The parameters to send to the service.
A Promise that resolves to an empty response object
Infer text.
Infer the next tokens for a given deployed model with a set of parameters. If a serving_name
is used then it must match the serving_name that is returned in the inference section when
the deployment was created.
Note that there is currently a limitation in this operation when using return_options, for
input only input_text will be returned if requested, for output the input_tokens and
generated_tokens will not be returned.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<WatsonXAI.TextGenResponse>>The parameters to send to the service.
A Promise that resolves to a text generation response
Infer text event stream.
Infer the next tokens for a given deployed model with a set of parameters. This operation will
return the output tokens as a stream of events. If a serving_name is used then it must match
the serving_name that is returned in the inference when the deployment was created.
Note that there is currently a limitation in this operation when using return_options, for
input only input_text will be returned if requested, for output the input_tokens and
generated_tokens will not be returned, also the rank and top_tokens will not be
returned.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>Infer text chat.
Infer the next chat message for a given deployment. The deployment must reference a prompt
template which has input_mode set to chat. The model to the chat request will be from the
deployment base_model_id. Parameters to the chat request will be from the prompt template
model_parameters. Related guides:
Deployment, Prompt
template, Text
chat.
If a serving_name is used then it must match the serving_name that is returned in the
inference section when the deployment was created.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<WatsonXAI.TextChatResponse>>The object containing callbacks for requests and response
A Promise that resolves to a text chat response
Infer text chat event stream.
Infer the next chat message for a given deployment. This operation will return the output
tokens as a stream of events. The deployment must reference a prompt template which has
input_mode set to chat. The model to the chat request will be from the deployment
base_model_id. Parameters to the chat request will be from the prompt template
model_parameters. Related guides:
Deployment, Prompt
template, Text
chat.
If a serving_name is used then it must match the serving_name that is returned in the
inference section when the deployment was created.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>The object containing callbacks for requests and response
Return
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>Retrieve the deployment details.
Retrieve the deployment details with the specified identifier.
The parameters to send to the service.
A Promise that resolves to a deployment resource
Retrieve the deployments.
Retrieve the list of deployments for the specified space or project.
Optional params: WatsonXAI.ListDeploymentsParams = {}The parameters to send to the service.
A Promise that resolves to a collection of deployment resources
Update the deployment metadata.
Update the deployment metadata. The following parameters of deployment metadata are supported for the patch operation.
/name/description/tags/custom/online/parameters/asset - replace only/prompt_template - replace only/hardware_spec/hardware_request/base_model_id - replace only (applicable only to prompt template deployments referring to
IBM base foundation models)The PATCH operation with path specified as /online/parameters can be used to update the
serving_name.
The parameters to send to the service.
A Promise that resolves to a deployment resource
Generate embeddings.
Generate embeddings from text input.
See the documentation for a description of text embeddings.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<WatsonXAI.EmbeddingsResponse>>The object containing callbacks for requests and response
A Promise that resolves to an embeddings response
List the available foundation models.
Retrieve the list of deployed foundation models.
Optional params: WatsonXAI.ListFoundationModelSpecsParams = {}The parameters to send to the service.
List the supported tasks.
Retrieve the list of tasks that are supported by the foundation models.
Optional params: WatsonXAI.ListFoundationModelTasksParams = {}The parameters to send to the service.
A Promise that resolves to a list of foundation model tasks
Create a new prompt session.
This creates a new prompt session.
The parameters to send to the service.
A Promise that resolves to a prompt response
Add a new prompt to a prompt session.
This creates a new prompt associated with the given session.
The parameters to send to the service.
A Promise that resolves to a prompt session entry
Add a new chat item to a prompt session entry.
This adds new chat items to the given entry.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete a prompt session.
This deletes a prompt session with the given id.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete a prompt session entry.
This deletes a prompt session entry with the given id.
The parameters to send to the service.
A Promise that resolves to an empty response object
Get a prompt session.
This retrieves a prompt session with the given id.
The parameters to send to the service.
A Promise that resolves to a prompt session
Get a prompt session entry.
This retrieves a prompt session entry with the given id.
The parameters to send to the service.
A Promise that resolves to a prompt response
Get current prompt session lock status.
Retrieves the current locked state of a prompt session.
The parameters to send to the service.
A Promise that resolves to a prompt lock
Get entries for a prompt session.
List entries from a given session.
The parameters to send to the service.
A Promise that resolves to a list of prompt session entries
Update a prompt session.
This updates a prompt session with the given id.
The parameters to send to the service.
A Promise that resolves to a prompt session
Prompt session lock modifications.
Modifies the current locked state of a prompt session.
The parameters to send to the service.
A Promise that resolves to a prompt lock
Create a new prompt / prompt template.
This creates a new prompt with the provided parameters.
The parameters to send to the service.
A Promise that resolves to a prompt response
Add a new chat item to a prompt.
This adds new chat items to the given prompt.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete a prompt.
This delets a prompt / prompt template with the given id.
The parameters to send to the service.
A Promise that resolves to an empty response object
Get a prompt.
This retrieves a prompt / prompt template with the given id.
The parameters to send to the service.
A Promise that resolves to a prompt response
Get the inference input string for a given prompt.
Computes the inference input string based on state of a prompt. Optionally replaces template params.
The parameters to send to the service.
A Promise that resolves to prompt input data
Get current prompt lock status.
Retrieves the current locked state of a prompt.
The parameters to send to the service.
A Promise that resolves to a prompt lock
List all prompts.
This retrieves all prompts within the given project/space.
The parameters to send to the service.
A Promise that resolves to a list of prompts
Update a prompt.
This updates a prompt / prompt template with the given id.
The parameters to send to the service.
A Promise that resolves to a prompt response
Prompt lock modifications.
Modifies the current locked state of a prompt.
The parameters to send to the service.
A Promise that resolves to a prompt lock
Retrieve the spaces.
Retrieves the space list.
The parameters to send to the service.
A Promise that resolves to space resources
Infer text.
Infer the next tokens for a given deployed model with a set of parameters.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<WatsonXAI.TextChatResponse>>The object containing callbacks for requests and response
A Promise that resolves to a text chat response
Infer text event stream.
Infer the next tokens for a given deployed model with a set of parameters. This operation will return the output tokens as a stream of events
Stream<string | WatsonXAI.ObjectStreamed<WatsonXAI.TextGenResponse>> represents a source of streaming data. If request performed successfully Stream<string | WatsonXAI.ObjectStreamed<WatsonXAI.TextGenResponse>> returns either stream line by line. Output will stream as follow:
Or stream of objects. Output will stream as follow: { id: 2, event: 'message', data: {data} } Here is one of the possibilities to read streaming output:
Const stream = await watsonxAIServiceenerateTextStream(parameters); for await (const line of stream) { console.log(line); }.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>The object containing callbacks for requests and response
Return
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>Infer text.
Infer the next tokens for a given deployed model with a set of parameters.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<WatsonXAI.TextGenResponse>>The object containing callbacks for requests and response
A Promise that resolves to a text generation response
Infer text event stream.
Infer the next tokens for a given deployed model with a set of parameters. This operation will return the output tokens as a stream of events.
Stream<string | WatsonXAI.ObjectStreamed<WatsonXAI.TextGenResponse>> represents a source of streaming data. If request performed successfully Stream<string | WatsonXAI.ObjectStreamed<WatsonXAI.TextGenResponse>> returns either stream line by line. Output will stream as follow:
Or stream of objects. Output will stream as follow: { id: , event: 'message', data: {data} }
Here is one of the possibilities to read streaming output:
Const stream = await watsonxAIServiceenerateTextStream(parameters); for await (const line of stream) { console.log(line); }
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>The parameters to send to the service.
Return
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<Unzip>>Generate rerank.
Rerank texts based on some queries.
The parameters to send to the service.
Optional callbacks: WatsonXAI.RequestCallbacks<WatsonXAI.Response<WatsonXAI.RerankResponse>>The parameters to send to the service.
A Promise that resolves to a rerank response
Text tokenization.
The text tokenize operation allows you to check the conversion of provided input to tokens for a given model. It splits text into words or sub-words, which then are converted to ids through a look-up table (vocabulary). Tokenization allows the model to have a reasonable vocabulary size.
The parameters to send to the service.
A Promise that resolves to a tokenization response
Cancel or delete the training.
Cancel the specified training and remove it.
The parameters to send to the service.
A Promise that resolves to an empty response object
Retrieve the training.
Retrieve the training with the specified identifier.
The parameters to send to the service.
A Promise that resolves to a training resource
Retrieve the list of trainings.
Retrieve the list of trainings for the specified space or project.
Optional params: WatsonXAI.TrainingsListParams = {}The parameters to send to the service.
A Promise that resolves to a collection of training resources
Cancel the document extraction.
Cancel the specified document extraction and remove it.
The parameters to send to the service.
A Promise that resolves to an empty response object
Cancel the synthetic data generation.
Cancel the synthetic data generation and remove it.
The parameters to send to the service.
A Promise that resolves to an empty response object
Create a document extraction.
Create a document extraction.
The parameters to send to the service.
A Promise that resolves to a document extraction resource
Create a fine tuning job.
Create a fine tuning job that will fine tune an LLM.
The parameters to send to the service.
A Promise that resolves to a fine-tuning resource
Create a new model.
Create a new model with the given payload. A model represents a machine learning model asset.
If a 202 status is returned then the model will be ready when the content_import_state in
the model status (/ml/v4/models/{model_id}) is completed. If content_import_state is not
used then a 201 status is returned.
The parameters to send to the service.
A Promise that resolves to a model resource
Protected createProtected Creates and executes an HTTP request to the watsonx.ai API. Handles HTTPS agent configuration, encryption parameters, and callback hooks.
Request parameters including URL, method, headers, and body
Optional additionalParameters: AdditionalCreateRequestParamsOptional additional parameters
Promise resolving to the API response
Create a new space.
Creates a new space to scope other assets. Authorized user must have the following roles (see https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-iams):
On Public Cloud, user is required to provide Cloud Object Storage instance details in the 'storage' property. On private CPD installations, the default storage is used instead.
The parameters to send to the service.
A Promise that resolves to a space resource
Create a synthetic data generation job.
Create a synthetic data generation job.
The parameters to send to the service.
A Promise that resolves to a synthetic data generation resource
Create a taxonomy job.
Create a taxonomy job.
The parameters to send to the service.
A Promise that resolves to a taxonomy resource
Start a text classification request.
Start a request to classify text from a document or an image (using OCR).
The parameters to send to the service.
A Promise that resolves to a text classification response
Start a text extraction request.
Start a request to extract text and metadata from documents.
See the documentation for a description of text extraction.
The parameters to send to the service.
A Promise that resolves to a text extraction response
Create a new watsonx.ai training.
Create a new watsonx.ai training in a project or a space.
The details of the base model and parameters for the training must be provided in the
prompt_tuning object.
In order to deploy the tuned model you need to follow the following steps:
Create a WML model asset, in a space or a project, by providing the request.json as shown
below:
curl -X POST "https://{cpd_cluster}/ml/v4/models?version=2024-01-29" \
-H "Authorization: Bearer <replace with your token>" \
-H "content-type: application/json" \
--data '{
"name": "replace_with_a_meaningful_name",
"space_id": "replace_with_your_space_id",
"type": "prompt_tune_1.0",
"software_spec": {
"name": "watsonx-textgen-fm-1.0"
},
"metrics": [ from the training job ],
"training": {
"id": "05859469-b25b-420e-aefe-4a5cb6b595eb",
"base_model": {
"model_id": "google/flan-t5-xl"
},
"task_id": "generation",
"verbalizer": "Input: {{input}} Output:"
},
"training_data_references": [
{
"connection": {
"id": "20933468-7e8a-4706-bc90-f0a09332b263"
},
"id": "file_to_tune1.json",
"location": {
"bucket": "wxproject-donotdelete-pr-xeyivy0rx3vrbl",
"path": "file_to_tune1.json"
},
"type": "connection_asset"
}
]
}'
```
Notes:
auto_update_model: true then you can skip this step as
the model will have been saved at the end of the training job.request.json that
was stored in the results_reference field, look for the path in the field
entity.results_reference.location.model_request_path.type must be prompt_tune_1.0.watsonx-textgen-fm-1.0.Create a tuned model deployment as described in the create deployment documentation.
@category Trainings @param {Object} params - The parameters to send to the service. @param
{string} params.name - The name of the training. @param {ObjectLocation}
params.resultsReference - The training results. Normally this is specified as type=container
which means that it is stored in the space or project. @param {string} [params.spaceId] - The
space that contains the resource. Either space_id or project_id has to be given. @param
{string} [params.projectId] - The project that contains the resource. Either space_id or
project_id has to be given. @param {string} [params.description] - A description of the
training. @param {string[]} [params.tags] - A list of tags for this resource. @param
{PromptTuning} [params.promptTuning] - Properties to control the prompt tuning. @param
{DataConnectionReference[]} [params.trainingDataReferences]
@param {JsonObject} [params.custom] - User defined properties specified as key-value pairs.
@param {boolean} [params.autoUpdateModel] - If set to true then the result of the training,
if successful, will be uploaded to the repository as a model. @param {OutgoingHttpHeaders}
[params.headers] - Custom request headers @returns
{Promise<WatsonXAI.Response<WatsonXAI.TrainingResource>>} A Promise that resolves to a training
resource
@category Trainings
Cancel or delete a fine tuning job.
Delete a fine tuning job if it exists, once deleted all trace of the job is gone.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete the model.
Delete the model with the specified identifier. This will delete all revisions of this model as well. For each revision all attachments will also be deleted.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete the space.
Deletes the space with the specified identifier.
The parameters to send to the service.
A Promise that resolves to an empty response object
Cancel or delete the taxonomy job.
Cancel or delete the taxonomy job.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete the request.
Cancel the specified text classification request and delete any associated results.
The parameters to send to the service.
A Promise that resolves to an empty response object
Delete the request.
Cancel the specified text extraction request and delete any associated results.
The parameters to send to the service.
A Promise that resolves to an empty response object
Time series forecast.
Generate forecasts, or predictions for future time points, given historical time series data.
The parameters to send to the service.
A Promise that resolves to a time series forecast response
Get document extraction.
Get document extraction.
The parameters to send to the service.
A Promise that resolves to a document extraction resource
Get a fine tuning job.
Get the results of a fine tuning job, or details if the job failed.
The parameters to send to the service.
A Promise that resolves to a fine-tuning resource
Retrieve the model.
Retrieve the model with the specified identifier. If rev query parameter is provided,
rev=latest will fetch the latest revision. A call with rev={revision_number} will fetch the
given revision_number record. Either space_id or project_id has to be provided and is
mandatory.
The parameters to send to the service.
A Promise that resolves to a model resource
Retrieve the space.
Retrieves the space with the specified identifier.
Optional params: WatsonXAI.GetSpaceParamsThe parameters to send to the service.
A Promise that resolves to a space
Get synthetic data generation job.
The parameters to send to the service.
A Promise that resolves to a synthetic data generation resource
Get taxonomy job.
The parameters to send to the service.
A Promise that resolves to a taxonomy resource
Get the results of the request.
Retrieve the text classification request with the specified identifier.
Note that there is a retention period of 2 days. If this retention period is exceeded then the
request will be deleted and the results no longer available. In this case this operation will
return 404.
The parameters to send to the service.
A Promise that resolves to a text classification response
Get the results of the request.
Retrieve the text extraction request with the specified identifier.
Note that there is a retention period of 2 days. If this retention period is exceeded then the
request will be deleted and the results no longer available. In this case this operation will
return 404.
The parameters to send to the service.
A Promise that resolves to a text extraction response
Get utility agent tool.
This retrieves the details of an utility agent tool and contains information required for running the tool. Providing authentication and configuration params may return additional details.
The parameters to send to the service.
A Promise that resolves to a utility agent tool
Get document extractions.
Get document extractions.
Optional params: WatsonXAI.ListDocumentExtractionsParamsThe parameters to send to the service.
A Promise that resolves to document extraction resources
Retrieve the list of fine tuning jobs.
Retrieve the list of fine tuning jobs for the specified space or project.
Optional params: WatsonXAI.FineTuningListParamsThe parameters to send to the service.
A Promise that resolves to fine-tuning resources
Retrieve the models.
Retrieve the models for the specified space or project.
Optional params: WatsonXAI.ModelsListParamsThe parameters to send to the service.
A Promise that resolves to model resources
Get synthetic data generation jobs.
Optional params: WatsonXAI.ListSyntheticDataGenerationsParamsThe parameters to send to the service.
A Promise that resolves to synthetic data generation resources
Get taxonomy jobs.
Optional params: WatsonXAI.ListTaxonomiesParams = {}The parameters to send to the service.
A Promise that resolves to taxonomy resources
Retrieve the text classification requests.
Retrieve the list of text classification requests for the specified space or project.
This operation does not save the history, any requests that were deleted or purged will not appear in this list.
Optional params: ListTextClassificationsParams = {}The parameters to send to the service.
A Promise that resolves to text classification resources
Retrieve the text extraction requests.
Retrieve the list of text extraction requests for the specified space or project.
This operation does not save the history, any requests that were deleted or purged will not appear in this list.
Optional params: WatsonXAI.ListTextExtractionsParams = {}The parameters to send to the service.
A Promise that resolves to text extraction resources
Get utility agent tools.
This retrieves the complete list of supported utility agent tools and contains information required for running each tool.
Optional params: WatsonXAI.GetUtilityAgentToolsParams = {}The parameters to send to the service.
A Promise that resolves to utility agent tools response
Run a utility agent tool.
This runs a utility agent tool given an input and optional configuration parameters.
Some tools can choose to tailor the response based on the access token identity.
The parameters to send to the service.
A Promise that resolves to a utility agent tools run response
Run a utility agent tool.
This runs a utility agent tool given an input and optional configuration parameters.
Some tools can choose to tailor the response based on the access token identity.
The parameters to send to the service.
A Promise that resolves to a utility agent tools run response
Time series forecast.
Generate forecasts, or predictions for future time points, given historical time series data.
The parameters to send to the service.
A Promise that resolves to a time series forecast response
Transcribes an audio file using the Watson AI ML VML service.
The parameters to send to the service.
Will throw an error if required or invalid parameters are provided.
Update the model.
Update the model with the provided patch data. The following fields can be patched:
/tags/name/description/custom/software_spec (operation replace only)/model_version (operation add and replace only).The parameters to send to the service.
A Promise that resolves to a model resource
Update the space.
Partially update this space. Allowed paths are:
The parameters to send to the service.
A Promise that resolves to a space
Static constructConstructs a service URL by formatting the parameterized service URL.
The parameterized service URL is: 'https://{region}.ml.cloud.ibm.com'
The default variable values are:
Optional providedUrlVariables: null | Map<string, string>Map from variable names to desired values. If a variable is not provided in this map, the default variable value will be used instead.
The formatted URL with all variable placeholders replaced by values.
SDK entrypoint for IBM watsonx.ai product. Provides access to IBM watsonx.ai services including text generation, embeddings, deployments, and model management.
Example