Spaces:
Sleeping
Sleeping
delete unused file
Browse files- src/lib/server/getInit.ts +0 -58
src/lib/server/getInit.ts
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
import type { Options, RequestArgs } from "@huggingface/inference";
|
2 |
-
|
3 |
-
const HF_INFERENCE_API_BASE_URL = "https://api-inference.huggingface.co/models/";
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Helper that prepares request arguments
|
7 |
-
*/
|
8 |
-
export function makeRequestOptions(
|
9 |
-
args: RequestArgs & {
|
10 |
-
data?: Blob | ArrayBuffer;
|
11 |
-
stream?: boolean;
|
12 |
-
},
|
13 |
-
options?: Options & {
|
14 |
-
/** For internal HF use, which is why it's not exposed in {@link Options} */
|
15 |
-
includeCredentials?: boolean;
|
16 |
-
}
|
17 |
-
): { url: string; info: RequestInit } {
|
18 |
-
const { model, accessToken, ...otherArgs } = args;
|
19 |
-
|
20 |
-
const headers: Record<string, string> = {};
|
21 |
-
if (accessToken) {
|
22 |
-
headers["Authorization"] = `Bearer ${accessToken}`;
|
23 |
-
}
|
24 |
-
|
25 |
-
const binary = "data" in args && !!args.data;
|
26 |
-
|
27 |
-
if (!binary) {
|
28 |
-
headers["Content-Type"] = "application/json";
|
29 |
-
} else {
|
30 |
-
if (options?.wait_for_model) {
|
31 |
-
headers["X-Wait-For-Model"] = "true";
|
32 |
-
}
|
33 |
-
if (options?.use_cache === false) {
|
34 |
-
headers["X-Use-Cache"] = "false";
|
35 |
-
}
|
36 |
-
if (options?.dont_load_model) {
|
37 |
-
headers["X-Load-Model"] = "0";
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
const url =
|
42 |
-
/^http(s?):/.test(model) || model.startsWith("/")
|
43 |
-
? model
|
44 |
-
: `${HF_INFERENCE_API_BASE_URL}${model}`;
|
45 |
-
const info: RequestInit = {
|
46 |
-
headers,
|
47 |
-
method: "POST",
|
48 |
-
body: binary
|
49 |
-
? args.data
|
50 |
-
: JSON.stringify({
|
51 |
-
...otherArgs,
|
52 |
-
options,
|
53 |
-
}),
|
54 |
-
credentials: options?.includeCredentials ? "include" : "same-origin",
|
55 |
-
};
|
56 |
-
|
57 |
-
return { url, info };
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|