idpromogroup/laravel-openai-responses
Composer 安装命令:
composer require idpromogroup/laravel-openai-responses
包简介
Laravel package for standardizing OpenAI API responses
README 文档
README
A Laravel package for standardizing OpenAI API responses in your applications.
Installation
composer require idpromogroup/laravel-openai-responses
Usage
Basic Usage
use Idpromogroup\LaravelOpenaiResponses\Services\LorService; $service = new LorService($externalKey, 'Your message here'); $result = $service->setModel('gpt-4o-mini') ->setInstructions('You are a helpful assistant') ->execute(); if ($result->success) { echo $result->data; }
Working with Files
The package supports file attachments for analysis, processing, and discussion:
Supported file types:
- Images: JPG, PNG, WEBP
- Documents: PDF only
File type restrictions:
- Only images (JPG/PNG/WEBP) and PDF files are accepted
- Unsupported formats will be rejected with error message
Upload and Attach Local Files
$service = new LorService($externalKey, 'Analyze this document') ->setModel('gpt-4o-mini') ->attachLocalFile(storage_path('app/documents/report.pdf')); $result = $service->execute();
Attach Already Uploaded Files
// Upload file first $apiService = app(LorApiService::class); $uploadResult = $apiService->uploadFile('/path/to/file.pdf', 'assistants'); $fileId = $uploadResult['id']; // Then attach to conversation $service = new LorService($externalKey, 'Discuss this file') ->attachFile($fileId) ->execute();
Attach Multiple Files
$service = new LorService($externalKey, 'Compare these documents') ->attachFileIds(['file_123', 'file_456']) ->attachLocalFile(storage_path('app/contract.docx')) ->execute();
Custom Tools for File Processing
$service = new LorService($externalKey, 'Extract data from spreadsheet') ->attachFile($fileId) ->execute();
Note:
- Images are sent as
input_imagetype to OpenAI - PDF files are sent as
input_filetype to OpenAI - Unsupported file formats will be rejected immediately
Using Templates
$service = new LorService($externalKey, 'Your message') ->useTemplate('analysis_template') // by name ->execute(); // Or by ID $service->useTemplate(1);
Conversation Mode
$service = new LorService($externalKey, 'Hello') ->setConversation('user123') ->execute(); // Subsequent messages will continue the conversation $service = new LorService($externalKey, 'Follow up question') ->setConversation('user123') ->execute();
Function Calls
Configure function handler in config/openai-responses.php:
'function_handler' => App\Services\MyFunctionHandler::class,
Your handler should implement the execute method:
class MyFunctionHandler { public function execute(string $functionName, array $args) { switch ($functionName) { case 'get_weather': return $this->getWeather($args['location']); default: return ['error' => 'Unknown function']; } } }
Advanced Configuration
$service = new LorService($externalKey, 'Your message') ->setModel('gpt-4o-mini') ->setInstructions('Custom instructions') ->setTemperature(0.7) ->setTools([ ['type' => 'function', 'function' => [...]] ]) ->setJSONSchema([ 'type' => 'object', 'properties' => [...] ]) ->execute();
File Upload API
Direct file upload to OpenAI:
use Idpromogroup\LaravelOpenaiResponses\Services\LorApiService; $apiService = new LorApiService(); $result = $apiService->uploadFile('/path/to/file.pdf', 'assistants'); if ($result) { $fileId = $result['id']; // Use $fileId in subsequent requests }
Supported file purposes:
assistants(default) - for Assistant APIfine-tune- for fine-tuningbatch- for batch processing
License
MIT License
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-14