文档
图像输入
一些模型,称为 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] },
]);
本页内容
先决条件:获取 VLM(视觉-语言模型)
1. 实例化模型
2. 准备图像
3. 在 .respond() 中将图像传递给模型