PHP code example of wilfreedi / laravel-apifinder

1. Go to this page and download the library: Download wilfreedi/laravel-apifinder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wilfreedi / laravel-apifinder example snippets

 artisan vendor:publish --provider="Wilfreedi\ApiFinder\Providers\ApiFinderServiceProvider" --tag="config"

use Wilfreedi\ApiFinder\ApiFinderClient;

$baseUrl = 'https://apifinder.ru';
$apiToken = 'your_secure_bearer_token_here';
$timeout = 60; // опционально
$guzzleOptions = [ // опционально
    // 'proxy' => 'http://user:pass@host:port'
];

$client = new ApiFinderClient($baseUrl, $apiToken, $timeout, $guzzleOptions);

// Дальнейшее использование
$openaiService = $client->openAI();
// $deepseekService = $client->deepSeek();

use Wilfreedi\ApiFinder\Facades\ApiFinder;

// --- OpenAI Chat ---
try {
    $params = [
        'model'    => 'gpt-3.5-turbo',
        'messages' => [
            ['role' => 'user', 'content' => 'Hello!']
        ]
    ];
    $response = ApiFinder::openAI()->chat($params);
    print_r($response);
} catch (\Wilfreedi\ApiFinder\Exceptions\ApiException $e) {
    // Обработка ошибок API
    echo "API Error: " . $e->getMessage() . " (Status: " . $e->getCode() . ")\n";
}

// --- OpenAI Transcribe ---
try {
    $filePath = '/path/to/your/audio.mp3';
    $params = [
        'model'    => 'whisper-1',
        'language' => 'en' // опционально
    ];
    $response = ApiFinder::openAI()->transcribe($filePath, basename($filePath), $params);
    echo "Transcription: " . $response['text'] . "\n";
} catch (\Wilfreedi\ApiFinder\Exceptions\ApiException $e) {
    // Обработка ошибок
     echo "API Error: " . $e->getMessage() . " (Status: " . $e->getCode() . ")\n";
} catch (\InvalidArgumentException $e) {
     // Ошибка файла
     echo "File Error: " . $e->getMessage() . "\n";
}

use Illuminate\Http\Request;
use Wilfreedi\ApiFinder\ApiFinderClient;
use Wilfreedi\ApiFinder\Services\OpenAIService; // Если внедрять напрямую

class SomeController
{
    protected ApiFinderClient $apiFinderClient;
    // Или protected OpenAIService $openaiService;

    public function __construct(ApiFinderClient $apiFinderClient /* или OpenAIService $openaiService */) {
        $this->apiFinderClient = $apiFinderClient;
        // $this->openaiService = $openaiService;
    }

    public function handleOpenAI(Request $request) {
        $openaiService = $this->apiFinderClient->openAI();
        try {
            $response = $openaiService->chat($request->input('params'));
            // ...
        } catch (\Wilfreedi\ApiFinder\Exceptions\ApiException $e) {
            // ...
        }
    }
}