文档
基础知识
图像输入
将图像作为输入传递给模型的 API
一些模型,称为 VLM(视觉语言模型),可以接受图像作为输入。您可以使用 .respond() 方法将图像传递给模型。
如果您还没有 VLM,可以使用以下命令下载 qwen2-vl-2b-instruct 等模型。
lms get qwen2-vl-2b-instruct
连接到 LM Studio 并获取您要使用的 VLM(视觉语言模型)的句柄。
import { LMStudioClient } from "@lmstudio/sdk";
const client = new LMStudioClient();
const model = await client.llm.model("qwen2-vl-2b-instruct");
使用 client.files.prepareImage() 方法获取图像句柄,该句柄随后可以传递给模型。
const imagePath = "/path/to/image.jpg"; // Replace with the path to your image
const image = await client.files.prepareImage(imagePath);
如果您只有 base64 字符串形式的图像,可以使用 client.files.prepareImageBase64() 方法。
const imageBase64 = "Your base64 string here";
const image = await client.files.prepareImageBase64(imageBase64);
LM Studio 服务器支持 JPEG、PNG 和 WebP 图像格式。
.respond() 中将图像传递给模型通过在 .respond() 方法中将图像传递给模型来生成预测。
const prediction = model.respond([
{ role: "user", content: "Describe this image please", images: [image] },
]);
本页的源代码可在 GitHub 上获取