zero_shot_image_classification
Classify images using custom labels without prior training. Upload an image and specify categories to identify objects, scenes, or content using AI-powered computer vision.
Instructions
Classify an image with zero-shot labels using DeepInfra OpenAI-compatible API (CLIP).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| candidate_labels | Yes | ||
| image_url | Yes | ||
| model | No |
Implementation Reference
- src/mcp_deepinfra/server.py:120-150 (handler)The core handler function for the 'zero_shot_image_classification' tool. It is decorated with @app.tool() for automatic MCP registration and implements the logic using an OpenAI-compatible vision model to classify the image against provided candidate labels, returning a JSON-formatted result or error.@app.tool() async def zero_shot_image_classification(image_url: str, candidate_labels: list[str]) -> str: """Classify an image with zero-shot labels using DeepInfra OpenAI-compatible API (CLIP).""" model = DEFAULT_MODELS["zero_shot_image_classification"] try: # Use chat/completions with vision capability to get classification response = await client.chat.completions.create( model=model, messages=[ { "role": "user", "content": [ { "type": "text", "text": f"Classify this image into one of these categories: {', '.join(candidate_labels)}. Return a JSON with 'label' and 'score' fields." }, { "type": "image_url", "image_url": {"url": image_url} } ] } ], max_tokens=200, ) if response.choices: return response.choices[0].message.content else: return "Unable to classify image" except Exception as e: return f"Error classifying image: {type(e).__name__}: {str(e)}"
- src/mcp_deepinfra/server.py:119-119 (registration)Conditional registration logic that defines the tool only if enabled via ENABLED_TOOLS environment variable or 'all'.if "all" in ENABLED_TOOLS or "zero_shot_image_classification" in ENABLED_TOOLS:
- src/mcp_deepinfra/server.py:36-36 (helper)Default model configuration for the zero_shot_image_classification tool, retrievable via environment variable."zero_shot_image_classification": os.getenv("MODEL_ZERO_SHOT_IMAGE_CLASSIFICATION", "openai/gpt-4o-mini"),