remove user/password auth logic
This commit is contained in:
parent
37702e17e2
commit
a0406f129f
1 changed files with 8 additions and 42 deletions
|
|
@ -41,47 +41,13 @@ 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"],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Using ZenApiKey auth
|
||||
return {
|
||||
token: this.watsonxCreds ?? "",
|
||||
expiration: -1,
|
||||
};
|
||||
}
|
||||
|
||||
static providerName: ModelProvider = "watsonx";
|
||||
|
|
@ -187,7 +153,7 @@ class WatsonX extends BaseLLM {
|
|||
this.watsonxStopToken ??
|
||||
(options.model?.includes("granite") ? "<|im_end|>" : undefined);
|
||||
var response = await this.fetch(
|
||||
`${this.watsonxUrl}/ml/v1/text/generation_stream?version=2023-05-29`,
|
||||
`${this.watsonxUrl}/ml/v1/text/generation_stream?version=${this.watsonxApiVersion}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -207,7 +173,7 @@ class WatsonX extends BaseLLM {
|
|||
repetition_penalty: 1,
|
||||
},
|
||||
model_id: options.model,
|
||||
project_id: this.watsonxProjectId,
|
||||
project_id: this.watsonxProjectId
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue