Home About Contact
Local LLM , LM Studio

LM Studio を試した

セットアップは https://lmstudio.ai/ の通り。

Ubuntu サーバーで使いたいので、次のようにした:

curl -fsSL https://lmstudio.ai/install.sh | bash

あとは、 https://lmstudio.ai/blog/0.4.0#deploy-on-servers-deploy-in-ci-deploy-anywhere の通り。

lms daemon up
lms get google/gemma-4-e4b
lms server start

about model: google/gemma-4-e4b

すでに lms get 済みの場合は load する(もしかして必要ないかも):

lms load google/gemma-4-e4b

次のようにして使えるモデルを確認する:

curl http://localhost:1234/v1/models 

こんな感じになった。

$ curl http://localhost:1234/v1/models
{
  "data": [
    {
      "id": "google/gemma-4-e4b",
      "object": "model",
      "owned_by": "organization_owner"
    },
    {
      "id": "text-embedding-nomic-embed-text-v1.5",
      "object": "model",
      "owned_by": "organization_owner"
    }
  ],
  "object": "list"
}

/v1/chat/completions を使う:

curl -X POST http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemma-4-e4b",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "日本の首都はどこですか?"}
    ]
  }'

こんな結果になった:

{
  "id": "chatcmpl-jg7switcb8ovru8xux0bl",
  "object": "chat.completion",
  "created": 1777117568,
  "model": "google/gemma-4-e4b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "日本の首都は**東京(とうきょう)**です。",
        "reasoning_content": "\nThinking Process:\n\n1.  **Analyze the Request:** The user asked, \"日本の首都はどこですか?\" (Nihon no shuto wa doko desu ka?) which means \"What is the capital of Japan?\"\n2.  **Determine the Answer:** The capital of Japan is Tokyo.\n3.  **Formulate the Response (Japanese):**\n    *   Direct answer: 東京です。(Tōkyō desu.)\n    *   Polite and comprehensive response (recommended for a helpful assistant): State the answer clearly, and maybe add context.\n4.  **Final Output Construction:** Provide the definitive answer in polite Japanese.\n\n*(Self-Correction/Review): Ensure the tone is helpful and factual.*",
        "tool_calls": []
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 171,
    "total_tokens": 199,
    "completion_tokens_details": {
      "reasoning_tokens": 154
    }
  },
  "stats": {},
  "system_fingerprint": "google/gemma-4-e4b"
}

/v1/embeddings を試したのだがうまくいかない。Claude によれば Gemma 4 は埋め込みに対応していないとのこと。

あらかじめ用意されていた text-embedding-nomic-embed-text-v1.5 を指すことで、埋め込みを得ることもできた。

curl -X POST http://localhost:1234/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-nomic-embed-text-v1.5",
    "input": "Hello, world!"
  }'

埋め込みを使って自分のメモを検索するツールをつくりたいと思っているが、結構たいへんそう。 Python の LangChain などを使えば、”やってみた” レベルならなんとかなりそうだが。 日常的に使えるようにする方法を探していく。