Documentation
¶
Overview ¶
lmstudio implements an API client for LM Studio, which runs models on your own computer. It replies, and embeds, with LM Studio's OpenAI-compatible API, and lists, downloads, loads and unloads models with its own REST API, which says what each model can do, and how much context it has. https://lmstudio.ai/docs/developer/rest
Index ¶
- Constants
- type Client
- func (c *Client) DeleteModel(context.Context, llm.Model) error
- func (c *Client) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) ([]llm.Vector, llm.Usage, error)
- func (c *Client) GetModel(ctx context.Context, name string) (llm.Model, error)
- func (c *Client) ListModels(ctx context.Context) ([]llm.Model, error)
- func (c *Client) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (llm.Model, error)
- func (*Client) Name() string
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (llm.Document, llm.Usage, error)
- func (c *Client) Self() llm.Provider
- func (c *Client) URL() *url.URL
- func (c *Client) UnloadModel(ctx context.Context, model llm.Model) error
- func (c *Client) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, ...) (llm.Message, llm.Usage, error)
- type Model
- func (m *Model) Aliases() []string
- func (m *Model) Capabilities() llm.ModelCap
- func (m *Model) Created() time.Time
- func (m *Model) Description() string
- func (m *Model) InputTokenLimit() *uint
- func (m *Model) Loaded() bool
- func (m *Model) Meta() map[string]json.RawMessage
- func (m *Model) Name() string
- func (m *Model) OutputTokenLimit() *uint
- func (m *Model) Provider() llm.Provider
Constants ¶
const DefaultEndpoint = "http://localhost:1234/v1"
DefaultEndpoint is the endpoint of LM Studio's server, on your own computer, unless it's told to listen on another port
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a client of an LM Studio server, with its own REST API, and the client of its OpenAI-compatible API, which replies, and embeds
func New ¶
New returns a client of the LM Studio server at the endpoint, which is its OpenAI-compatible API's, such as "http://localhost:1234/v1", the default, or the server's, such as "localhost:1234", and an API token, which LM Studio needs only when it's told to, which is sent as a bearer token
func (*Client) DeleteModel ¶
DeleteModel returns ErrNotImplemented, as LM Studio's API doesn't delete models, which are deleted in LM Studio
func (*Client) Embed ¶
func (c *Client) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) ([]llm.Vector, llm.Usage, error)
Embed returns a vector for each of the messages, which must be for an embedding model of this client, with LM Studio's OpenAI-compatible embeddings API, as the OpenAI provider does
func (*Client) GetModel ¶
GetModel returns the model with the name, which is found in the list of models, as LM Studio doesn't get a model by its name
func (*Client) ListModels ¶
ListModels returns the models which are stored on the server
func (*Client) LoadModel ¶
func (c *Client) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (llm.Model, error)
LoadModel downloads the model with the name, when it isn't stored, which is a model of LM Studio's catalog, such as "google/gemma-4-12b-qat", or a Hugging Face link, and loads it, in memory, unless it's loaded already, with LM Studio's settings, such as its context length, and returns it. The progress function, if not nil, is called with the status of the download, and the percentage of its bytes downloaded, as it progresses, and as the model is loaded. Neither is timed out, as models can be large, but both are cancelled with the context.
func (*Client) Ping ¶
Ping checks the server can be reached, and that the API token, when it needs one, is accepted, by listing its models
func (*Client) Recognize ¶
func (c *Client) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (llm.Document, llm.Usage, error)
Recognize returns the text in the image, which is one page, in Markdown, and the tokens used, and the page. The model must be an LM Studio model which sees images, such as an OCR model, such as olmOCR, which is asked with the prompt it's trained on, or another, which is asked to convert the image to Markdown. It's asked with LM Studio's OpenAI-compatible Chat Completions API, as models read images, not documents, so a PDF isn't recognized. An image should be large enough for its text to be read, such as 1288 pixels on its longest side, as olmOCR's pages are. Regions aren't recognized. The request isn't timed out, as a model can take a while to load, but is cancelled with the context.
func (*Client) URL ¶
URL returns the endpoint of the server's OpenAI-compatible API, such as "http://localhost:1234/v1"
func (*Client) UnloadModel ¶
UnloadModel unloads the model, which must be an LM Studio model, from the server's memory, keeping it stored, which is every instance of it which is loaded, so it's loaded again when it's next used, when LM Studio is set to load models as they're needed
func (*Client) WithoutSession ¶
func (c *Client) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (llm.Message, llm.Usage, error)
WithoutSession returns the model's reply to the messages, which must be for a model of this client, and the tokens used, with LM Studio's OpenAI-compatible Chat Completions API, as the OpenAI provider does, with its thinking, and its effort, as the model reasons. A model which isn't loaded is loaded as it's asked, when LM Studio is set to load models as they're needed.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is a model of an LM Studio server, which is stored on it, and may be loaded, in memory
func (*Model) Capabilities ¶
Capabilities returns what the model can do: a language model replies, and calls tools, when it was trained to, sees images, when it has vision, thinks, when it reasons, and recognizes text, when it's an OCR model, such as olmOCR, and an embedding model embeds. A model which replies is only sent images, as the chat completions API which it replies with has no audio, video, or documents.
func (*Model) Created ¶
Created returns the zero time, as LM Studio doesn't say when a model was made
func (*Model) Description ¶
Description returns the model's description, or its display name, such as "Gemma 4 12B QAT", when it has none
func (*Model) InputTokenLimit ¶
InputTokenLimit returns the model's context length, which is the one it was loaded with, when it's loaded, as LM Studio sets it as it's loaded, and otherwise the most it can have
func (*Model) Meta ¶
func (m *Model) Meta() map[string]json.RawMessage
Meta returns what LM Studio says of the model, such as its publisher, architecture, quantization, size, and the instances of it which are loaded, apart from its key
func (*Model) Name ¶
Name returns the model's name, which is its key, such as "google/gemma-4-12b-qat"
func (*Model) OutputTokenLimit ¶
OutputTokenLimit returns nil, as LM Studio doesn't say