Path: blob/master/cpd4.8/notebooks/python_sdk/deployments/foundation_models/Use watsonx, and Meta `llama-2-70b-chat` to answer question about an article.ipynb
5214 views

Use watsonx, and Meta llama-2-70b-chat to answer question about an article
Disclaimers
Use only Projects and Spaces that are available in watsonx context.
Notebook content
This notebook contains the steps and code to demonstrate support for question answering in watsonx. It introduces commands for defining prompt and model testing.
Some familiarity with Python is helpful. This notebook uses Python 3.10.
Learning goal
The goal of this notebook is to demonstrate how to use llama-2-70b-chat model to answer question about provided article.
Contents
This notebook contains the following parts:
Install dependecies
Connection to WML
Authenticate the Watson Machine Learning service on IBM Cloud Pak® for Data. You need to provide platform url, your username and api_key.
Alternatively you can use username and password to authenticate WML services.
Defining the project id
The Foundation Model requires project id that provides the context for the call. We will obtain the id from the project in which this notebook runs. Otherwise, please provide the project id.
List available models
All avaliable models are presented under ModelTypes class. For more information refer to documentation.
You need to specify model_id that will be used for inferencing:
Defining the model parameters
You might need to adjust model parameters for different models or tasks, to do so please refer to documentation.
Initialize the model
Initialize the ModelInference class with previous set params.
Model's details
Define instructions for the model with few-shot example.
Prepare question for the model.
Answer the question using Meta llama-2-70b-chat model.
Inter the model to answer the question, according to provided instruction.
Explore model output.
Summary and next steps
You successfully completed this notebook!.
You learned how to answer questions about body of text with Meta's llama-2-70b-chat on watsonx.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Daniel Ryszka, watsonx.ai & Watson Machine Learning.
Copyright © 2023-2026 IBM. This notebook and its source code are released under the terms of the MIT License.