Path: blob/master/cpd5.1/notebooks/python_sdk/deployments/ai_services/Use watsonx, and `granite-3-8b-instruct` to run as an AI service.ipynb
6405 views
Use watsonx, and ibm/granite-3-8b-instruct
to run as an AI service
Disclaimers
Use only Projects and Spaces that are available in watsonx context.
Notebook content
This notebook provides a detailed demonstration of the steps and code required to showcase support for watsonx.ai AI service.
Some familiarity with Python is helpful. This notebook uses Python 3.11.
Learning goal
The learning goal for your notebook is to leverage AI services to generate accurate and contextually relevant responses based on a question.
Table of Contents
This notebook contains the following parts:
Install dependencies
Define credentials
Authenticate the Watson Machine Learning service on IBM Cloud Pak for Data. You need to provide the admin's username
and the platform url
.
Use the admin's api_key
to authenticate WML services:
Alternatively you can use the admin's password
:
Working with spaces
First of all, you need to create a space that will be used for your work. If you do not have a space, you can use {PLATFORM_URL}/ml-runtime/spaces?context=icp4data
to create one.
Click New Deployment Space
Create an empty space
Go to space
Settings
tabCopy
space_id
and paste it below
Tip: You can also use SDK to prepare the space for your work. More information can be found here.
Action: Assign space ID below
Create APIClient
instance
Specify model
This notebook uses chat model ibm/granite-3-8b-instruct
, which has to be available on your Cloud Pak for Data environment for this notebook to run successfully.
If this model is not available on your Cloud Pack for Data environment, you can specify any other available chat model.
You can list available chat models by running the cell below.
Specify the model_id
of the model you will use for the chat.
Prepare request json payload for local invoke.
Execute the generate
function locally.
Execute the generate_stream
function locally.
Store AI service with previous created custom software specifications.
Create online deployment of AI service.
Obtain the deployment_id
of the previously created deployment.
Execute generate_stream
method.
Summary and next steps
You successfully completed this notebook!
You learned how to create and deploy AI service using ibm_watsonx_ai
SDK.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Author
Rafał Chrzanowski, Software Engineer Intern at watsonx.ai.
Copyright © 2025 IBM. This notebook and its source code are released under the terms of the MIT License.