mahmoudnaggar/laravel-lmstudio
Composer 安装命令:
composer require mahmoudnaggar/laravel-lmstudio
包简介
Advanced LM Studio integration for Laravel - Run local LLMs with OpenAI-compatible API, model management, streaming, embeddings, and more
关键字:
README 文档
README
Advanced LM Studio integration for Laravel - Run powerful local LLMs with a clean, Laravel-friendly API. Perfect for privacy-focused AI applications, offline development, and cost-effective AI solutions.
🚀 Features
- ✅ OpenAI-Compatible API - Drop-in replacement for OpenAI with local models
- ✅ Model Management - List, load, and switch between models programmatically
- ✅ Streaming Support - Real-time token streaming for chat responses
- ✅ Embeddings - Generate vector embeddings for semantic search
- ✅ Conversation Management - Maintain context across multiple messages
- ✅ Health Monitoring - Check LM Studio server status and loaded models
- ✅ Token Counting - Estimate and track token usage
- ✅ Artisan Commands - CLI tools for model management and testing
- ✅ Comprehensive Testing - Full test suite included
- ✅ Laravel 10 & 11 - Full support for latest Laravel versions
📋 Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
- LM Studio installed and running
- LM Studio local server enabled (default:
http://localhost:1234)
📦 Installation
Install the package via Composer:
composer require mahmoudnaggar/laravel-lmstudio
Publish the configuration file:
php artisan vendor:publish --tag=lmstudio-config
⚙️ Configuration
Update your .env file:
LMSTUDIO_BASE_URL=http://localhost:1234/v1 LMSTUDIO_TIMEOUT=120 LMSTUDIO_DEFAULT_MODEL=llama-3.2-3b-instruct LMSTUDIO_MAX_TOKENS=2048 LMSTUDIO_TEMPERATURE=0.7
The configuration file (config/lmstudio.php) provides extensive customization options.
🎯 Quick Start
Basic Chat
use MahmoudNaggar\LaravelLMStudio\Facades\LMStudio; // Simple chat $response = LMStudio::chat('What is Laravel?'); echo $response->content(); // With options $response = LMStudio::chat('Explain quantum computing', [ 'model' => 'llama-3.2-3b-instruct', 'temperature' => 0.8, 'max_tokens' => 500, ]);
Streaming Responses
LMStudio::stream('Write a story about AI', function ($chunk) { echo $chunk; // Output each token as it arrives });
Conversations
$conversation = LMStudio::conversation(); $conversation->addMessage('user', 'Hello! My name is John.'); $response1 = $conversation->send(); $conversation->addMessage('user', 'What is my name?'); $response2 = $conversation->send(); // Will remember "John"
Embeddings
$embedding = LMStudio::embedding('Laravel is a PHP framework'); $vector = $embedding->vector(); // Array of floats $dimensions = $embedding->dimensions(); // 384, 768, etc.
Model Management
// List available models $models = LMStudio::models()->list(); // Get loaded model $currentModel = LMStudio::models()->loaded(); // Load a specific model LMStudio::models()->load('mistral-7b-instruct'); // Unload current model LMStudio::models()->unload();
Health Checks
// Check if LM Studio is running if (LMStudio::health()->isHealthy()) { echo "LM Studio is running!"; } // Get detailed status $status = LMStudio::health()->status(); echo "Server: " . $status['server']; echo "Model: " . $status['model'];
🛠️ Artisan Commands
List Models
php artisan lmstudio:models
Test Connection
php artisan lmstudio:test
Chat from CLI
php artisan lmstudio:chat "What is the meaning of life?"
Load Model
php artisan lmstudio:load mistral-7b-instruct
📚 Advanced Usage
Custom System Prompts
$response = LMStudio::chat('Hello', [ 'system' => 'You are a helpful coding assistant specializing in Laravel.', ]);
Function Calling (Tool Use)
$response = LMStudio::chat('What is the weather in Paris?', [ 'tools' => [ [ 'type' => 'function', 'function' => [ 'name' => 'get_weather', 'description' => 'Get current weather', 'parameters' => [ 'type' => 'object', 'properties' => [ 'location' => ['type' => 'string'], ], ], ], ], ], ]); if ($response->hasToolCalls()) { $toolCalls = $response->toolCalls(); // Process tool calls... }
Token Counting
$text = "This is a sample text"; $tokens = LMStudio::countTokens($text); if (LMStudio::withinTokenLimit($text, 1000)) { // Process the text }
Batch Processing
$prompts = ['Question 1', 'Question 2', 'Question 3']; $responses = collect($prompts)->map(function ($prompt) { return LMStudio::chat($prompt); });
Error Handling
use MahmoudNaggar\LaravelLMStudio\Exceptions\LMStudioException; try { $response = LMStudio::chat('Hello'); } catch (LMStudioException $e) { Log::error('LM Studio error: ' . $e->getMessage()); // Fallback logic }
🧪 Testing
Run the test suite:
composer test
Run code formatting:
composer format
📖 Documentation
For detailed documentation, visit the Wiki.
🤝 Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
🔒 Security
If you discover any security-related issues, please email mahmoud@example.com instead of using the issue tracker.
📄 License
The MIT License (MIT). Please see License File for more information.
🙏 Credits
🌟 Show Your Support
If this package helps you, please consider giving it a ⭐️ on GitHub!
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ for the Laravel community
mahmoudnaggar/laravel-lmstudio 适用场景与选型建议
mahmoudnaggar/laravel-lmstudio 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「streaming」 「laravel」 「ai」 「machine-learning」 「llama」 「embeddings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mahmoudnaggar/laravel-lmstudio 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mahmoudnaggar/laravel-lmstudio 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mahmoudnaggar/laravel-lmstudio 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A laravel bundle for the OpenTok PHP SDK
Laravel Wrapper for the OpenTok PHP SDK
A robust, configuration-driven ETL and data import framework for Laravel. Handles CSV/Excel streaming, queues, validation, and relationships.
Simple PHP client for Qdrant vector database. Easy-to-use library for storing, searching, and managing vector embeddings in AI and machine learning applications.
#1 PHP client for the Replicate API, compatible with Laravel and native PHP, built on Saloon v4
🚀 GigaChat PHP SDK - полнофункциональная библиотека для интеграции с Sber GigaChat API. Простое подключение GigaChat к PHP-приложениям с поддержкой Laravel. Генерация текста, чат-боты, AI-ассистенты. Полная документация, примеры кода, OAuth авторизация.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-24