Skip to content

Commit a927440

Browse files
kefranabgWauplin
andauthored
Add billTo parameter to snippets (#1349)
Adding a parameter to generate snippets with the `billTo` option Pre-requisite of https://www.figma.com/design/3kPIEQvrVISDp2VPLmoJax/-SPEC--Inference-Providers?node-id=633-1725&t=Il0MBjEKJghDXHnw-0 --------- Co-authored-by: Lucain <[email protected]>
1 parent f7608fb commit a927440

File tree

63 files changed

+329
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+329
-72
lines changed

packages/inference/src/snippets/getInferenceSnippets.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface TemplateParams {
3737
model?: ModelDataMinimal;
3838
provider?: InferenceProvider;
3939
providerModelId?: string;
40+
billTo?: string;
4041
methodName?: string; // specific to snippetBasic
4142
importBase64?: boolean; // specific to snippetImportRequests
4243
importJson?: boolean; // specific to snippetImportRequests
@@ -119,6 +120,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
119120
accessToken: string,
120121
provider: InferenceProvider,
121122
inferenceProviderMapping?: InferenceProviderModelMapping,
123+
billTo?: string,
122124
opts?: Record<string, unknown>
123125
): InferenceSnippet[] => {
124126
const providerModelId = inferenceProviderMapping?.providerId ?? model.id;
@@ -146,13 +148,14 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
146148
providerModelId,
147149
providerHelper,
148150
{
149-
accessToken: accessToken,
150-
provider: provider,
151+
accessToken,
152+
provider,
151153
...inputs,
152154
} as RequestArgs,
153155
inferenceProviderMapping,
154156
{
155-
task: task,
157+
task,
158+
billTo,
156159
}
157160
);
158161

@@ -191,6 +194,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
191194
model,
192195
provider,
193196
providerModelId: providerModelId ?? model.id,
197+
billTo,
194198
};
195199

196200
/// Iterate over clients => check if a snippet exists => generate
@@ -279,6 +283,7 @@ const snippets: Partial<
279283
accessToken: string,
280284
provider: InferenceProvider,
281285
inferenceProviderMapping?: InferenceProviderModelMapping,
286+
billTo?: string,
282287
opts?: Record<string, unknown>
283288
) => InferenceSnippet[]
284289
>
@@ -319,10 +324,11 @@ export function getInferenceSnippets(
319324
accessToken: string,
320325
provider: InferenceProvider,
321326
inferenceProviderMapping?: InferenceProviderModelMapping,
327+
billTo?: string,
322328
opts?: Record<string, unknown>
323329
): InferenceSnippet[] {
324330
return model.pipeline_tag && model.pipeline_tag in snippets
325-
? snippets[model.pipeline_tag]?.(model, accessToken, provider, inferenceProviderMapping, opts) ?? []
331+
? snippets[model.pipeline_tag]?.(model, accessToken, provider, inferenceProviderMapping, billTo, opts) ?? []
326332
: [];
327333
}
328334

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ async function query(data) {
55
headers: {
66
Authorization: "{{ authorizationHeader }}",
77
"Content-Type": "application/json",
8-
},
8+
{% if billTo %}
9+
"X-HF-Bill-To": "{{ billTo }}",
10+
{% endif %} },
911
method: "POST",
1012
body: JSON.stringify(data),
1113
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ async function query(data) {
44
{
55
headers: {
66
Authorization: "{{ authorizationHeader }}",
7-
"Content-Type": "audio/flac"
8-
},
7+
"Content-Type": "audio/flac",
8+
{% if billTo %}
9+
"X-HF-Bill-To": "{{ billTo }}",
10+
{% endif %} },
911
method: "POST",
1012
body: JSON.stringify(data),
1113
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ async function query(data) {
44
{
55
headers: {
66
Authorization: "{{ authorizationHeader }}",
7-
"Content-Type": "image/jpeg"
8-
},
7+
"Content-Type": "image/jpeg",
8+
{% if billTo %}
9+
"X-HF-Bill-To": "{{ billTo }}",
10+
{% endif %} },
911
method: "POST",
1012
body: JSON.stringify(data),
1113
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ async function query(data) {
66
headers: {
77
Authorization: "{{ authorizationHeader }}",
88
"Content-Type": "application/json",
9-
},
9+
{% if billTo %}
10+
"X-HF-Bill-To": "{{ billTo }}",
11+
{% endif %} },
1012
method: "POST",
1113
body: JSON.stringify(data),
1214
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ async function query(data) {
55
headers: {
66
Authorization: "{{ authorizationHeader }}",
77
"Content-Type": "application/json",
8-
},
8+
{% if billTo %}
9+
"X-HF-Bill-To": "{{ billTo }}",
10+
{% endif %} },
911
method: "POST",
1012
body: JSON.stringify(data),
1113
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ async function query(data) {
55
headers: {
66
Authorization: "{{ authorizationHeader }}",
77
"Content-Type": "application/json",
8-
},
8+
{% if billTo %}
9+
"X-HF-Bill-To": "{{ billTo }}",
10+
{% endif %} },
911
method: "POST",
1012
body: JSON.stringify(data),
1113
}

packages/inference/src/snippets/templates/js/huggingface.js/basic.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const output = await client.{{ methodName }}({
66
model: "{{ model.id }}",
77
inputs: {{ inputs.asObj.inputs }},
88
provider: "{{ provider }}",
9-
});
9+
}{% if billTo %}, {
10+
billTo: "{{ billTo }}",
11+
}{% endif %});
1012

1113
console.log(output);

packages/inference/src/snippets/templates/js/huggingface.js/basicAudio.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const output = await client.{{ methodName }}({
88
data,
99
model: "{{ model.id }}",
1010
provider: "{{ provider }}",
11-
});
11+
}{% if billTo %}, {
12+
billTo: "{{ billTo }}",
13+
}{% endif %});
1214

1315
console.log(output);

packages/inference/src/snippets/templates/js/huggingface.js/basicImage.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const output = await client.{{ methodName }}({
88
data,
99
model: "{{ model.id }}",
1010
provider: "{{ provider }}",
11-
});
11+
}{% if billTo %}, {
12+
billTo: "{{ billTo }}",
13+
}{% endif %});
1214

1315
console.log(output);

0 commit comments

Comments
 (0)