fgdumitru / viceroy
Viceroy: An LLM interactions library with an OpenAI compatible completion endpoint via PHP.
Installs: 56
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/fgdumitru/viceroy
Requires
- php: >=8.1
- ext-dom: *
- guzzlehttp/guzzle: ^7.10
- league/commonmark: ^2.7
- league/html-to-markdown: ^5.1
- pixel418/markdownify: ^2.3
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2025-11-10 05:42:37 UTC
README
Table of Contents
Installation
composer require viceroy/llm-library
Basic Usage
use Viceroy\Configuration\ConfigObjects; use Viceroy\Configuration\ConfigManager; use Viceroy\Connections\Definitions\OpenAICompatibleEndpointConnection; // Initialize configuration $config = new ConfigObjects('config.json'); $configManager = new ConfigManager($config); // Create connection $connection = new OpenAICompatibleEndpointConnection($config); $connection->setSystemMessage("You are a helpful assistant.") ->setParameter('temperature', 0.7) ->setParameter('top_p', 0.9); // Send query $response = $connection->query("Explain quantum physics"); // Handle response if ($response->wasStreamed()) { echo "Streamed response received"; } else { echo $response->getLlmResponse(); echo "\nThink content: " . $response->getThinkContent(); }
Features
- Dynamic function chaining
- Custom configuration inheritance
- Multi-turn conversation support
- Vision capabilities
Image Processing Examples
use Viceroy\Connections\Definitions\OpenAICompatibleEndpointConnection; // describe_image.php $imagePath = 'examples/images/ocr.png'; $imageData = base64_encode(file_get_contents($imagePath)); $response = $connection->query("Describe this image", [ 'vision' => true, 'image' => $imageData, 'max_tokens' => 500 ]); echo $response->getLlmResponse();
Available images:
- Document analysis:
/examples/images/image_1.jpg - Diagram parsing:
/examples/images/image_2.jpg - OCR demonstration:
/examples/images/ocr.png
Advanced Capabilities
Dynamic Function Chaining
use Viceroy\Connections\Definitions\OpenAICompatibleEndpointConnection; $connection->enableFunctionCalling() ->registerFunction('get_weather', 'Retrieves weather data') ->query("What's the weather in Berlin?");
Custom Configuration
use Viceroy\Configuration\ConfigObjects; $customConfig = [ 'endpoint' => 'https://api.example.com/v1', 'timeout' => 30, 'vision_support' => true, 'model_mappings' => [ 'gpt-4' => 'company-llm-v4' ] ];
License
MIT License
Copyright (c) 2024 Viceroy Project