add back id/pw auth :)
This commit is contained in:
parent
f128cbe95c
commit
950a0e9969
1 changed files with 36 additions and 2 deletions
|
|
@ -41,13 +41,47 @@ class WatsonX extends BaseLLM {
|
|||
token: wxToken["access_token"],
|
||||
expiration: wxToken["expiration"],
|
||||
};
|
||||
}
|
||||
|
||||
} else {
|
||||
// watsonx Software
|
||||
if (
|
||||
!this.watsonxCreds?.includes(":")
|
||||
) {
|
||||
// Using ZenApiKey auth
|
||||
return {
|
||||
token: this.watsonxCreds ?? "",
|
||||
expiration: -1,
|
||||
};
|
||||
} else {
|
||||
// Using username/password auth
|
||||
const userPass = this.watsonxCreds?.split(":");
|
||||
const wxToken = await (
|
||||
await fetch(`${this.watsonxUrl}/icp4d-api/v1/authorize`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: userPass[0],
|
||||
password: userPass[1],
|
||||
}),
|
||||
})
|
||||
).json();
|
||||
const wxTokenExpiry = await (
|
||||
await fetch(`${this.watsonxUrl}/usermgmt/v1/user/tokenExpiry`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${wxToken["token"]}`,
|
||||
},
|
||||
})
|
||||
).json();
|
||||
return {
|
||||
token: wxToken["token"],
|
||||
expiration: wxTokenExpiry["exp"],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static providerName: ModelProvider = "watsonx";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue