Skip to content

Commit 456fa2a

Browse files
committed
Merge branch 'main' of github.com:huggingface/huggingface.js into update-request-func
2 parents 40ea773 + 6c9b6bf commit 456fa2a

File tree

11 files changed

+7187
-7152
lines changed

11 files changed

+7187
-7152
lines changed

packages/inference/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const HF_HUB_URL = "https://huggingface.co";
22
export const HF_ROUTER_URL = "https://router.huggingface.co";
3+
export const HF_HEADER_X_BILL_TO = "X-HF-Bill-To";

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
1+
import { HF_HUB_URL, HF_ROUTER_URL, HF_HEADER_X_BILL_TO } from "../config";
22
import { BLACK_FOREST_LABS_CONFIG } from "../providers/black-forest-labs";
33
import { CEREBRAS_CONFIG } from "../providers/cerebras";
44
import { COHERE_CONFIG } from "../providers/cohere";
@@ -117,7 +117,7 @@ export function makeRequestOptionsFromResolvedModel(
117117
const provider = maybeProvider ?? "hf-inference";
118118
const providerConfig = providerConfigs[provider];
119119

120-
const { includeCredentials, task, chatCompletion, signal } = options ?? {};
120+
const { includeCredentials, task, chatCompletion, signal, billTo } = options ?? {};
121121

122122
const authMethod = (() => {
123123
if (providerConfig.clientSideRoutingOnly) {
@@ -159,6 +159,9 @@ export function makeRequestOptionsFromResolvedModel(
159159
accessToken,
160160
authMethod,
161161
});
162+
if (billTo) {
163+
headers[HF_HEADER_X_BILL_TO] = billTo;
164+
}
162165

163166
// Add content-type to headers
164167
if (!binary) {

packages/inference/src/snippets/templates/js/fetch/textToImage.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async function query(data) {
1414
return result;
1515
}
1616

17-
query({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {
17+
18+
query({ {{ providerInputs.asTsString }} }).then((response) => {
1819
// Use image
1920
});
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { SentenceSimilarityInput, SentenceSimilarityOutput } from "@huggingface/tasks";
22
import { InferenceOutputError } from "../../lib/InferenceOutputError";
33
import type { BaseArgs, Options } from "../../types";
4-
import { omit } from "../../utils/omit";
54
import { innerRequest } from "../../utils/request";
65

76
export type SentenceSimilarityArgs = BaseArgs & SentenceSimilarityInput;
@@ -14,7 +13,7 @@ export async function sentenceSimilarity(
1413
options?: Options
1514
): Promise<SentenceSimilarityOutput> {
1615
const res = (
17-
await innerRequest<SentenceSimilarityOutput>(prepareInput(args), {
16+
await innerRequest<SentenceSimilarityOutput>(args, {
1817
...options,
1918
task: "sentence-similarity",
2019
})
@@ -26,11 +25,3 @@ export async function sentenceSimilarity(
2625
}
2726
return res;
2827
}
29-
30-
function prepareInput(args: SentenceSimilarityArgs) {
31-
return {
32-
...omit(args, ["inputs", "parameters"]),
33-
inputs: { ...omit(args.inputs, "sourceSentence") },
34-
parameters: { source_sentence: args.inputs.sourceSentence, ...args.parameters },
35-
};
36-
}

packages/inference/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ export interface Options {
2424
* (Default: "same-origin"). String | Boolean. Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all.
2525
*/
2626
includeCredentials?: string | boolean;
27+
28+
/**
29+
* The billing account to use for the requests.
30+
*
31+
* By default the requests are billed on the user's account.
32+
* Requests can only be billed to an organization the user is a member of, and which has subscribed to Enterprise Hub.
33+
*/
34+
billTo?: string;
2735
}
2836

2937
export type InferenceTask = Exclude<PipelineType, "other">;

0 commit comments

Comments
 (0)