from vlmrun.client import VLMRun
from pydantic import BaseModel, Field
# Define response schema
class ImageCaption(BaseModel):
caption: str = Field(..., description="Detailed caption of the image")
tags: list[str] = Field(..., description="Tags describing the image")
client = VLMRun(api_key="<VLMRUN_API_KEY>", base_url="https://agent.vlm.run/v1")
# Get structured response
response = client.agent.completions.create(
model="vlmrun-orion-1:auto",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Generate a caption and tags for this image"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}
],
response_format={"type": "json_schema", "schema": ImageCaption.model_json_schema()}
)
# Validate and parse the response
result = ImageCaption.model_validate_json(response.choices[0].message.content)
print(result)