lmstudio

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

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

func New(endPoint, apiKey string, opts ...client.ClientOpt) (*Client, error)

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

func (c *Client) DeleteModel(context.Context, llm.Model) error

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

func (c *Client) GetModel(ctx context.Context, name string) (llm.Model, error)

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

func (c *Client) ListModels(ctx context.Context) ([]llm.Model, error)

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) Name

func (*Client) Name() string

Name returns the provider's name

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

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) Self

func (c *Client) Self() llm.Provider

Self returns the underlying client implementation

func (*Client) URL

func (c *Client) URL() *url.URL

URL returns the endpoint of the server's OpenAI-compatible API, such as "http://localhost:1234/v1"

func (*Client) UnloadModel

func (c *Client) UnloadModel(ctx context.Context, model llm.Model) error

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) Aliases

func (m *Model) Aliases() []string

Aliases returns no aliases, as LM Studio has none

func (*Model) Capabilities

func (m *Model) Capabilities() llm.ModelCap

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

func (m *Model) Created() time.Time

Created returns the zero time, as LM Studio doesn't say when a model was made

func (*Model) Description

func (m *Model) Description() string

Description returns the model's description, or its display name, such as "Gemma 4 12B QAT", when it has none

func (*Model) InputTokenLimit

func (m *Model) InputTokenLimit() *uint

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) Loaded

func (m *Model) Loaded() bool

Loaded returns whether the model is loaded, in memory

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

func (m *Model) Name() string

Name returns the model's name, which is its key, such as "google/gemma-4-12b-qat"

func (*Model) OutputTokenLimit

func (m *Model) OutputTokenLimit() *uint

OutputTokenLimit returns nil, as LM Studio doesn't say

func (*Model) Provider

func (m *Model) Provider() llm.Provider

Provider returns the client the model is from

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL