0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

just-agentsでLM Studioのmistral-small3.2を使ってみた

Last updated at Posted at 2025-06-22

概要

mistral-small3.2が出てたので、LM Studioでダウンロードして、just-agentsからローカルで使ってみた備忘録です。

なお、just-agentsはシンプルなAIエージェントのライブラリです。

コード

import base64
import urllib

from just_agents.base_agent import BaseAgent
from just_agents.data_classes import ImageContent as _ImageContent
from just_agents.data_classes import Message, Role, TextContent
from pydantic import AnyUrl


class ImageContent(_ImageContent):
    image_url: AnyUrl


def describe(url: str) -> str:
    llm_options = {
        "model": "lm_studio/mistralai/mistral-small-3.2",
        "api_base": "http://localhost:1234/v1",
        "api_key": "_",
    }
    agent = BaseAgent(llm_options=llm_options)
    with urllib.request.urlopen(url) as fp:
        b64 = base64.b64encode(fp.read()).decode("utf-8")
    message = Message(
        role=Role.user,
        content=[
            TextContent(text="画像の説明"),
            ImageContent(image_url=f"data:image/jpeg;base64,{b64}"),
        ],
    )
    return agent.query(message, remember_query=False)


print(describe("file:///path/to/some.jpg"))
print(describe("https://path/to/some.jpg"))

解説

just-agentsにはImageContentというのがあるので、これを使ってみましょう。
ローカルのLLMの場合は、画像をbase64で渡す必要があるようです。
実際に実行すると、下記のようなエラーになります。

pydantic_core._pydantic_core.ValidationError: 1 validation error for ImageContent
image_url
  URL should have at most 2083 characters [type=url_too_long, \
  input_value='data:image/jpeg;base64,/...', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/url_too_long

調べると、ImageContent.image_urlの型がHttpUrlで、文字列の長さが長いためPydanticでバリデーションエラーになってようです。

今回は、下記のように無理やりAnyUrlに変えて回避しました。

from just_agents.data_classes import ImageContent as _ImageContent
from pydantic import AnyUrl

class ImageContent(_ImageContent):
    image_url: AnyUrl

軽いモデルですが、わりと良さそうな印象でした

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?