Getting started with Watsonx Assistant II

Nathalia Trazzi
13 min readJan 24, 2024

To keep going, It is important that you are familiar with Watsonx Assistant

If you are not, follow this article: https://medium.com/@nathalia.trazzi/getting-started-with-watsonx-assistant-311d74baa988

In this article, you will be taught how to use extensions in Watsonx Assistant and along the way you will learn some other things. Don’t worry, everything will be taught in the most friendly way possible so you don’t get lost along the way.

Let’s learn about integrations on Watsonx Assistant.

On Watsonx Assistant’s home page, browse to the integrations button.

If everything goes well, your page should look like the following image:

This is the Watsonx Assistant integrations page.

We can use Assistant to integrate with: Salesforce, Zendesk and many other channels.

In the Essential channels section, by clicking on Web chat, you can customize your Watsonx Assistant.

Let’s have a brief moment to see what we can do there.

Style

You can make visual changes to your Assistant, And you can change it as many times as you want.

Launcher

Edit how your Assistant looks on desktop and mobile devices when its window is minimized.

It’s ok if you don’t your assistant minimized on the screen, there are ways to change it. To learn more, visit this link: https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-web-chat-develop

Home Screen

You can enable or disable a welcome message, conversations starters which are shortcuts made up of words to take the user where they need to go.

On this page, you also have the option to see how your Assistant is looking and test it while making decisions about changes.

Live agent

The Integrations available for Watsonx Assistant are listed here, or you can connect your own.

Suggestions

You can enable or disable Watsonx Assistant suggestions to offer you direct contact with a live agent.

Security

You can enable Encryption for your sensitive data on your Assistant and only grant access to your users who are authorized to use it.

To learn more about it, check the following links: https://github.com/miucciaknows/Watson-Assistant-WebSecurityPage https://cloud.ibm.com/docs/watson-assistant/watson-assistant?topic=watson-assistant-web-chat-security

Embed

Plugging Watsonx Assistant into your website or application is very simple. In this section, by copying this code you can embed your Assistant into your application.

Resources

This Watsonx Assistant session introduces you to articles and tutorials with product features.

To exit this session, click on Close.

Let’s get back to the Integrations page.

Watsonx Assistant can offer help through phone calls. You can have your assistance by calling a number.

Watsonx Assistant supports integration with Genesys, IntelePeer, Nice CX One, and Twillio.

To use Assistant over the phone, you also need the products: Speech to Text and Text to Speech.

- Speech to Text: https://www.ibm.com/products/speech-to-text

- Text to Speech: https://www.ibm.com/products/text-to-speech

Channels

In the channels section, we have a list of the available channels where Watsonx Assistant can connect such as: SMS, Facebook messenger, Genesys Bot Connector, Slack, Microsoft teams, and WhatsApp with Twillio.

Extensions

Extensions are what allow you to add features or content to your Assistant.

- Search: You can add search for questions in documents using Watson Discovery and Watsonx Discovery

- Segment: To have a better understanding of your end users. Segment allows data from your assistant to be combined with data from other sources and tools, giving you a more detailed look at where your assistant fits in your users’ end-to-end journeys.

- Build custom extensions: When you build a custom extension you can add any application to your assistant, the possibilities are endless. All you need is an OpenAPI for your application.

Starter Kits

Starter kits are tools where you can learn how to create an integration of multiple products and applications with Watsonx Assistant. These kits help make integration faster and easier. Using them or not is optional. But they can be great allies.

Building a custom extension on Watsonx Assistant

The extension created will be as simple as possible for teaching purposes only.

Let’s create an extension to calculate sum between two numbers. It seems like a silly example and it really is, but the intention here is to learn how to create extensions in Watsonx Assistant.

To Build this custom extension, we are going to use Python Language.

Create a directory and a file main.py.

Open your favorite editor and start with the following code:

# Dependencies
from fastapi import FastAPI # Importing the FastAPI framework
import uvicorn # Importing the uvicorn server
from pydantic import BaseModel # Importing BaseModel for data validation

# Creating a FastAPI instance
app = FastAPI()

# Defining a Pydantic model for request validation
class NumbersRequest(BaseModel):
number1: float
number2: float

