Nous.Providers.LMStudio (nous v0.16.3)
View SourceLM Studio local provider implementation.
LM Studio provides a local OpenAI-compatible API server for running
models locally. By default it runs on http://localhost:1234/v1.
Configuration
No API key is required for local usage. Configure the base URL if needed:
config :nous, :lmstudio,
base_url: "http://localhost:1234/v1"Or use environment variable:
export LMSTUDIO_BASE_URL="http://localhost:1234/v1"Usage
# Via Model.parse
model = Nous.Model.parse("lmstudio:my-local-model")
# Direct provider usage
{:ok, response} = Nous.Providers.LMStudio.chat(%{
"model" => "my-local-model",
"messages" => [%{"role" => "user", "content" => "Hello"}]
})Features
LM Studio supports:
- OpenAI-compatible chat completions
- Streaming responses
- Tool/function calling (model-dependent)
- Various open-source models (Llama, Mistral, etc.)
Summary
Functions
Get the API key from options, environment, or application config.
Get the base URL from options, application config, or default.
Count tokens in messages (rough estimate).
High-level request with message conversion, telemetry, and error wrapping.
High-level streaming request with message conversion and telemetry.
Functions
Get the API key from options, environment, or application config.
Lookup order:
:api_keyoption passed directly- Environment variable (LMSTUDIO_API_KEY)
- Application config:
config :nous, lmstudio, api_key: "..."
Get the base URL from options, application config, or default.
Lookup order:
:base_urloption passed directly- Application config:
config :nous, lmstudio, base_url: "..." - Default: http://localhost:1234/v1
Count tokens in messages (rough estimate).
Override this in your provider for more accurate counting.
High-level request with message conversion, telemetry, and error wrapping.
Default implementation that:
- Converts messages to provider format
- Builds request params
- Calls chat/2
- Parses response
- Emits telemetry events
- Wraps errors
High-level streaming request with message conversion and telemetry.