Skip to content

Commit 956050f

Browse files
committed
lint & format
1 parent c886dd5 commit 956050f

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ export async function makeRequestOptions(
6868
? "hf-token"
6969
: "provider-key"
7070
: includeCredentials === "include"
71-
? "credentials-include"
72-
: "none";
71+
? "credentials-include"
72+
: "none";
7373

7474
const url = endpointUrl
7575
? chatCompletion
7676
? endpointUrl + `/v1/chat/completions`
7777
: endpointUrl
7878
: makeUrl({
79-
authMethod,
80-
chatCompletion: chatCompletion ?? false,
81-
forceTask,
82-
model,
83-
provider: provider ?? "hf-inference",
84-
taskHint,
85-
});
79+
authMethod,
80+
chatCompletion: chatCompletion ?? false,
81+
forceTask,
82+
model,
83+
provider: provider ?? "hf-inference",
84+
taskHint,
85+
});
8686

8787
const headers: Record<string, string> = {};
8888
if (accessToken) {
@@ -148,9 +148,9 @@ export async function makeRequestOptions(
148148
body: binary
149149
? args.data
150150
: JSON.stringify({
151-
...otherArgs,
152-
...(chatCompletion || provider === "together" ? { model } : undefined),
153-
}),
151+
...otherArgs,
152+
...(chatCompletion || provider === "together" ? { model } : undefined),
153+
}),
154154
...(credentials ? { credentials } : undefined),
155155
signal: options?.signal,
156156
};
@@ -176,7 +176,7 @@ function makeUrl(params: {
176176
const baseUrl = shouldProxy
177177
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
178178
: BLACKFORESTLABS_AI_API_BASE_URL;
179-
return `${baseUrl}/${params.model}`
179+
return `${baseUrl}/${params.model}`;
180180
}
181181
case "fal-ai": {
182182
const baseUrl = shouldProxy

packages/inference/src/tasks/cv/textToImage.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ interface BlackForestLabsResponse {
2727
*/
2828
export async function textToImage(args: TextToImageArgs, options?: Options): Promise<Blob> {
2929
const payload =
30-
args.provider === "together" || args.provider === "fal-ai" || args.provider === "replicate" || args.provider === "black-forest-labs"
30+
args.provider === "together" ||
31+
args.provider === "fal-ai" ||
32+
args.provider === "replicate" ||
33+
args.provider === "black-forest-labs"
3134
? {
32-
...omit(args, ["inputs", "parameters"]),
33-
...args.parameters,
34-
...(args.provider !== "replicate" ? { response_format: "base64" } : undefined),
35-
prompt: args.inputs,
36-
}
35+
...omit(args, ["inputs", "parameters"]),
36+
...args.parameters,
37+
...(args.provider !== "replicate" ? { response_format: "base64" } : undefined),
38+
prompt: args.inputs,
39+
}
3740
: args;
38-
const res = await request<TextToImageOutput | Base64ImageGeneration | OutputUrlImageGeneration | BlackForestLabsResponse>(payload, {
41+
const res = await request<
42+
TextToImageOutput | Base64ImageGeneration | OutputUrlImageGeneration | BlackForestLabsResponse
43+
>(payload, {
3944
...options,
4045
taskHint: "text-to-image",
4146
});
@@ -77,11 +82,21 @@ async function pollBflResponse(url: string): Promise<Blob> {
7782
throw new InferenceOutputError("Failed to fetch result from black forest labs API");
7883
}
7984
const payload = await resp.json();
80-
if (typeof payload === "object" && payload && "status" in payload && typeof payload.status === "string" && payload.status === "Ready" && "result" in payload && typeof payload.result === "object" && payload.result && "sample" in payload.result && typeof payload.result.sample === "string") {
85+
if (
86+
typeof payload === "object" &&
87+
payload &&
88+
"status" in payload &&
89+
typeof payload.status === "string" &&
90+
payload.status === "Ready" &&
91+
"result" in payload &&
92+
typeof payload.result === "object" &&
93+
payload.result &&
94+
"sample" in payload.result &&
95+
typeof payload.result.sample === "string"
96+
) {
8197
const image = await fetch(payload.result.sample);
8298
return await image.blob();
8399
}
84100
}
85101
throw new InferenceOutputError("Failed to fetch result from black forest labs API");
86102
}
87-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function delay(ms: number): Promise<void> {
2-
return new Promise(resolve => {
2+
return new Promise((resolve) => {
33
setTimeout(() => resolve(), ms);
44
});
55
}

packages/inference/test/HfInference.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,6 @@ describe.concurrent("HfInference", () => {
11291129
describe.concurrent(
11301130
"Black Forest Labs",
11311131
() => {
1132-
11331132
HARDCODED_MODEL_ID_MAPPING["black-forest-labs"] = {
11341133
"black-forest-labs/FLUX.1-dev": "flux-dev",
11351134
// "black-forest-labs/FLUX.1-schnell": "flux-pro",
@@ -1146,11 +1145,10 @@ describe.concurrent("HfInference", () => {
11461145
width: 256,
11471146
num_inference_steps: 4,
11481147
seed: 8817,
1149-
}
1148+
},
11501149
});
11511150
expect(res).toBeInstanceOf(Blob);
11521151
});
1153-
11541152
},
11551153
TIMEOUT
11561154
);

0 commit comments

Comments
 (0)