Skip to content

Instantly share code, notes, and snippets.

@Vaibhavs10
Created May 7, 2025 13:25
Show Gist options
  • Save Vaibhavs10/b525c1ae4982c04fe0202c2f78ac2f03 to your computer and use it in GitHub Desktop.
Save Vaibhavs10/b525c1ae4982c04fe0202c2f78ac2f03 to your computer and use it in GitHub Desktop.
if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
const pipelineSnippet = ["# Use a pipeline as a high-level helper", "from transformers import pipeline", ""];
if (model.config?.tokenizer_config?.chat_template) {
if (model.tags.includes("conversational") && model.tags.includes("image-text-to-text")) {
pipelineSnippet.push(
"messages = [",
[
" {",
' "role": "user",',
' "content": [',
' {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},',
' {"type": "text", "text": "What animal is on the candy?"}',
" ]",
" },",
].join("\n"),
"]"
);
} else if (model.tags.includes("conversational")) {
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
}
}
pipelineSnippet.push(`pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
pipelineSnippet.push("pipe(messages)");
return [pipelineSnippet.join("\n"), autoSnippet];
}
return [autoSnippet];
@Wauplin
Copy link

Wauplin commented May 7, 2025

	if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
		const pipelineSnippet = [
		    "# Use a pipeline as a high-level helper",
                    "from transformers import pipeline",
                    "",
                    `pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")"
               ];

		if (model.tags.includes("conversational")) {
			if (model.tags.includes("image-text-to-text")) {
				pipelineSnippet.push(
					"messages = [",
					[
						"    {",
						'        "role": "user",',
						'        "content": [',
						'            {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},',
						'            {"type": "text", "text": "What animal is on the candy?"}',
						"        ]",
						"    },",
					].join("\n"),
					"]"
				);
			} else {
				pipelineSnippet.push("messages = [", '    {"role": "user", "content": "Who are you?"},', "]");
			}
                        pipelineSnippet.push("pipe(messages)");
		}

		return [pipelineSnippet.join("\n"), autoSnippet];
	}
	return [autoSnippet];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment