lmstudio

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: None detected not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package lmstudio 实现 LM Studio 本地模型服务的 ModelProvider.

LM Studio 提供 GUI 界面管理本地 LLM,并内置 OpenAI 兼容 API 服务器. 与 Ollama 不同,LM Studio 使用标准的 OpenAI /v1/models 端点, 同时也支持 /v1/chat/completions 流式请求.

两者对比:

  • Ollama:命令行管理,/api/tags 端点,更适合服务器场景
  • LM Studio:GUI 管理,/v1/models 端点,更适合桌面开发场景

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BaseURL 是 LM Studio 本地 API 服务器地址(默认 http://localhost:1234).
	BaseURL string

	// HTTPClient 注入自定义 HTTP 客户端.
	// nil = 使用默认 http.Client (带 Timeout 字段配置的 ResponseHeaderTimeout).
	// 非 nil 时 consumer 完全接管超时责任, 下面的 Timeout 字段被忽略.
	HTTPClient *http.Client

	// Timeout 限制"从请求发出到收到响应首字节"的时间.
	//
	// 通过 http.Transport.ResponseHeaderTimeout 实现, **不影响** SSE 流式 body 读取.
	// 精妙之处(CLEVER): 不要误用 http.Client.Timeout - 会砍死 SSE 流.
	//
	// 0 = 使用 defaultTimeout (300s, 适合本地推理冷启动).
	// 与 ollama 一致: 本地模型 load + warm-up 可能耗时 30-60s.
	// 仅当 HTTPClient 为 nil 时生效; 提供自定义 HTTPClient 时此字段被忽略.
	Timeout time.Duration
}

Config 是 LM Studio provider 的配置.

func (Config) GoString

func (c Config) GoString() string

GoString 实现 fmt.GoStringer,防止 %#v 打印时意外暴露配置详情. 升华改进(ELEVATED): LM Studio 本地部署无 APIKey,BaseURL 暴露内网地址也应避免.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider 是 LM Studio ModelProvider 实现.

func New

func New(cfg Config) *Provider

New 创建 LM Studio ModelProvider.

func (*Provider) Models

func (p *Provider) Models(ctx context.Context) ([]flyto.ModelInfo, error)

Models 从 LM Studio /v1/models 端点获取当前加载的模型列表.

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req *flyto.Request) (<-chan flyto.Event, error)

Jump to

Keyboard shortcuts

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