Skip to content

Commit

Permalink
No newline at the end of inference code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Aug 29, 2024
1 parent caef921 commit 370a567
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
9 changes: 3 additions & 6 deletions packages/tasks/src/snippets/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const snippetBasic = (model: ModelDataMinimal, accessToken: string): stri
-X POST \\
-d '{"inputs": ${getModelInputSnippet(model, true)}}' \\
-H 'Content-Type: application/json' \\
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
`;
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`;

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

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

export const curlSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string) => string>> = {
// Same order as in js/src/lib/interfaces/Types.ts
Expand Down
3 changes: 1 addition & 2 deletions packages/tasks/src/snippets/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ for await (const chunk of inference.chatCompletionStream({
max_tokens: 500,
})) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
`;
}`;
} else {
return snippetBasic(model, accessToken);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/tasks/src/snippets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ for message in client.chat_completion(
max_tokens=500,
stream=True,
):
print(message.choices[0].delta.content, end="")
`;
print(message.choices[0].delta.content, end="")`;

export const snippetZeroShotClassification = (model: ModelDataMinimal): string =>
`def query(payload):
Expand Down

0 comments on commit 370a567

Please sign in to comment.