ドキュメント

基本

画像入力

モデルに画像を入力として渡すためのAPI

VLM(Vision-Language Model)と呼ばれる一部のモデルは、画像を入力として受け入れることができます。`.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] },
]);

このページのソースは GitHub で利用可能です。