ドキュメンテーション
LLM をローカルで実行
プリセット
ユーザーインターフェース
高度な設定
LLM をローカルで実行
プリセット
ユーザーインターフェース
高度な設定
OpenAI 互換性 API
チャット補完 (テキストおよび画像)、補完、埋め込みのエンドポイントにリクエストを送信します。
LM Studio は、いくつかの OpenAI エンドポイントからのリクエストを受け付け、OpenAI のような応答オブジェクトを返します。
GET /v1/models POST /v1/chat/completions POST /v1/embeddings POST /v1/completions
既存の OpenAI クライアント(Python、JS、C# など)は、"ベース URL" プロパティを OpenAI のサーバーではなく LM Studio に向けることで再利用できます。
base url
を LM Studio に向ける1234
であることを前提としています。from openai import OpenAI client = OpenAI( + base_url="http://localhost:1234/v1" ) # ... the rest of your code ...
import OpenAI from 'openai'; const client = new OpenAI({ + baseUrl: "http://localhost:1234/v1" }); // ... the rest of your code ...
- curl https://api.openai.com/v1/chat/completions \ + curl http://localhost:1234/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ - "model": "gpt-4o-mini", + "model": "use the model identifier from LM Studio here", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }'
/v1/models
GET
リクエストcurl http://localhost:1234/v1/models
/v1/chat/completions
POST
リクエストlms log stream
を使用してターミナルウィンドウを開いたままにしてください# Example: reuse your existing OpenAI setup from openai import OpenAI # Point to the local server client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio") completion = client.chat.completions.create( model="model-identifier", messages=[ {"role": "system", "content": "Always answer in rhymes."}, {"role": "user", "content": "Introduce yourself."} ], temperature=0.7, ) print(completion.choices[0].message)
/v1/embeddings
POST
リクエスト# Make sure to `pip install openai` first from openai import OpenAI client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio") def get_embedding(text, model="model-identifier"): text = text.replace("\n", " ") return client.embeddings.create(input = [text], model=model).data[0].embedding print(get_embedding("Once upon a time, there was a cat."))
/v1/completions
この OpenAI のようなエンドポイントは、OpenAI ではサポートされなくなりました。LM Studio は引き続きこれをサポートします。
このエンドポイントをチャット調整済みモデルで使用すると、モデルが余分なロールトークンを出力するなど、予期しない動作が発生する可能性があります。
最良の結果を得るには、ベースモデルを利用してください。
POST
リクエストlms log stream
を使用してターミナルウィンドウを開いたままにしてください各パラメータの説明については、https://platform.openai.com/docs/api-reference/chat/create を参照してください。
model top_p top_k messages temperature max_tokens stream stop presence_penalty frequency_penalty logit_bias repeat_penalty seed
他の LM Studio 開発者とチャットしたり、LLM、ハードウェアなどについてLM Studio Discord サーバーで議論できます。
このページについて
OpenAI のような API エンドポイント
- サポートされているエンドポイント
既存の OpenAI クライアントの再利用
- ベース URL を LM Studio に向ける
エンドポイントの概要
- /v1/models
- /v1/chat/completions
- /v1/embeddings
- /v1/completions
サポートされているペイロードパラメータ
コミュニティ