Skip to content

Commit 43b3b92

Browse files
committed
format+lint
1 parent 665f449 commit 43b3b92

File tree

10 files changed

+74
-66
lines changed

10 files changed

+74
-66
lines changed

packages/inference/src/errors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ abstract class InferenceClientHttpRequestError extends InferenceClientError {
3939
...httpRequest,
4040
...(httpRequest.headers
4141
? {
42-
headers: {
43-
...httpRequest.headers,
44-
...("Authorization" in httpRequest.headers ? { Authorization: `Bearer [redacted]` } : undefined),
45-
/// redact authentication in the request headers
46-
},
47-
}
42+
headers: {
43+
...httpRequest.headers,
44+
...("Authorization" in httpRequest.headers ? { Authorization: `Bearer [redacted]` } : undefined),
45+
/// redact authentication in the request headers
46+
},
47+
}
4848
: undefined),
4949
};
5050
this.httpResponse = httpResponse;

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,24 @@ export async function makeRequestOptions(
6464

6565
const inferenceProviderMapping = providerHelper.clientSideRoutingOnly
6666
? ({
67-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
68-
providerId: removeProviderPrefix(maybeModel!, provider),
69-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70-
hfModelId: maybeModel!,
71-
status: "live",
72-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
73-
task: task!,
74-
} satisfies InferenceProviderModelMapping)
75-
: await getInferenceProviderMapping(
76-
{
77-
modelId: hfModel,
67+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
68+
providerId: removeProviderPrefix(maybeModel!, provider),
69+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70+
hfModelId: maybeModel!,
71+
status: "live",
7872
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7973
task: task!,
80-
provider,
81-
accessToken: args.accessToken,
82-
},
83-
{ fetch: options?.fetch }
84-
);
74+
} satisfies InferenceProviderModelMapping)
75+
: await getInferenceProviderMapping(
76+
{
77+
modelId: hfModel,
78+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79+
task: task!,
80+
provider,
81+
accessToken: args.accessToken,
82+
},
83+
{ fetch: options?.fetch }
84+
);
8585
if (!inferenceProviderMapping) {
8686
throw new InferenceClientInputError(
8787
`We have not been able to find inference provider information for model ${hfModel}.`

packages/inference/src/providers/fal-ai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ export class FalAITextToVideoTask extends FalAITask implements TextToVideoTaskHe
165165
let status = response.status;
166166

167167
const parsedUrl = new URL(url);
168-
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/fal-ai" : ""
169-
}`;
168+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${
169+
parsedUrl.host === "router.huggingface.co" ? "/fal-ai" : ""
170+
}`;
170171

171172
// extracting the provider model id for status and result urls
172173
// from the response as it might be different from the mapped model in `url`

packages/inference/src/providers/featherless-ai.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export class FeatherlessAITextGenerationTask extends BaseTextGenerationTask {
3838
...omit(params.args, ["inputs", "parameters"]),
3939
...(params.args.parameters
4040
? {
41-
max_tokens: params.args.parameters.max_new_tokens,
42-
...omit(params.args.parameters, "max_new_tokens"),
43-
}
41+
max_tokens: params.args.parameters.max_new_tokens,
42+
...omit(params.args.parameters, "max_new_tokens"),
43+
}
4444
: undefined),
4545
prompt: params.args.inputs,
4646
};

packages/inference/src/providers/hf-inference.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ export class HFInferenceAudioClassificationTask extends HFInferenceTask implemen
224224

225225
export class HFInferenceAutomaticSpeechRecognitionTask
226226
extends HFInferenceTask
227-
implements AutomaticSpeechRecognitionTaskHelper {
227+
implements AutomaticSpeechRecognitionTaskHelper
228+
{
228229
override async getResponse(response: AutomaticSpeechRecognitionOutput): Promise<AutomaticSpeechRecognitionOutput> {
229230
return response;
230231
}
@@ -233,9 +234,9 @@ export class HFInferenceAutomaticSpeechRecognitionTask
233234
return "data" in args
234235
? args
235236
: {
236-
...omit(args, "inputs"),
237-
data: args.inputs,
238-
};
237+
...omit(args, "inputs"),
238+
data: args.inputs,
239+
};
239240
}
240241
}
241242

@@ -270,7 +271,8 @@ export class HFInferenceAudioToAudioTask extends HFInferenceTask implements Audi
270271

