LM Studio
LM Studio
LM Studio로 로컬 LLM을 발견·다운로드·실행할 수 있어요. 모든 LM Studio 모델을 지원해요. litellm 요청 시 model=lm_studio/<any-model-on-lmstudio> 접두사로 설정하기만 하면 돼요.
출처: 문서
본문
개요 (Overview)
| 속성 | 설명 |
|---|---|
| 설명 | 로컬 LLM 발견·다운로드·실행 |
| LiteLLM 라우트 | lm_studio/ |
| 공급자 문서 | LM Studio |
| 지원 OpenAI 엔드포인트 | /chat/completions, /embeddings, /completions |
API 키
# env variable
os.environ['LM_STUDIO_API_BASE']
os.environ['LM_STUDIO_API_KEY'] # optional, default is empty
샘플 사용법 (Sample Usage)
from litellm import completion
import os
os.environ['LM_STUDIO_API_BASE'] = ""
response = completion(
model="lm_studio/llama-3-8b-instruct",
messages=[
{
"role": "user",
"content": "What's the weather like in Boston today in Fahrenheit?",
}
]
)
print(response)
샘플 사용법 - 스트리밍 (Streaming)
from litellm import completion
import os
os.environ['LM_STUDIO_API_KEY'] = ""
response = completion(
model="lm_studio/llama-3-8b-instruct",
messages=[
{
"role": "user",
"content": "What's the weather like in Boston today in Fahrenheit?",
}
],
stream=True,
)
for chunk in response:
print(chunk)
LiteLLM Proxy Server 사용법
config.yaml 수정:
model_list:
- model_name: my-model
litellm_params:
model: lm_studio/<your-model-name> # add lm_studio/ prefix to route as LM Studio provider
api_key: api-key # api key to send your model
Proxy 시작:
$ litellm --config /path/to/config.yaml
LiteLLM Proxy Server로 요청:
OpenAI Python v1.0.0+:
import openai
client = openai.OpenAI(
api_key="sk-<your-litellm-api-key>", # pass litellm proxy key, if you're using virtual keys
base_url="http://0.0.0.0:4000" # litellm-proxy-base url
)
response = client.chat.completions.create(
model="my-model",
messages = [
{
"role": "user",
"content": "what llm are you"
}
],
)
print(response)
curl:
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header "Authorization: Bearer ***" \
--header 'Content-Type: application/json' \
--data '{
"model": "my-model",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
],
}'
지원 파라미터 (Supported Parameters)
지원 파라미터 목록은 Supported Parameters 문서를 참고하세요.
Embedding
from litellm import embedding
import os
os.environ['LM_STUDIO_API_BASE'] = "http://localhost:8000"
response = embedding(
model="lm_studio/jina-embeddings-v3",
input=["Hello world"],
)
print(response)
구조화 출력 (Structured Output)
Pydantic 모델을 전달해 구조화된 출력을 받을 수 있어요.
from pydantic import BaseModel
from litellm import completion
class Book(BaseModel):
title: str
author: str
year: int
response = completion(
model="lm_studio/llama-3-8b-instruct",
messages=[{"role": "user", "content": "Tell me about The Hobbit"}],
response_format=Book,
)
print(response.choices[0].message.content)