update docs

This commit is contained in:
mq200 2025-03-03 19:54:45 -08:00
parent 9bcec29383
commit 523b1e4cc6
2 changed files with 48 additions and 11 deletions

View file

@ -138,7 +138,7 @@ class WatsonX extends BaseLLM {
};
}
protected async getOrFetchWatsonxToken() {
protected async updateWatsonxToken() {
var now = new Date().getTime() / 1000;
if (
watsonxToken === undefined ||
@ -194,7 +194,7 @@ class WatsonX extends BaseLLM {
signal: AbortSignal,
options: CompletionOptions,
): AsyncGenerator<ChatMessage> {
await this.getOrFetchWatsonxToken();
await this.updateWatsonxToken();
const stopSequences =
options.stop?.slice(0, 6) ??
@ -272,7 +272,7 @@ class WatsonX extends BaseLLM {
}
protected async _embed(chunks: string[]): Promise<number[][]> {
await this.getOrFetchWatsonxToken();
await this.updateWatsonxToken();
const payload: any = {
inputs: chunks,
@ -318,7 +318,15 @@ class WatsonX extends BaseLLM {
throw new Error("Query and chunks must not be empty");
}
try {
await this.getOrFetchWatsonxToken();
await this.updateWatsonxToken();
const headers = {
"Content-Type": "application/json",
Authorization: `${
watsonxToken.expiration === -1 ? "ZenApiKey" : "Bearer"
} ${watsonxToken.token}`,
};
const payload: any = {
inputs: chunks.map((chunk) => ({ text: chunk.content })),
query: query,
@ -331,20 +339,15 @@ class WatsonX extends BaseLLM {
model_id: this.model,
project_id: this.projectId,
};
const headers = {
"Content-Type": "application/json",
Authorization: `${
watsonxToken.expiration === -1 ? "ZenApiKey" : "Bearer"
} ${watsonxToken.token}`,
};
const resp = await this.fetch(
new URL(
`${this.apiBase}/ml/v1/text/rerank?version=${this.apiVersion}`,
),
{
method: "POST",
body: JSON.stringify(payload),
headers: headers,
body: JSON.stringify(payload),
},
);

View file

@ -244,3 +244,37 @@ To view the list of available embeddings models, visit [this page](https://datap
```
</TabItem>
</Tabs>
## Reranker
<Tabs groupId="config-example">
<TabItem value="yaml" label="YAML">
```yaml title="config.yaml"
models:
- name: Watsonx Reranker
provider: watsonx
model: cross-encoder/ms-marco-minilm-l-12-v2
apiBase: https://us-south.ml.cloud.ibm.com
projectId: PROJECT_ID
apiKey: API_KEY/ZENAPI_KEY/USERNAME:PASSWORD
apiVersion: 2024-03-14
```
</TabItem>
<TabItem value="json" label="JSON">
```json title="config.json"
{
"reranker": {
"name": "watsonx",
"params": {
"model": "cross-encoder/ms-marco-minilm-l-12-v2",
"apiBase": "watsonx endpoint e.g. https://us-south.ml.cloud.ibm.com",
"projectId": "PROJECT_ID",
"apiKey": "API_KEY/ZENAPI_KEY/USERNAME:PASSWORD",
"apiVersion": "2024-03-14"
}
}
}
```
</TabItem>
</Tabs>