Created
June 28, 2025 19:31
-
-
Save Vaibhavs10/e5d1b50b386d921a413399ca73fa7b29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test-provider-snippet.mjs | |
import { snippets as hfInferenceSnippets } from "@huggingface/inference"; | |
async function fetchModelData(modelId) { | |
const res = await fetch(`https://huggingface.co/api/models/${modelId}`); | |
if (!res.ok) throw new Error(`Model ${modelId} not found`); | |
const apiModel = await res.json(); | |
return { | |
id: apiModel.modelId ?? modelId, | |
pipeline_tag: apiModel.pipeline_tag, | |
tags: apiModel.tags ?? [], | |
}; | |
} | |
async function main() { | |
const modelId = process.argv[2] || "gpt2"; | |
const modelData = await fetchModelData(modelId); | |
const providerSnippet = hfInferenceSnippets | |
.getInferenceSnippets(modelData, "auto") | |
.find(sn => sn.language === "python" && sn.client === "huggingface_hub"); | |
if (!providerSnippet) { | |
console.error("No matching Python/huggingface_hub snippet returned."); | |
process.exit(1); | |
} | |
const content = Array.isArray(providerSnippet.content) | |
? providerSnippet.content.join("\n") | |
: providerSnippet.content; | |
console.log(`✅ snippet for ${modelId}\n`); | |
console.log("──────── snippet start ────────"); | |
console.log(content); | |
console.log("──────── snippet end ──────────"); | |
} | |
main().catch(err => { | |
console.error(err); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment