{"id":42201564,"url":"https://github.com/hypernetix/lmstudio-go","last_synced_at":"2026-01-27T00:26:23.968Z","repository":{"id":291233980,"uuid":"974480035","full_name":"hypernetix/lmstudio-go","owner":"hypernetix","description":"Go SDK and CLI for LM Studio: manage, interact, and run LLMs via WebSocket API","archived":false,"fork":false,"pushed_at":"2025-09-08T15:27:36.000Z","size":131,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-08T17:29:47.449Z","etag":null,"topics":["cli","go","golang","llm","lmstudio","machine-learning","open-source","sdk","sdk-go","sdk-golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hypernetix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-28T21:01:50.000Z","updated_at":"2025-09-08T15:31:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"224e793c-c615-4128-9f3e-4bb7925c6ac0","html_url":"https://github.com/hypernetix/lmstudio-go","commit_stats":null,"previous_names":["hypernetix/lmstudio-go"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/hypernetix/lmstudio-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypernetix%2Flmstudio-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypernetix%2Flmstudio-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypernetix%2Flmstudio-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypernetix%2Flmstudio-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypernetix","download_url":"https://codeload.github.com/hypernetix/lmstudio-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypernetix%2Flmstudio-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28792987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T21:49:50.245Z","status":"ssl_error","status_checked_at":"2026-01-26T21:48:29.455Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","go","golang","llm","lmstudio","machine-learning","open-source","sdk","sdk-go","sdk-golang"],"created_at":"2026-01-27T00:26:23.160Z","updated_at":"2026-01-27T00:26:23.957Z","avatar_url":"https://github.com/hypernetix.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LM Studio Go\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/hypernetix/lmstudio-go)](https://goreportcard.com/report/github.com/hypernetix/lmstudio-go)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![GitHub issues](https://img.shields.io/github/issues/Dynaval81/lmstudio-go.svg)](https://github.com/hypernetix/lmstudio-go/issues)\n[![GitHub stars](https://img.shields.io/github/stars/Dynaval81/lmstudio-go.svg)](https://github.com/hypernetix/lmstudio-go/stargazers)\n\n**LM Studio Go** is an open-source Go SDK and CLI for managing and interacting with Large Language Models (LLMs) via [LM Studio](https://lmstudio.ai)'s WebSocket API.\nEasily load, manage, and chat with LLMs in your Go applications or from the command line.\n\n\u003e Inspired by [lmstudio-python](https://github.com/lmstudio-ai/lmstudio-python).\n\n\n## Motivation\n\nLM Studio is a great tool for interacting with LLMs and it has REST API for chatting, models management and more. However, this API is incomplete and is still in Beta, for example it doesn't yet support:\n\n- Advanced model details (size, path, etc)\n- Model loading and unloading progress\n- Server management (start, stop, etc)\n\n\n## Overview\n\nThis library provides Go bindings for LM Studio, allowing you to interact with LM Studio's WebSocket API from Go applications. It supports:\n\n- Status check to verify if the LM Studio service is running\n- Version reporting (version 1.0)\n- Model management:\n  - Listing loaded LLM models\n  - Listing loaded embedding models\n  - Listing all loaded models (LLMs and embeddings)\n  - Listing downloaded models\n  - Loading specific models with progress reporting and cancellation support\n  - Unloading specific models\n  - Unloading all loaded models\n- Sending prompts to models with streaming responses\n- Configurable logging with multiple log levels\n- **Advanced model loading features:**\n  - Real-time progress reporting with model information (size, format)\n  - Graceful cancellation support (Ctrl+C or context cancellation)\n  - Configurable timeouts for large model loading operations\n  - Progress bars and visual feedback in CLI\n- **CLI enhancements:**\n  - Quiet mode for automation and scripting\n  - Timeout configuration for model operations\n  - Enhanced error handling and user feedback\n\n\n## Installation\n\n```bash\ngo get github.com/hypernetix/lmstudio-go\n```\n\n\n## Library Usage\n\n### Basic Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/hypernetix/lmstudio-go/pkg/lmstudio\"\n)\n\nfunc main() {\n\t// Create a logger with desired verbosity\n\tlogger := lmstudio.NewLogger(lmstudio.LogLevelInfo)\n\n\t// Create an LM Studio client\n\tclient := lmstudio.NewLMStudioClient(\"localhost:1234\", logger)\n\tdefer client.Close()\n\n\t// List all loaded models\n\tmodels, err := client.ListLoadedLLMs()\n\tif err != nil {\n\t\tlogger.Error(\"Failed to list loaded models: %v\", err)\n\t\treturn\n\t}\n\n\t// Print the models\n\tfmt.Println(\"Loaded models:\")\n\tfor _, model := range models {\n\t\tfmt.Printf(\"- %s\\n\", model.Identifier)\n\t}\n\n\t// Load a model if none is loaded\n\tif len(models) == 0 {\n\t\tdownloaded, err := client.ListDownloadedModels()\n\t\tif err != nil || len(downloaded) == 0 {\n\t\t\tlogger.Error(\"No models available\")\n\t\t\treturn\n\t\t}\n\n\t\tmodelToLoad := downloaded[0].ModelKey\n\t\tfmt.Printf(\"Loading model: %s\\n\", modelToLoad)\n\t\tif err := client.LoadModel(modelToLoad); err != nil {\n\t\t\tlogger.Error(\"Failed to load model: %v\", err)\n\t\t\treturn\n\t\t}\n\n\t\t// Update the models list\n\t\tmodels, _ = client.ListLoadedLLMs()\n\t}\n\n\t// Send a prompt to the first loaded model\n\tif len(models) \u003e 0 {\n\t\tmodelID := models[0].Identifier\n\t\tprompt := \"Tell me a short joke\"\n\n\t\tfmt.Printf(\"\\nSending prompt to %s: %s\\n\\nResponse:\\n\", modelID, prompt)\n\n\t\t// Create a callback to print tokens as they arrive\n\t\tcallback := func(token string) {\n\t\t\tfmt.Print(token)\n\t\t}\n\n\t\tif err := client.SendPrompt(modelID, prompt, 0.7, callback); err != nil {\n\t\t\tlogger.Error(\"Failed to send prompt: %v\", err)\n\t\t}\n\t\tfmt.Println(\"\\n\")\n\t}\n}\n```\n\n### Custom Logger\n\nYou can implement your own logger by implementing the `lmstudio.Logger` interface:\n\n```go\ntype MyLogger struct {\n\tlevel lmstudio.LogLevel\n}\n\nfunc (l *MyLogger) SetLevel(level lmstudio.LogLevel) {\n\tl.level = level\n}\n\nfunc (l *MyLogger) Error(format string, v ...interface{}) {\n\t// Your custom error logging implementation\n}\n\n// Implement other required methods: Warn, Info, Debug, Trace\n\n// Then use it with the client\nclient := lmstudio.NewLMStudioClient(\"localhost:1234\", \u0026MyLogger{level: lmstudio.LogLevelDebug})\n```\n\n\n## CLI Usage\n\nThe project includes a command-line interface for interacting with LM Studio:\n\n### Basic Commands\n\n```bash\n# Check if LM Studio service is running\nlms-go --status\n\n# Display version information\nlms-go --version\n\n# List all loaded models\nlms-go --list\n\n# List loaded LLM models\nlms-go --list-llms\n\n# List loaded embedding models\nlms-go --list-embeddings\n\n# List downloaded models\nlms-go --list-downloaded\n\n# Load a model with progress bar\nlms-go --load=\"mistral-7b-instruct\"\n\n# Load a model with custom timeout (default: 30s)\nlms-go --timeout=60s --load=\"large-model-70b\"\n\n# Unload a model\nlms-go --unload=\"mistral-7b-instruct\"\n\n# Unload all loaded models\nlms-go --unload-all\n\n# Send a prompt to a model\nlms-go --model=\"mistral-7b-instruct\" --prompt=\"Tell me a joke\" --temp=0.7\n\n# Enable verbose logging\nlms-go -v\n\n# Enable quiet mode (suppress informational output)\nlms-go --quiet --load=\"model-name\"\nlms-go -q --list\n\n# Wait for Ctrl+C to exit (useful for keeping the program running)\nlms-go --wait\n```\n\n### Advanced Options\n\n```bash\n# Timeout Options\n--timeout=30s              # Set timeout for model loading operations (default: 30s)\n--timeout=2m               # Use minutes\n--timeout=120s             # Use seconds\n\n# Output Control\n-q, --quiet                # Suppress informational messages (JSON output and errors still shown)\n-v                         # Enable verbose logging\n\n# Model Loading Features\n# - Real-time progress bar with percentage and visual indicators\n# - Model size and format information display\n# - Graceful cancellation with Ctrl+C\n# - Timeout handling with clear error messages\n```\n\n### Model Loading with Progress\n\nWhen loading models, the CLI displays a detailed progress bar:\n\n```\nLoading model \"mistral-7b-instruct\" (size: 4.1 GB, format: safetensors) ...\nModel: 4.1 GB (safetensors)\n: [████████████████████████████████████████████████] 100.00%\n✓ Model loaded successfully\n```\n\n**Features:**\n- Real-time progress updates with percentage\n- Visual progress bar using block characters\n- Model size and format information\n- **Cancellation support**: Press `Ctrl+C` to gracefully cancel loading\n- **Timeout handling**: Use `--timeout` to set custom timeouts for large models\n\n### Quiet Mode\n\nUse quiet mode (`-q` or `--quiet`) for automation and scripting:\n\n```bash\n# Regular output with progress and messages\nlms-go --load=\"model-name\"\n\n# Quiet mode - only essential output\nlms-go --quiet --load=\"model-name\"\n\n# In quiet mode, you still get:\n# - JSON output for --list commands\n# - Error messages\n# - Actual prompt responses\n# But informational messages and progress bars are suppressed\n```\n\n\n## API Reference\n\n### Client Initialization\n\n```go\n// Create a new client with default logger\nclient := lmstudio.NewLMStudioClient(\"localhost:1234\", nil)\n\n// Create a new client with custom logger and log level\nlogger := lmstudio.NewLogger(lmstudio.LogLevelDebug)\nclient := lmstudio.NewLMStudioClient(\"localhost:1234\", logger)\n```\n\n### Model Management\n\n```go\n// List loaded LLM models\nmodels, err := client.ListLoadedLLMs()\n\n// List loaded embedding models\nmodels, err := client.ListLoadedEmbeddingModels()\n\n// List all loaded models (LLMs and embeddings)\nmodels, err := client.ListAllLoadedModels()\n\n// List downloaded models\nmodels, err := client.ListDownloadedModels()\n\n// Load a model (basic)\nerr := client.LoadModel(\"mistral-7b-instruct\")\n\n// Load a model with progress reporting and timeout\nerr := client.LoadModelWithProgress(30*time.Second, \"mistral-7b-instruct\", func(progress float64, modelInfo *lmstudio.Model) {\n    if modelInfo != nil {\n        fmt.Printf(\"Loading %s (%.1f GB)...\\n\", modelInfo.ModelName, float64(modelInfo.SizeBytes)/(1024*1024*1024))\n    }\n    fmt.Printf(\"Progress: %.1f%%\\n\", progress*100)\n})\n\n// Load a model with progress reporting and cancellation support\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\n\nerr := client.LoadModelWithProgressContext(ctx, 30*time.Second, \"mistral-7b-instruct\", func(progress float64, modelInfo *lmstudio.Model) {\n    // Handle progress updates\n    fmt.Printf(\"Progress: %.1f%%\\n\", progress*100)\n})\n\n// Cancel loading by calling cancel() or using Ctrl+C signal handling\n\n// Unload a model\nerr := client.UnloadModel(\"mistral-7b-instruct\")\n\n// Unload all loaded models\nerr := client.UnloadAllModels()\n```\n\n### Inference\n\n```go\n// Send a prompt with streaming response\ncallback := func(token string) {\n    fmt.Print(token)\n}\nerr := client.SendPrompt(\"mistral-7b-instruct\", \"Tell me a joke\", 0.7, callback)\n```\n\n### Service Status\n\n```go\n// Check if LM Studio service is running\nrunning, err := client.IsServiceRunning()\nif running {\n    fmt.Println(\"LM Studio service is running\")\n} else {\n    fmt.Println(\"LM Studio service is NOT running\")\n}\n```\n\n### Cleanup\n\n```go\n// Close the client and all connections\nclient.Close()\n```\n\n\n## Project Structure\n\n- `main.go`: example of CLI executable entry point\n- `pkg/lmstudio/`: Library package code\n  - `lmstudio_client.go`: Main client implementation\n  - `conn.go`: Namespace connection and WebSocket management\n  - `model_loading.go`: Model loading channel and related logic\n  - `chat_streaming.go`: Streaming chat/channel logic\n  - `logger.go`: Logging abstraction with multiple log levels\n  - `types.go`: Data types (e.g., `Model`, `ChatMessage`, etc.)\n  - `params.go`: Parameter structures for API calls\n\n\n## Testing\n\n```bash\nmake test\n```\n\n## Using the Makefile\n\nThe project includes a Makefile to simplify common development tasks:\n\n```bash\n# Run tests, generate coverage report, and build the binary\nmake all\n\n# Run all the tests\nmake tests\n\n# Run only the unit tests\nmake unit-tests\n\n# Run only the CLI tests\nmake cli-tests\n\n# Generate code coverage reports\nmake coverage\n\n# Build the CLI executable (outputs to build/lms-go)\nmake build\n\n# Install the CLI executable to your Go bin directory\nmake install\n\n# Clean up build artifacts and coverage files\nmake clean\n```\n## License\n\nThis project is licensed under the [Apache 2.0 License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypernetix%2Flmstudio-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypernetix%2Flmstudio-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypernetix%2Flmstudio-go/lists"}