@@ -31,30 +31,30 @@ export async function makeRequestOptions(
3131 stream ?: boolean ;
3232 } ,
3333 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 ;
3636 chatCompletion ?: boolean ;
3737 }
3838) : Promise < { url : string ; info : RequestInit } > {
3939 const { accessToken, endpointUrl, provider : maybeProvider , model : maybeModel , ...remainingArgs } = args ;
4040 let otherArgs = remainingArgs ;
4141 const provider = maybeProvider ?? "hf-inference" ;
4242
43- const { includeCredentials, taskHint , chatCompletion } = options ?? { } ;
43+ const { includeCredentials, task , chatCompletion } = options ?? { } ;
4444
4545 if ( endpointUrl && provider !== "hf-inference" ) {
4646 throw new Error ( `Cannot use endpointUrl with a third-party provider.` ) ;
4747 }
4848 if ( maybeModel && isUrl ( maybeModel ) ) {
4949 throw new Error ( `Model URLs are no longer supported. Use endpointUrl instead.` ) ;
5050 }
51- if ( ! maybeModel && ! taskHint ) {
51+ if ( ! maybeModel && ! task ) {
5252 throw new Error ( "No model provided, and no task has been specified." ) ;
5353 }
5454 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55- const hfModel = maybeModel ?? ( await loadDefaultModel ( taskHint ! ) ) ;
55+ const hfModel = maybeModel ?? ( await loadDefaultModel ( task ! ) ) ;
5656 const model = await getProviderModelId ( { model : hfModel , provider } , args , {
57- taskHint ,
57+ task ,
5858 chatCompletion,
5959 fetch : options ?. fetch ,
6060 } ) ;
@@ -77,7 +77,7 @@ export async function makeRequestOptions(
7777 chatCompletion : chatCompletion ?? false ,
7878 model,
7979 provider : provider ?? "hf-inference" ,
80- taskHint ,
80+ task ,
8181 } ) ;
8282
8383 const headers : Record < string , string > = { } ;
@@ -133,7 +133,7 @@ export async function makeRequestOptions(
133133 ? args . data
134134 : JSON . stringify ( {
135135 ...otherArgs ,
136- ...( taskHint === "text-to-image" && provider === "hyperbolic"
136+ ...( task === "text-to-image" && provider === "hyperbolic"
137137 ? { model_name : model }
138138 : chatCompletion || provider === "together" || provider === "nebius" || provider === "hyperbolic"
139139 ? { model }
@@ -151,7 +151,7 @@ function makeUrl(params: {
151151 chatCompletion : boolean ;
152152 model : string ;
153153 provider : InferenceProvider ;
154- taskHint : InferenceTask | undefined ;
154+ task : InferenceTask | undefined ;
155155} ) : string {
156156 if ( params . authMethod === "none" && params . provider !== "hf-inference" ) {
157157 throw new Error ( "Authentication is required when requesting a third-party provider. Please provide accessToken" ) ;
@@ -176,10 +176,10 @@ function makeUrl(params: {
176176 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
177177 : NEBIUS_API_BASE_URL ;
178178
179- if ( params . taskHint === "text-to-image" ) {
179+ if ( params . task === "text-to-image" ) {
180180 return `${ baseUrl } /v1/images/generations` ;
181181 }
182- if ( params . taskHint === "text-generation" ) {
182+ if ( params . task === "text-generation" ) {
183183 if ( params . chatCompletion ) {
184184 return `${ baseUrl } /v1/chat/completions` ;
185185 }
@@ -203,7 +203,7 @@ function makeUrl(params: {
203203 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
204204 : SAMBANOVA_API_BASE_URL ;
205205 /// 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 ) {
207207 return `${ baseUrl } /v1/chat/completions` ;
208208 }
209209 return baseUrl ;
@@ -213,10 +213,10 @@ function makeUrl(params: {
213213 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
214214 : TOGETHER_API_BASE_URL ;
215215 /// 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" ) {
217217 return `${ baseUrl } /v1/images/generations` ;
218218 }
219- if ( params . taskHint === "text-generation" ) {
219+ if ( params . task === "text-generation" ) {
220220 if ( params . chatCompletion ) {
221221 return `${ baseUrl } /v1/chat/completions` ;
222222 }
@@ -229,7 +229,7 @@ function makeUrl(params: {
229229 const baseUrl = shouldProxy
230230 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
231231 : FIREWORKS_AI_API_BASE_URL ;
232- if ( params . taskHint === "text-generation" && params . chatCompletion ) {
232+ if ( params . task === "text-generation" && params . chatCompletion ) {
233233 return `${ baseUrl } /v1/chat/completions` ;
234234 }
235235 return baseUrl ;
@@ -239,7 +239,7 @@ function makeUrl(params: {
239239 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
240240 : HYPERBOLIC_API_BASE_URL ;
241241
242- if ( params . taskHint === "text-to-image" ) {
242+ if ( params . task === "text-to-image" ) {
243243 return `${ baseUrl } /v1/images/generations` ;
244244 }
245245 return `${ baseUrl } /v1/chat/completions` ;
@@ -248,7 +248,7 @@ function makeUrl(params: {
248248 const baseUrl = shouldProxy
249249 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
250250 : NOVITA_API_BASE_URL ;
251- if ( params . taskHint === "text-generation" ) {
251+ if ( params . task === "text-generation" ) {
252252 if ( params . chatCompletion ) {
253253 return `${ baseUrl } /chat/completions` ;
254254 }
@@ -258,11 +258,11 @@ function makeUrl(params: {
258258 }
259259 default : {
260260 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 ) ) {
262262 /// 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 } ` ;
264264 }
265- if ( params . taskHint === "text-generation" && params . chatCompletion ) {
265+ if ( params . task === "text-generation" && params . chatCompletion ) {
266266 return `${ baseUrl } /models/${ params . model } /v1/chat/completions` ;
267267 }
268268 return `${ baseUrl } /models/${ params . model } ` ;
0 commit comments