Skip to content

Commit 523b1e4

Browse files
committed
update docs
1 parent 9bcec29 commit 523b1e4

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

core/llm/llms/WatsonX.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class WatsonX extends BaseLLM {
138138
};
139139
}
140140

141-
protected async getOrFetchWatsonxToken() {
141+
protected async updateWatsonxToken() {
142142
var now = new Date().getTime() / 1000;
143143
if (
144144
watsonxToken === undefined ||
@@ -194,7 +194,7 @@ class WatsonX extends BaseLLM {
194194
signal: AbortSignal,
195195
options: CompletionOptions,
196196
): AsyncGenerator<ChatMessage> {
197-
await this.getOrFetchWatsonxToken();
197+
await this.updateWatsonxToken();
198198

199199
const stopSequences =
200200
options.stop?.slice(0, 6) ??
@@ -272,7 +272,7 @@ class WatsonX extends BaseLLM {
272272
}
273273

274274
protected async _embed(chunks: string[]): Promise<number[][]> {
275-
await this.getOrFetchWatsonxToken();
275+
await this.updateWatsonxToken();
276276

277277
const payload: any = {
278278
inputs: chunks,
@@ -318,7 +318,15 @@ class WatsonX extends BaseLLM {
318318
throw new Error("Query and chunks must not be empty");
319319
}
320320
try {
321-
await this.getOrFetchWatsonxToken();
321+
await this.updateWatsonxToken();
322+
323+
const headers = {
324+
"Content-Type": "application/json",
325+
Authorization: `${
326+
watsonxToken.expiration === -1 ? "ZenApiKey" : "Bearer"
327+
} ${watsonxToken.token}`,
328+
};
329+
322330
const payload: any = {
323331
inputs: chunks.map((chunk) => ({ text: chunk.content })),
324332
query: query,
@@ -331,20 +339,15 @@ class WatsonX extends BaseLLM {
331339
model_id: this.model,
332340
project_id: this.projectId,
333341
};
334-
const headers = {
335-
"Content-Type": "application/json",
336-
Authorization: `${
337-
watsonxToken.expiration === -1 ? "ZenApiKey" : "Bearer"
338-
} ${watsonxToken.token}`,
339-
};
342+
340343
const resp = await this.fetch(
341344
new URL(
342345
`${this.apiBase}/ml/v1/text/rerank?version=${this.apiVersion}`,
343346
),
344347
{
345348
method: "POST",
346-
body: JSON.stringify(payload),
347349
headers: headers,
350+
body: JSON.stringify(payload),
348351
},
349352
);
350353

docs/docs/customize/model-providers/more/watsonx.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,37 @@ To view the list of available embeddings models, visit [this page](https://datap
244244
```
245245
</TabItem>
246246
</Tabs>
247+
248+
249+
## Reranker
250+
251+
<Tabs groupId="config-example">
252+
<TabItem value="yaml" label="YAML">
253+
```yaml title="config.yaml"
254+
models:
255+
- name: Watsonx Reranker
256+
provider: watsonx
257+
model: cross-encoder/ms-marco-minilm-l-12-v2
258+
apiBase: https://us-south.ml.cloud.ibm.com
259+
projectId: PROJECT_ID
260+
apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD
261+
apiVersion: 2024-03-14
262+
```
263+
</TabItem>
264+
<TabItem value="json" label="JSON">
265+
```json title="config.json"
266+
{
267+
"reranker": {
268+
"name": "watsonx",
269+
"params": {
270+
"model": "cross-encoder/ms-marco-minilm-l-12-v2",
271+
"apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com",
272+
"projectId": "PROJECT_ID",
273+
"apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD",
274+
"apiVersion": "2024-03-14"
275+
}
276+
}
277+
}
278+
```
279+
</TabItem>
280+
</Tabs>

0 commit comments

Comments
 (0)