fgdumitru/viceroy
最新稳定版本:1.0.13
Composer 安装命令:
composer require fgdumitru/viceroy
包简介
Viceroy: An LLM interactions library with an OpenAI compatible completion endpoint via PHP.
关键字:
README 文档
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
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-17