Skip to content

Commit 665f449

Browse files
committed
rename error -> errors
1 parent 9a3240d commit 665f449

20 files changed

+85
-93
lines changed

packages/inference/src/error.ts renamed to 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/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient.js";
2-
export * from "./error.js";
2+
export * from "./errors.js";
33
export * from "./types.js";
44
export * from "./tasks/index.js";
55
import * as snippets from "./snippets/index.js";

packages/inference/src/lib/getInferenceProviderMapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { HARDCODED_MODEL_INFERENCE_MAPPING } from "../providers/consts.js";
44
import { EQUIVALENT_SENTENCE_TRANSFORMERS_TASKS } from "../providers/hf-inference.js";
55
import type { InferenceProvider, InferenceProviderOrPolicy, ModelId } from "../types.js";
66
import { typedInclude } from "../utils/typedInclude.js";
7-
import { InferenceClientHubApiError, InferenceClientInputError } from "../error.js";
7+
import { InferenceClientHubApiError, InferenceClientInputError } from "../errors.js";
88

99
export const inferenceProviderMappingCache = new Map<ModelId, InferenceProviderMapping>();
1010

packages/inference/src/lib/getProviderHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import * as Replicate from "../providers/replicate.js";
4848
import * as Sambanova from "../providers/sambanova.js";
4949
import * as Together from "../providers/together.js";
5050
import type { InferenceProvider, InferenceProviderOrPolicy, InferenceTask } from "../types.js";
51-
import { InferenceClientInputError } from "../error.js";
51+
import { InferenceClientInputError } from "../errors.js";
5252

5353
export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask, TaskProviderHelper>>> = {
5454
"black-forest-labs": {

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { InferenceProviderModelMapping } from "./getInferenceProviderMappin
55
import { getInferenceProviderMapping } from "./getInferenceProviderMapping.js";
66
import type { getProviderHelper } from "./getProviderHelper.js";
77
import { isUrl } from "./isUrl.js";
8-
import { InferenceClientHubApiError, InferenceClientInputError } from "../error.js";
8+
import { InferenceClientHubApiError, InferenceClientInputError } from "../errors.js";
99

1010
/**
1111
* Lazy-loaded from huggingface.co/api/tasks when needed
@@ -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",
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,
7278
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7379
task: task!,
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-
);
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/black-forest-labs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
InferenceClientInputError,
1919
InferenceClientProviderApiError,
2020
InferenceClientProviderOutputError,
21-
} from "../error.js";
21+
} from "../errors.js";
2222
import type { BodyParams, HeaderParams, UrlParams } from "../types.js";
2323
import { delay } from "../utils/delay.js";
2424
import { omit } from "../utils/omit.js";

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
InferenceClientInputError,
3434
InferenceClientProviderApiError,
3535
InferenceClientProviderOutputError,
36-
} from "../error.js";
36+
} from "../errors.js";
3737

3838
export interface FalAiQueueOutput {
3939
request_id: string;
@@ -165,9 +165,8 @@ 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}${
169-
parsedUrl.host === "router.huggingface.co" ? "/fal-ai" : ""
170-
}`;
168+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/fal-ai" : ""
169+
}`;
171170

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import type { BodyParams } from "../types.js";
88
import { BaseConversationalTask, BaseTextGenerationTask } from "./providerHelper.js";
99
import { omit } from "../utils/omit.js";
10-
import { InferenceClientProviderOutputError } from "../error.js";
10+
import { InferenceClientProviderOutputError } from "../errors.js";
1111

1212
interface FeatherlessAITextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
1313
choices: Array<{
@@ -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: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type {
3434
ZeroShotImageClassificationOutput,
3535
} from "@huggingface/tasks";
3636
import { HF_ROUTER_URL } from "../config.js";
37-
import { InferenceClientProviderOutputError } from "../error.js";
37+
import { InferenceClientProviderOutputError } from "../errors.js";
3838
import type { TabularClassificationOutput } from "../tasks/tabular/tabularClassification.js";
3939
import type { BodyParams, RequestArgs, UrlParams } from "../types.js";
4040
import { toArray } from "../utils/toArray.js";
@@ -224,8 +224,7 @@ export class HFInferenceAudioClassificationTask extends HFInferenceTask implemen
224224

225225
export class HFInferenceAutomaticSpeechRecognitionTask
226226
extends HFInferenceTask
227-
implements AutomaticSpeechRecognitionTaskHelper
228-
{
227+
implements AutomaticSpeechRecognitionTaskHelper {
229228
override async getResponse(response: AutomaticSpeechRecognitionOutput): Promise<AutomaticSpeechRecognitionOutput> {
230229
return response;
231230
}
@@ -234,9 +233,9 @@ export class HFInferenceAutomaticSpeechRecognitionTask
234233
return "data" in args
235234
? args
236235
: {
237-
...omit(args, "inputs"),
238-
data: args.inputs,
239-
};
236+
...omit(args, "inputs"),
237+
data: args.inputs,
238+
};
240239
}
241240
}
242241

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

272271
export class HFInferenceDocumentQuestionAnsweringTask
273272
extends HFInferenceTask
274-
implements DocumentQuestionAnsweringTaskHelper
275-
{
273+
implements DocumentQuestionAnsweringTaskHelper {
276274
override async getResponse(
277275
response: DocumentQuestionAnsweringOutput
278276
): Promise<DocumentQuestionAnsweringOutput[number]> {
@@ -408,8 +406,7 @@ export class HFInferenceObjectDetectionTask extends HFInferenceTask implements O
408406

409407
export class HFInferenceZeroShotImageClassificationTask
410408
extends HFInferenceTask
411-
implements ZeroShotImageClassificationTaskHelper
412-
{
409+
implements ZeroShotImageClassificationTaskHelper {
413410
override async getResponse(response: ZeroShotImageClassificationOutput): Promise<ZeroShotImageClassificationOutput> {
414411
if (Array.isArray(response) && response.every((x) => typeof x.label === "string" && typeof x.score === "number")) {
415412
return response;
@@ -439,20 +436,20 @@ export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements
439436
if (
440437
Array.isArray(response)
441438
? response.every(
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-
)
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+
)
450447
: typeof response === "object" &&
451-
!!response &&
452-
typeof response.answer === "string" &&
453-
typeof response.end === "number" &&
454-
typeof response.score === "number" &&
455-
typeof response.start === "number"
448+
!!response &&
449+
typeof response.answer === "string" &&
450+
typeof response.end === "number" &&
451+
typeof response.score === "number" &&
452+
typeof response.start === "number"
456453
) {
457454
return Array.isArray(response) ? response[0] : response;
458455
}
@@ -609,8 +606,7 @@ export class HFInferenceTabularClassificationTask extends HFInferenceTask implem
609606

610607
export class HFInferenceVisualQuestionAnsweringTask
611608
extends HFInferenceTask
612-
implements VisualQuestionAnsweringTaskHelper
613-
{
609+
implements VisualQuestionAnsweringTaskHelper {
614610
override async getResponse(response: VisualQuestionAnsweringOutput): Promise<VisualQuestionAnsweringOutput[number]> {
615611
if (
616612
Array.isArray(response) &&

packages/inference/src/providers/hyperbolic.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
TaskProviderHelper,
2424
type TextToImageTaskHelper,
2525
} from "./providerHelper.js";
26-
import { InferenceClientProviderOutputError } from "../error.js";
26+
import { InferenceClientProviderOutputError } from "../errors.js";
2727
const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
2828

2929
export interface HyperbolicTextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
@@ -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,

0 commit comments

Comments
 (0)