import { VlmRun } from "vlmrun";import { z } from "zod";import { zodToJsonSchema } from "zod-to-json-schema";// Define the response schema with Zodconst DetectionsSchema = z.object({ detections: z.array(z.object({ label: z.string().describe("Name of the detected object"), xywh: z.array(z.number()).describe("Bounding box (x, y, width, height)") })).describe("List of detections")});// Initialize the VLMRun clientconst client = new VlmRun({ apiKey: "<VLMRUN_API_KEY>", baseURL: "https://api.vlm.run/v1"});// Execute object detection with structured outputconst response = await client.agent.completions.create({ model: "vlmrun-orion-1:auto", messages: [ { role: "user", content: [ { type: "text", text: "Detect all objects in this image" }, { type: "image_url", image_url: { url: "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/image.object-detection/donuts.png", detail: "auto" } } ] } ], response_format: { type: "json_schema", schema: zodToJsonSchema(DetectionsSchema) }});const result = DetectionsSchema.parse(JSON.parse(response.choices[0].message.content));
FAQ
What objects are supported?
Open-world (open-set) detection. There is no predefined category list. Describe the object in natural language. That includes rare items, parts of objects, and visual relations.