| 1 | --- |
| 2 | title: "IBM WatsonX" |
| 3 | --- |
| 4 | |
| 5 | watsonx, developed by IBM, offers a variety of pre-trained AI foundation models that can be used for natural language processing (NLP), computer vision, and speech recognition tasks. |
| 6 | |
| 7 | ## Setup |
| 8 | |
| 9 | Accessing watsonx models can be done either through watsonx SaaS on IBM Cloud or using a dedicated watsonx.ai Software instance. |
| 10 | |
| 11 | ### watsonx.ai SaaS - IBM Cloud |
| 12 | |
| 13 | To get started with watsonx SaaS, visit the [registration page](https://dataplatform.cloud.ibm.com/registration/stepone?context=wx). If you do not have an existing IBM Cloud account, you can sign up for a free trial. |
| 14 | |
| 15 | To authenticate to watsonx.ai SaaS with Continue, you will need to create a project and [set up an API key](https://www.ibm.com/docs/en/mas-cd/continuous-delivery?topic=cli-creating-your-cloud-api-key). Then, in continue: |
| 16 | |
| 17 | - Set **apiBase** to your watsonx SaaS endpoint, e.g. `https://us-south.ml.cloud.ibm.com` for US South region. |
| 18 | - Set **projectId** to your watsonx project ID. |
| 19 | - Set **apiKey** to your watsonx API Key. |
| 20 | |
| 21 | ### watsonx.ai Software |
| 22 | |
| 23 | To authenticate to your watsonx.ai Software instance with Continue, you can use either `username/password` or `ZenApiKey` method: |
| 24 | |
| 25 | 1. _Option 1_ (Recommended): using `ZenApiKey` authentication: |
| 26 | - Set **apiBase** to your watsonx software endpoint, e.g. `https://cpd-watsonx.apps.example.com`. |
| 27 | - Set **projectId** to your watsonx project ID. |
| 28 | - Set **apiKey** to your watsonx Zen API Key. To generate it: |
| 29 | 1. Log in to the CPD web client. |
| 30 | 2. From the toolbar, click your avatar. |
| 31 | 3. Click **Profile and settings**. |
| 32 | 4. Click **API key** > **Generate new key**. |
| 33 | 5. Click **Generate**. |
| 34 | 6. Click **Copy** and save your key somewhere safe. You cannot recover this key if you lose it. |
| 35 | 7. Generate your ZenApiKey by running the following command in your preferred terminal: `echo "<username>:<apikey>" | base64`, replacing `<username>` with your CPD username and `<apikey>` with the API Key you just created. |
| 36 | 2. _Option 2_: using `username/password` authentication: |
| 37 | - Set **apiBase** to your watsonx software endpoint, e.g. `https://cpd-watsonx.apps.example.com`. |
| 38 | - Set **projectId** to your watsonx project ID. |
| 39 | - Set **API Key** to your watsonx Username and Password using `username:password` as format. |
| 40 | |
| 41 | ## Configuration |
| 42 | |
| 43 | Add the following configuration: |
| 44 | |
| 45 | <Tabs> |
| 46 | <Tab title="YAML"> |
| 47 | ```yaml title="config.yaml" |
| 48 | models: |
| 49 | - name: watsonx - Model Name |
| 50 | provider: watsonx |
| 51 | model: model ID |
| 52 | apiBase: https://us-south.ml.cloud.ibm.com |
| 53 | apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD |
| 54 | env: |
| 55 | projectId: PROJECT_ID |
| 56 | apiVersion: 2024-03-14 |
| 57 | ``` |
| 58 | </Tab> |
| 59 | <Tab title="JSON"> |
| 60 | ```json title="config.json" |
| 61 | { |
| 62 | "models": [ |
| 63 | { |
| 64 | "model": "model ID", |
| 65 | "title": "watsonx - Model Name", |
| 66 | "provider": "watsonx", |
| 67 | "apiBase": "https://us-south.ml.cloud.ibm.com", |
| 68 | "projectId": "PROJECT_ID", |
| 69 | "apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD", |
| 70 | "apiVersion": "2024-03-14" |
| 71 | } |
| 72 | ] |
| 73 | } |
| 74 | ``` |
| 75 | </Tab> |
| 76 | </Tabs> |
| 77 | |
| 78 | `apiVersion` is optional and defaults to the latest version. |
| 79 | |
| 80 | If you are using a custom deployment endpoint, set `deploymentID` to the model's deployment ID. You can find it in the watsonx.ai Prompt Lab UI by selecting the corresponding model and opening the `</>` tab on the right, which will display the endpoint's URL containing the deployment ID. |
| 81 | |
| 82 | <Tabs> |
| 83 | <Tab title="YAML"> |
| 84 | ```yaml title="config.yaml" |
| 85 | models: |
| 86 | - name: watsonx - Model Name |
| 87 | provider: watsonx |
| 88 | model: model ID |
| 89 | apiBase: watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com |
| 90 | apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD |
| 91 | env: |
| 92 | apiVersion: 2024-03-14 |
| 93 | deploymentId: DEPLOYMENT_ID |
| 94 | ``` |
| 95 | </Tab> |
| 96 | <Tab title="JSON"> |
| 97 | ```json title="config.json" |
| 98 | { |
| 99 | "models": [ |
| 100 | { |
| 101 | "model": "model ID", |
| 102 | "title": "watsonx - Model Name", |
| 103 | "provider": "watsonx", |
| 104 | "apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com", |
| 105 | "apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD", |
| 106 | "apiVersion": "2024-03-14", |
| 107 | "deploymentId": "DEPLOYMENT_ID" |
| 108 | } |
| 109 | ] |
| 110 | } |
| 111 | ``` |
| 112 | </Tab> |
| 113 | </Tabs> |
| 114 | |
| 115 | ### Configuration Options |
| 116 | |
| 117 | Make sure to specify a template name, such as `granite` or `llama3`, and to set the `contextLength` to the model's context window size. |
| 118 | You can also configure generation parameters, such as temperature, topP, topK, frequency penalty, and stop sequences: |
| 119 | |
| 120 | <Tabs> |
| 121 | <Tab title="YAML"> |
| 122 | ```yaml title="config.yaml" |
| 123 | models: |
| 124 | - name: Granite Code 20b |
| 125 | provider: watsonx |
| 126 | model: ibm/granite-20b-code-instruct |
| 127 | apiBase: watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com |
| 128 | apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD |
| 129 | template: granite |
| 130 | defaultCompletionOptions: |
| 131 | contextLength: 8000 |
| 132 | temperature: 0.1 |
| 133 | topP: 0.3 |
| 134 | topK: 20 |
| 135 | maxTokens: 2000 |
| 136 | frequencyPenalty: 1.1 |
| 137 | stop: |
| 138 | - Question: |
| 139 | - "\n\n\n" |
| 140 | env: |
| 141 | projectId: PROJECT_ID |
| 142 | apiVersion: 2024-03-14 |
| 143 | |
| 144 | ``` |
| 145 | </Tab> |
| 146 | <Tab title="JSON"> |
| 147 | ```json title="config.json" |
| 148 | { |
| 149 | "models": [ |
| 150 | { |
| 151 | "model": "ibm/granite-20b-code-instruct", |
| 152 | "title": "Granite Code 20b", |
| 153 | "provider": "watsonx", |
| 154 | "apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com", |
| 155 | "projectId": "PROJECT_ID", |
| 156 | "apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD", |
| 157 | "apiVersion": "2024-03-14", |
| 158 | "template": "granite", |
| 159 | "contextLength": 8000, |
| 160 | "completionOptions": { |
| 161 | "temperature": 0.1, |
| 162 | "topP": 0.3, |
| 163 | "topK": 20, |
| 164 | "maxTokens": 2000, |
| 165 | "frequencyPenalty": 1.1, |
| 166 | "stop": ["Question:", "\n\n\n"] |
| 167 | } |
| 168 | } |
| 169 | ] |
| 170 | } |
| 171 | ``` |
| 172 | </Tab> |
| 173 | </Tabs> |
| 174 | |
| 175 | ## Tab Auto Complete Model |
| 176 | |
| 177 | Granite models are recommended for tab auto complete. The configuration is similar to that of the chat models: |
| 178 | |
| 179 | <Tabs> |
| 180 | <Tab title="YAML"> |
| 181 | ```yaml title="config.yaml" |
| 182 | models: |
| 183 | - name: Granite Code 8b |
| 184 | provider: watsonx |
| 185 | model: ibm/granite-8b-code-instruct |
| 186 | apiBase: watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com |
| 187 | projectId: PROJECT_ID |
| 188 | apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD |
| 189 | apiVersion: 2024-03-14 |
| 190 | roles: |
| 191 | - autocomplete |
| 192 | ``` |
| 193 | </Tab> |
| 194 | <Tab title="JSON"> |
| 195 | ```json title="config.json" |
| 196 | { |
| 197 | "tabAutocompleteModel": { |
| 198 | "model": "ibm/granite-8b-code-instruct", |
| 199 | "title": "Granite Code 8b", |
| 200 | "provider": "watsonx", |
| 201 | "apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com", |
| 202 | "projectId": "PROJECT_ID", |
| 203 | "apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD", |
| 204 | "apiVersion": "2024-03-14", |
| 205 | "contextLength": 4000 |
| 206 | } |
| 207 | } |
| 208 | ``` |
| 209 | </Tab> |
| 210 | </Tabs> |
| 211 | |
| 212 | ## Embeddings Model |
| 213 | |
| 214 | To view the list of available embeddings models, visit [this page](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-models-embed.html?context=wx&pos=2#ibm-provided). |
| 215 | |
| 216 | <Tabs> |
| 217 | <Tab title="YAML"> |
| 218 | ```yaml title="config.yaml" |
| 219 | models: |
| 220 | - name: Watsonx Embedder |
| 221 | provider: watsonx |
| 222 | model: ibm/slate-30m-english-rtrvr-v2 |
| 223 | apiBase: https://us-south.ml.cloud.ibm.com |
| 224 | projectId: PROJECT_ID |
| 225 | apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD |
| 226 | apiVersion: 2024-03-14 |
| 227 | roles: |
| 228 | - embed |
| 229 | ``` |
| 230 | </Tab> |
| 231 | <Tab title="JSON"> |
| 232 | ```json title="config.json" |
| 233 | { |
| 234 | "embeddingsProvider": { |
| 235 | "provider": "watsonx", |
| 236 | "model": "ibm/slate-30m-english-rtrvr-v2", |
| 237 | "apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com", |
| 238 | "projectId": "PROJECT_ID", |
| 239 | "apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD", |
| 240 | "apiVersion": "2024-03-14" |
| 241 | } |
| 242 | } |
| 243 | ``` |
| 244 | </Tab> |
| 245 | </Tabs> |
| 246 | |
| 247 | ## Reranker |
| 248 | |
| 249 | <Tabs> |
| 250 | <Tab title="YAML"> |
| 251 | ```yaml title="config.yaml" |
| 252 | models: |
| 253 | - name: Watsonx Reranker |
| 254 | provider: watsonx |
| 255 | model: cross-encoder/ms-marco-minilm-l-12-v2 |
| 256 | apiBase: https://us-south.ml.cloud.ibm.com |
| 257 | projectId: PROJECT_ID |
| 258 | apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD |
| 259 | apiVersion: 2024-03-14 |
| 260 | ``` |
| 261 | </Tab> |
| 262 | <Tab title="JSON"> |
| 263 | ```json title="config.json" |
| 264 | { |
| 265 | "reranker": { |
| 266 | "name": "watsonx", |
| 267 | "params": { |
| 268 | "model": "cross-encoder/ms-marco-minilm-l-12-v2", |
| 269 | "apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com", |
| 270 | "projectId": "PROJECT_ID", |
| 271 | "apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD", |
| 272 | "apiVersion": "2024-03-14" |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | ``` |
| 277 | </Tab> |
| 278 | </Tabs> |