Skip to content

Commit 1170a77

Browse files
committed
fix: resolve TypeScript type errors in watsonx provider
1 parent 97b48d7 commit 1170a77

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/api/providers/watsonx.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@ export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHa
6969
const platform = this.options.watsonxPlatform || "ibmCloud"
7070

7171
try {
72-
const serviceOptions: Partial<WatsonxServiceOptions> = {
73-
version: "2024-05-31",
74-
serviceUrl: serviceUrl,
75-
}
72+
let finalServiceUrl: string
73+
let authenticator: IamAuthenticator | CloudPakForDataAuthenticator
7674

7775
// Choose authenticator based on platform
7876
if (platform === "cloudPak") {
77+
if (!serviceUrl) {
78+
throw new Error("Base URL is required for IBM Cloud Pak for Data")
79+
}
80+
finalServiceUrl = serviceUrl
81+
7982
const username = this.options.watsonxUsername
8083
if (!username) {
8184
throw new Error("You must provide a valid username for IBM Cloud Pak for Data.")
@@ -89,7 +92,7 @@ export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHa
8992
throw new Error("You must provide a valid API key for IBM Cloud Pak for Data.")
9093
}
9194

92-
serviceOptions.authenticator = new CloudPakForDataAuthenticator({
95+
authenticator = new CloudPakForDataAuthenticator({
9396
username: username,
9497
apikey: apiKey,
9598
url: serviceUrl,
@@ -100,7 +103,7 @@ export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHa
100103
throw new Error("You must provide a valid password for IBM Cloud Pak for Data.")
101104
}
102105

103-
serviceOptions.authenticator = new CloudPakForDataAuthenticator({
106+
authenticator = new CloudPakForDataAuthenticator({
104107
username: username,
105108
password: password,
106109
url: serviceUrl,
@@ -113,9 +116,17 @@ export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHa
113116
throw new Error("You must provide a valid IBM watsonx API key.")
114117
}
115118

116-
serviceOptions.authenticator = new IamAuthenticator({
119+
authenticator = new IamAuthenticator({
117120
apikey: apiKey,
118121
})
122+
123+
finalServiceUrl = serviceUrl || `https://${this.options.watsonxRegion || "us-south"}.ml.cloud.ibm.com`
124+
}
125+
126+
const serviceOptions: WatsonxServiceOptions = {
127+
version: "2024-05-31",
128+
serviceUrl: finalServiceUrl,
129+
authenticator: authenticator,
119130
}
120131

121132
this.service = WatsonXAI.newInstance(serviceOptions)

0 commit comments

Comments
 (0)