@@ -31,30 +31,30 @@ export async function makeRequestOptions(
31
31
stream ?: boolean ;
32
32
} ,
33
33
options ?: Options & {
34
- /** To load default model if needed */
35
- taskHint ?: InferenceTask ;
34
+ /** In most cases (unless we pass a endpointUrl) we know the task */
35
+ task ?: InferenceTask ;
36
36
chatCompletion ?: boolean ;
37
37
}
38
38
) : Promise < { url : string ; info : RequestInit } > {
39
39
const { accessToken, endpointUrl, provider : maybeProvider , model : maybeModel , ...remainingArgs } = args ;
40
40
let otherArgs = remainingArgs ;
41
41
const provider = maybeProvider ?? "hf-inference" ;
42
42
43
- const { includeCredentials, taskHint , chatCompletion } = options ?? { } ;
43
+ const { includeCredentials, task , chatCompletion } = options ?? { } ;
44
44
45
45
if ( endpointUrl && provider !== "hf-inference" ) {
46
46
throw new Error ( `Cannot use endpointUrl with a third-party provider.` ) ;
47
47
}
48
48
if ( maybeModel && isUrl ( maybeModel ) ) {
49
49
throw new Error ( `Model URLs are no longer supported. Use endpointUrl instead.` ) ;
50
50
}
51
- if ( ! maybeModel && ! taskHint ) {
51
+ if ( ! maybeModel && ! task ) {
52
52
throw new Error ( "No model provided, and no task has been specified." ) ;
53
53
}
54
54
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
- const hfModel = maybeModel ?? ( await loadDefaultModel ( taskHint ! ) ) ;
55
+ const hfModel = maybeModel ?? ( await loadDefaultModel ( task ! ) ) ;
56
56
const model = await getProviderModelId ( { model : hfModel , provider } , args , {
57
- taskHint ,
57
+ task ,
58
58
chatCompletion,
59
59
fetch : options ?. fetch ,
60
60
} ) ;
@@ -77,7 +77,7 @@ export async function makeRequestOptions(
77
77
chatCompletion : chatCompletion ?? false ,
78
78
model,
79
79
provider : provider ?? "hf-inference" ,
80
- taskHint ,
80
+ task ,
81
81
} ) ;
82
82
83
83
const headers : Record < string , string > = { } ;
@@ -133,7 +133,7 @@ export async function makeRequestOptions(
133
133
? args . data
134
134
: JSON . stringify ( {
135
135
...otherArgs ,
136
- ...( taskHint === "text-to-image" && provider === "hyperbolic"
136
+ ...( task === "text-to-image" && provider === "hyperbolic"
137
137
? { model_name : model }
138
138
: chatCompletion || provider === "together" || provider === "nebius" || provider === "hyperbolic"
139
139
? { model }
@@ -151,7 +151,7 @@ function makeUrl(params: {
151
151
chatCompletion : boolean ;
152
152
model : string ;
153
153
provider : InferenceProvider ;
154
- taskHint : InferenceTask | undefined ;
154
+ task : InferenceTask | undefined ;
155
155
} ) : string {
156
156
if ( params . authMethod === "none" && params . provider !== "hf-inference" ) {
157
157
throw new Error ( "Authentication is required when requesting a third-party provider. Please provide accessToken" ) ;
@@ -176,10 +176,10 @@ function makeUrl(params: {
176
176
? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
177
177
: NEBIUS_API_BASE_URL ;
178
178
179
- if ( params . taskHint === "text-to-image" ) {
179
+ if ( params . task === "text-to-image" ) {
180
180
return `${ baseUrl } /v1/images/generations` ;
181
181
}
182
- if ( params . taskHint === "text-generation" ) {
182
+ if ( params . task === "text-generation" ) {
183
183
if ( params . chatCompletion ) {
184
184
return `${ baseUrl } /v1/chat/completions` ;
185
185
}
@@ -203,7 +203,7 @@ function makeUrl(params: {
203
203
? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
204
204
: SAMBANOVA_API_BASE_URL ;
205
205
/// Sambanova API matches OpenAI-like APIs: model is defined in the request body
206
- if ( params . taskHint === "text-generation" && params . chatCompletion ) {
206
+ if ( params . task === "text-generation" && params . chatCompletion ) {
207
207
return `${ baseUrl } /v1/chat/completions` ;
208
208
}
209
209
return baseUrl ;
@@ -213,10 +213,10 @@ function makeUrl(params: {
213
213
? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
214
214
: TOGETHER_API_BASE_URL ;
215
215
/// Together API matches OpenAI-like APIs: model is defined in the request body
216
- if ( params . taskHint === "text-to-image" ) {
216
+ if ( params . task === "text-to-image" ) {
217
217
return `${ baseUrl } /v1/images/generations` ;
218
218
}
219
- if ( params . taskHint === "text-generation" ) {
219
+ if ( params . task === "text-generation" ) {
220
220
if ( params . chatCompletion ) {
221
221
return `${ baseUrl } /v1/chat/completions` ;
222
222
}
@@ -229,7 +229,7 @@ function makeUrl(params: {
229
229
const baseUrl = shouldProxy
230
230
? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
231
231
: FIREWORKS_AI_API_BASE_URL ;
232
- if ( params . taskHint === "text-generation" && params . chatCompletion ) {
232
+ if ( params . task === "text-generation" && params . chatCompletion ) {
233
233
return `${ baseUrl } /v1/chat/completions` ;
234
234
}
235
235
return baseUrl ;
@@ -239,7 +239,7 @@ function makeUrl(params: {
239
239
? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
240
240
: HYPERBOLIC_API_BASE_URL ;
241
241
242
- if ( params . taskHint === "text-to-image" ) {
242
+ if ( params . task === "text-to-image" ) {
243
243
return `${ baseUrl } /v1/images/generations` ;
244
244
}
245
245
return `${ baseUrl } /v1/chat/completions` ;
@@ -248,7 +248,7 @@ function makeUrl(params: {
248
248
const baseUrl = shouldProxy
249
249
? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
250
250
: NOVITA_API_BASE_URL ;
251
- if ( params . taskHint === "text-generation" ) {
251
+ if ( params . task === "text-generation" ) {
252
252
if ( params . chatCompletion ) {
253
253
return `${ baseUrl } /chat/completions` ;
254
254
}
@@ -258,11 +258,11 @@ function makeUrl(params: {
258
258
}
259
259
default : {
260
260
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE . replaceAll ( "{{PROVIDER}}" , "hf-inference" ) ;
261
- if ( params . taskHint && [ "feature-extraction" , "sentence-similarity" ] . includes ( params . taskHint ) ) {
261
+ if ( params . task && [ "feature-extraction" , "sentence-similarity" ] . includes ( params . task ) ) {
262
262
/// when deployed on hf-inference, those two tasks are automatically compatible with one another.
263
- return `${ baseUrl } /pipeline/${ params . taskHint } /${ params . model } ` ;
263
+ return `${ baseUrl } /pipeline/${ params . task } /${ params . model } ` ;
264
264
}
265
- if ( params . taskHint === "text-generation" && params . chatCompletion ) {
265
+ if ( params . task === "text-generation" && params . chatCompletion ) {
266
266
return `${ baseUrl } /models/${ params . model } /v1/chat/completions` ;
267
267
}
268
268
return `${ baseUrl } /models/${ params . model } ` ;
0 commit comments