Skip to content

Commit 8399207

Browse files
committed
fix python requests ones
1 parent 2644759 commit 8399207

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

packages/tasks/src/snippets/python.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,24 @@ export function getPythonInferenceSnippet(
313313
// Example sending an image to the Message API
314314
return snippetConversationalWithImage(model, accessToken);
315315
} else {
316-
const body =
316+
let snippets =
317317
model.pipeline_tag && model.pipeline_tag in pythonSnippets
318-
? pythonSnippets[model.pipeline_tag]?.(model, accessToken) ?? ""
319-
: "";
318+
? pythonSnippets[model.pipeline_tag]?.(model, accessToken) ?? { content: "" }
319+
: { content: "" };
320320

321-
return {
322-
content: `import requests
321+
snippets = Array.isArray(snippets) ? snippets : [snippets];
323322

323+
return snippets.map((snippet) => {
324+
return {
325+
...snippet,
326+
content: `import requests
327+
324328
API_URL = "https://api-inference.huggingface.co/models/${model.id}"
325329
headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
326-
327-
${body}`,
328-
};
330+
331+
${snippet.content}`,
332+
};
333+
});
329334
}
330335
}
331336

0 commit comments

Comments
 (0)