# Root endpoint for a GET request (test)
@app.get("/")
def read_root():
return {"Hello": "World!"}

# Root to handle POST request for sum calculation
@app.post("/sum")
def sum(numbers: NumbersRequest):
# Calculating the sum of the provided numbers
result = numbers.number1 + numbers.number2
# Retuing the sum of the provided numbers
return {"result": result}

# Running the FastAPI application using uvicorn server
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0', port=8000)

Now, create a Dockerfile file.

If you don’t know about Dockerfiles and application containment, visit this link: https://docs.docker.com/engine/reference/builder/

# base image
FROM python:3.12.0-slim

# working directory
WORKDIR /rest_api

# copying local files to WORKDIR inside container
COPY . .

RUN pip install --upgrade pip


# needed packages specified in requirements.txt.
RUN pip install -r requirements.txt

# port 8000
EXPOSE 8000

# run the application
CMD ["python", "main.py"]

The composition of my directory:

Make sure your composition is the same. If not, change the names in the Dockerfile according to the names chosen by you. This ensures that everything will work well.

Now we have an application to connect to Watsonx Assistant, follow the next steps:

Upload this repository to GitHub

Now we are going to use Code Engine from IBM.

Code Engine

what’s code engine?

According to IBM, Code Engine is a fully managed, serverless platform that runs your containerized workloads, including web apps, micro-services, event-driven functions, or batch jobs. Code Engine even builds container images for you from your source code. All these workloads can seamlessly work together because they are all hosted within the same Kubernetes infrastructure. The Code Engine experience is designed so that you can focus on writing code and not on the infrastructure that is needed to host it.

