ドキュメント

画像入力

VLM (Vision-Language Models) と呼ばれる一部のモデルは、画像をインプットとして受け入れることができます。.respond() メソッドを使用して、モデルに画像を渡すことができます。

前提条件:VLM (Vision-Language Model) を入手する

VLM をまだお持ちでない場合は、次のコマンドを使用して qwen2-vl-2b-instruct のようなモデルをダウンロードできます

lms get qwen2-vl-2b-instruct

1. モデルをインスタンス化する

LM Studio に接続し、使用したい VLM (Vision-Language Model) のハンドルを取得します。

import { LMStudioClient } from "@lmstudio/sdk";
const client = new LMStudioClient();

const model = await client.llm.model("qwen2-vl-2b-instruct");

2. 画像を準備する

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 の画像フォーマットをサポートしています。

3. .respond() で画像をモデルに渡す

.respond() メソッドで画像をモデルに渡すことにより、予測を生成します。

const prediction = model.respond([
  { role: "user", content: "Describe this image please", images: [image] },
]);