Skip to content

Commit e815d0b

Browse files
authored
No extra newline in inference code snippets (#874)
from @osanseviero suggestion in huggingface/hub-docs#1398 (comment) Let's remove the extra newlines at the end of code snippets (if not already the case)
1 parent caef921 commit e815d0b

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

packages/tasks/src/snippets/curl.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export const snippetBasic = (model: ModelDataMinimal, accessToken: string): stri
77
-X POST \\
88
-d '{"inputs": ${getModelInputSnippet(model, true)}}' \\
99
-H 'Content-Type: application/json' \\
10-
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
11-
`;
10+
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`;
1211

1312
export const snippetTextGeneration = (model: ModelDataMinimal, accessToken: string): string => {
1413
if (model.config?.tokenizer_config?.chat_template) {
@@ -33,15 +32,13 @@ export const snippetZeroShotClassification = (model: ModelDataMinimal, accessTok
3332
-X POST \\
3433
-d '{"inputs": ${getModelInputSnippet(model, true)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}' \\
3534
-H 'Content-Type: application/json' \\
36-
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
37-
`;
35+
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`;
3836

3937
export const snippetFile = (model: ModelDataMinimal, accessToken: string): string =>
4038
`curl https://api-inference.huggingface.co/models/${model.id} \\
4139
-X POST \\
4240
--data-binary '@${getModelInputSnippet(model, true, true)}' \\
43-
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
44-
`;
41+
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`;
4542

4643
export const curlSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string) => string>> = {
4744
// Same order as in js/src/lib/interfaces/Types.ts

packages/tasks/src/snippets/js.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ for await (const chunk of inference.chatCompletionStream({
3636
max_tokens: 500,
3737
})) {
3838
process.stdout.write(chunk.choices[0]?.delta?.content || "");
39-
}
40-
`;
39+
}`;
4140
} else {
4241
return snippetBasic(model, accessToken);
4342
}

packages/tasks/src/snippets/python.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ for message in client.chat_completion(
1515
max_tokens=500,
1616
stream=True,
1717
):
18-
print(message.choices[0].delta.content, end="")
19-
`;
18+
print(message.choices[0].delta.content, end="")`;
2019

2120
export const snippetZeroShotClassification = (model: ModelDataMinimal): string =>
2221
`def query(payload):

0 commit comments

Comments
 (0)