-> Code Engine’s official documentation: https://cloud.ibm.com/docs/codeengine?topic=codeengine-getting-started

  1. Navigate to IBM Cloud (https://cloud.ibm.com/)

2. Use the left side menu to navigate to Code Engine

4. Click onCreate +

5. Choose a location for your instance (According to the one closest to your location for better latency) a name, a resource group (or leave it as default) and optionally tags.

After filling in all the mandatory fields, the Create button should turn blue.

Click on it.

6. Your page should look like the image below, according to your name preferences.

Click on Applications or Create application +

Now, let’s deploy our application.

  • General: Choose the name of your application
  • Code: Choose the Source code option

Copy the HTTPS link from your github project’s page and paste into Source code field.

I leave mine available for you: https://github.com/miucciaknows/Simple-Python-App

For projects that are in private repositories, you can copy the link from the GitHub SSH tab.

> To generate a ssh key : https://github.com/settings/ssh/new

-> How to access private repositories with code Engine: https://cloud.ibm.com/docs/codeengine?topic=codeengine-code-repositories

Click on Specify build details

In the Source tab:

  • Keep the code repo URL.
  • In code repo access, if your application is public or you are using the one provided by me, leave it as None.
  • In branch name, type: main

If you leave this field blank, Code Eangine will consider the main branch as the default.

  • In context directory, type ./SUM/source/rest_api
  • Then click on Next

On the next page, keep everything as it is. We are using Docker image to deploy this application and a time out of 10 minutes seems good.

We are setting a small resource because the application is small.

In the Output tab, keep the settings or change them if you need. Change the namespace according to your project if you have one more in your IBM Cloud account.

Choose tags optionally.

Click on Done

Then, on the Recources& scaling section, increase the Ephemetal storage to 1GB, and in Autoscaling - instance scaling section range in Min number of instances to 1

Scroll down.Leave things as they are, in the Optional Setting section, click on Image star options to expand it

Now, check if your Listing port is set to 8080

Finally, click on the blue Create button on the right side of the page.

Your application may take a few moments to complete.

If an error occurs, you will see a warning on the screen and you can click on it to view and even view the logs to see what went wrong. It is important that you follow the steps in this article exactly as it is to be successful.

Although this article is teaching you how to deploy an application on IBM’s Code Engine, it is not an article entirely about that.

To see more about Code Engine, visit: https://www.ibm.com/products/code-engine, https://cloud.ibm.com/docs/codeengine?topic=codeengine-getting-started.

Click on Test Application

And then click on Application URL

Now your page should look like this following image:

In your browser you should have access to your endpoint, copy that endpoint and reserve it.

Navigate to this link and download the OpenAPI.json file: https://github.com/miucciaknows/Simple-Python-App

Open the file in the code editor, and paste your endpoint (from your code engine application) between the quotation marks.

Salve it.

Now, head back to Watsox Assistant

you can use the list of resources to find your instance: https://cloud.ibm.com/resources

On the Watsonx Assistant home page, use the left side menu to access Integrations.

Now, on the integrations page, browse the Extensions section, click on Build custom extension +

Let’s start creating our custom extension.

Click onNext

Choose a name for your extension and a description.

The choose name to this step by step is sum and the description: A basic extension to calculate sum with two user-defined numbers.

Click on Next

Now drag and drop your openapi.json file or click to locate it in your files.

Click on Next

On this page you can review information about extension and its operations. The Url must be in accordance with your Deploy endpoint in Code Engine.

Click on Finish

You are now seeing the custom extension you created.

Click onAdd +

Then, click on Add

This next page is responsible for using your credentials such as url and/or apikey to authenticate with your application. In our case, we are using a simple application, so let’s just check the endpoint of our deploy to communicate with the application

Click onNext

And then confirm your url for authentication with your application.

Click on Next

Review operations and Finally, click onFinish

Now, through the Watsonx Assistant side menu, access Actions

On the actions page, It’s fine if you don’t have any actions at the moment or if you have several.

If you have followed the first steps of this getting started, you can delete this action by clicking on the three dot icons and deleting, or simply leave it as it is.

Click onNew action +

Select the option Start from scratch

You can build an action with templates that already defined by Watsonx Assistant, this helps you integrate extensions easier and quickly, but we’re going to build ours from Scratch.

Define some examples to call this action.

Ideally, 5 examples are really good to start training Assistant, so it starts to understand even if the user writes differently but has the same intention, this is called intention detection and was explained in the first part of this article.

And then click on the first step of the action.

Type a message in the Assistant says box: Please, enter just a number

In Define Customer response section choose Free text

Create a new step inNew step +

Now, chooseSet variable values

Click on Set news values

We are creating a context variable to save the value of the number the user will type.

And then, choose+ New session values

Name: Choose a name of your session variable as first_number

Type: Select Free text

Click on Apply

Select Expression as the following image:

Fill the Expression box with input.text

This expression will guarantee that the number the user enters is stored in the first_number variable.

Click on Appy

In Assistant says box type: Please, enter the second number:

In Define customer response section choose Free Text

Now create a new step in New step +

Repeat the steps:

  1. Create another session variable

2. Name it as second_number this time

3. Click Apply

4. Choose Expression as well as for the first_number variable

5. Click Apply

6. Fill in the expression box with input.text

In Assistant says box type: “Ok” or a message of your choice.

On And then section, select Use an extension.

Choose the sum as the extension and the operation Sum.

This will give access to the sum route to perform the sum between the two values ​​that the user enters.

in Parameters section:

  • for number1, click on the list after “to” and select session variables > first_number
  • for number2, click on the list after “to” and select session variables > second_number

Click on Apply

Now create a new step, using the New step + button

On the next step, click on fx

Select (sum, step 3)

Choose the Sum Result

Your page should look like the image below:

Click on the Preview > button

And test the results of your Assistant. If everything goes well, you should get good results.

Note: You ask the Assistant to “sum two numbers please.”

When you type a very different message from the one we defined when we were creating this action and Assistant was able to take care of my request. This is thanks to Watsonx Assistant’s intent detection.

This article was an intermediate introduction to Watsonx Assistant, where you learned about different features of Watsonx Assistant, context variables, creating custom extensions and even deploying an application on IBM’s Code engine.

To learn more, follow the article: Getting started with Watsonx Assistant II( https://medium.com/@nathalia.trazzi/getting-started-with-watsonx-assistant-ii-b434486470bd)

--

--

Nathalia Trazzi

Full stack software developer | Fine art photographer | Obsessed with AI, Cloud development, Fashion, Carrot Cake, Music, Dogs, Black holes and Exoplanets.