tinycodinglm / lmstudio /lmstudio-0075.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.93 kB
opencode trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

Does LM Studio support vision (image input) models locally? Show how to send an image with the OpenAI-compatible chat completions API using base64. Include code examples.

Assistant

Yes - with a vision-capable model loaded (e.g. LLaVA, Qwen-VL - check the Models tab for VL variants). Text-only models will error on image input.

python
import base64
from openai import OpenAI

client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")

with open("photo.jpg", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode("utf-8")

response = client.chat.completions.create(
    model="model-identifier-of-loaded-vision-model",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Describe this image."},
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"},
                },
            ],
        }
    ],
    max_tokens=500,
)
print(response.choices[0].message.content)

Limits:

  • Single images only; no video (send frames individually)
  • Images are resized to the model's native resolution
  • Larger images consume more context tokens