Hierarchy

  • BaseService
    • WatsonXAI

Constructors

Properties

version: string

The version date for the API of the form YYYY-MM-DD.

wxServiceUrl: string
wxServiceUrl: string

Methods - Deployments

  • 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.

    Parameters

    Returns Promise<WatsonXAI.Response<WatsonXAI.DeploymentResource>>

Methods - Embeddings

Methods - Foundation Model Specs

Methods - Prompt Sessions

Methods - Prompts / Prompt Templates

Methods - Text Chat

  • 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

    Response

    Stream<string | WatsonxAiMlVml_v1.ObjectStreamed<WatsonxAiMlVml_v1.TextGenResponse>> represents a source of streaming data. If request performed successfully Stream<string | WatsonxAiMlVml_v1.ObjectStreamed<WatsonxAiMlVml_v1.TextGenResponse>> returns either stream line by line. Output will stream as follow:

    • id: 1
    • event: message
    • data: {data}
    • empty line which separates the next Event Message

    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 watsonxAiMlService.generateTextStream(parameters); for await (const line of stream) { console.log(line); }.

    Parameters

    Returns Promise<Stream<string>>

    return - Promise resolving to Stream object. Stream object is AsyncIterable based class. Stream object contains an additional property holding an AbortController, read more below.

  • Parameters

    Returns Promise<Stream<WatsonXAI.ObjectStreamed<WatsonXAI.TextChatStreamResponse>>>

Methods - Text Generation

  • 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.

    Response

    Stream<string | WatsonxAiMlVml_v1.ObjectStreamed<WatsonxAiMlVml_v1.TextGenResponse>> represents a source of streaming data. If request performed successfully Stream<string | WatsonxAiMlVml_v1.ObjectStreamed<WatsonxAiMlVml_v1.TextGenResponse>> returns either stream line by line. Output will stream as follow:

    • id: 1
    • event: message
    • data: {data}
    • empty line which separates the next Event Message

    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 watsonxAiMlService.generateTextStream(parameters); for await (const line of stream) { console.log(line); }

    Parameters

    Returns Promise<Stream<string>>

    return - Promise resolving to Stream object. Stream object is AsyncIterable based class. Stream object contains an additional property holding an AbortController, read more below.

  • Parameters

    Returns Promise<Stream<WatsonXAI.ObjectStreamed<WatsonXAI.TextGenResponse>>>

Methods - Text Rerank

Methods - Tokenization

Methods - Trainings

  • 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:

    1. 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:

      1. If you used the training request field auto_update_model: true then you can skip this step as the model will have been saved at the end of the training job.
      2. Rather than creating the payload for the model you can use the generated request.json that was stored in the results_reference field, look for the path in the field entity.results_reference.location.model_request_path.
      3. The model type must be prompt_tune_1.0.
      4. The software spec name must be watsonx-textgen-fm-1.0.
    2. Create a tuned model deployment as described in the create deployment documentation.

    Parameters

    Returns Promise<WatsonXAI.Response<WatsonXAI.TrainingResource>>

Methods - constructor

  • Constructs an instance of WatsonxAiMlVml_v1 with passed in options and external configuration.

    Parameters

    • Optional options: UserOptions

      The parameters to send to the service.

    Returns WatsonXAI

Methods - Other

  • Constructs 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:

    • 'region': 'us-south'

    Parameters

    • providedUrlVariables: Map<string, string>

    Returns string

    The formatted URL with all variable placeholders replaced by values.