271272
export class HFInferenceDocumentQuestionAnsweringTask
272273
extends HFInferenceTask
273-
implements DocumentQuestionAnsweringTaskHelper {
274+
implements DocumentQuestionAnsweringTaskHelper
275+
{
274276
override async getResponse(
275277
response: DocumentQuestionAnsweringOutput
276278
): Promise<DocumentQuestionAnsweringOutput[number]> {
@@ -406,7 +408,8 @@ export class HFInferenceObjectDetectionTask extends HFInferenceTask implements O
406408

407409
export class HFInferenceZeroShotImageClassificationTask
408410
extends HFInferenceTask
409-
implements ZeroShotImageClassificationTaskHelper {
411+
implements ZeroShotImageClassificationTaskHelper
412+
{
410413
override async getResponse(response: ZeroShotImageClassificationOutput): Promise<ZeroShotImageClassificationOutput> {
411414
if (Array.isArray(response) && response.every((x) => typeof x.label === "string" && typeof x.score === "number")) {
412415
return response;
@@ -436,20 +439,20 @@ export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements
436439
if (
437440
Array.isArray(response)
438441
? response.every(
439-
(elem) =>
440-
typeof elem === "object" &&
441-
!!elem &&
442-
typeof elem.answer === "string" &&
443-
typeof elem.end === "number" &&
444-
typeof elem.score === "number" &&
445-
typeof elem.start === "number"
446-
)
442+
(elem) =>
443+
typeof elem === "object" &&
444+
!!elem &&
445+
typeof elem.answer === "string" &&
446+
typeof elem.end === "number" &&
447+
typeof elem.score === "number" &&
448+
typeof elem.start === "number"
449+
)
447450
: typeof response === "object" &&
448-
!!response &&
449-
typeof response.answer === "string" &&
450-
typeof response.end === "number" &&
451-
typeof response.score === "number" &&
452-
typeof response.start === "number"
451+
!!response &&
452+
typeof response.answer === "string" &&
453+
typeof response.end === "number" &&
454+
typeof response.score === "number" &&
455+
typeof response.start === "number"
453456
) {
454457
return Array.isArray(response) ? response[0] : response;
455458
}
@@ -606,7 +609,8 @@ export class HFInferenceTabularClassificationTask extends HFInferenceTask implem
606609

607610
export class HFInferenceVisualQuestionAnsweringTask
608611
extends HFInferenceTask
609-
implements VisualQuestionAnsweringTaskHelper {
612+
implements VisualQuestionAnsweringTaskHelper
613+
{
610614
override async getResponse(response: VisualQuestionAnsweringOutput): Promise<VisualQuestionAnsweringOutput[number]> {
611615
if (
612616
Array.isArray(response) &&

packages/inference/src/providers/hyperbolic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export class HyperbolicTextGenerationTask extends BaseTextGenerationTask {
5656
messages: [{ content: params.args.inputs, role: "user" }],
5757
...(params.args.parameters
5858
? {
59-
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
60-
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
61-
}
59+
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
60+
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
61+
}
6262
: undefined),
6363
...omit(params.args, ["inputs", "parameters"]),
6464
model: params.model,

packages/inference/src/providers/novita.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV
9292
}
9393

9494
const parsedUrl = new URL(url);
95-
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/novita" : ""
96-
}`;
95+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${
96+
parsedUrl.host === "router.huggingface.co" ? "/novita" : ""
97+
}`;
9798
const resultUrl = `${baseUrl}/v3/async/task-result?task_id=${taskId}`;
9899

99100
let status = "";

packages/inference/src/providers/ovhcloud.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export class OvhCloudTextGenerationTask extends BaseTextGenerationTask {
5050
...omit(params.args, ["inputs", "parameters"]),
5151
...(params.args.parameters
5252
? {
53-
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
54-
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
55-
}
53+
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
54+
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
55+
}
5656
: undefined),
5757
prompt: params.args.inputs,
5858
};

packages/inference/src/providers/providerHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export abstract class TaskProviderHelper {
6161
readonly provider: InferenceProvider,
6262
private baseUrl: string,
6363
readonly clientSideRoutingOnly: boolean = false
64-
) { }
64+
) {}
6565

6666
/**
6767
* Return the response in the expected format.

packages/inference/src/utils/request.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export async function innerRequest<T>(
5353
const output = await response.json();
5454
if ([400, 422, 404, 500].includes(response.status) && options?.chatCompletion) {
5555
throw new InferenceClientProviderApiError(
56-
`Provider ${args.provider} does not seem to support chat completion for model ${args.model
56+
`Provider ${args.provider} does not seem to support chat completion for model ${
57+
args.model
5758
} . Error: ${JSON.stringify(output.error)}`,
5859
{
5960
url,
@@ -134,7 +135,8 @@ export async function* innerStreamingRequest<T>(
134135
const output = await response.json();
135136
if ([400, 422, 404, 500].includes(response.status) && options?.chatCompletion) {
136137
throw new InferenceClientProviderApiError(
137-
`Provider ${args.provider} does not seem to support chat completion for model ${args.model
138+
`Provider ${args.provider} does not seem to support chat completion for model ${
139+
args.model
138140
} . Error: ${JSON.stringify(output.error)}`,
139141
{
140142
url,
@@ -199,7 +201,7 @@ export async function* innerStreamingRequest<T>(
199201
if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
200202
throw new InferenceClientProviderApiError(
201203
`Failed to perform inference: server does not support event stream content type, it returned ` +
202-
response.headers.get("content-type"),
204+
response.headers.get("content-type"),
203205
{
204206
url,
205207
method: info.method ?? "GET",
@@ -224,8 +226,8 @@ export async function* innerStreamingRequest<T>(
224226

225227
const onChunk = getLines(
226228
getMessages(
227-
() => { },
228-
() => { },
229+
() => {},
230+
() => {},
229231
onEvent
230232
)
231233
);
@@ -248,11 +250,11 @@ export async function* innerStreamingRequest<T>(
248250
typeof data.error === "string"
249251
? data.error
250252
: typeof data.error === "object" &&
251-
data.error &&
252-
"message" in data.error &&
253-
typeof data.error.message === "string"
254-
? data.error.message
255-
: JSON.stringify(data.error);
253+
data.error &&
254+
"message" in data.error &&
255+
typeof data.error.message === "string"
256+
? data.error.message
257+
: JSON.stringify(data.error);
256258
throw new InferenceClientProviderApiError(
257259
`Failed to perform inference: an occurred while streaming the response: ${errorStr}`,
258260
{

0 commit comments

Comments
 (0)