PHP code example of mpstenson / cloudflare-ai
1. Go to this page and download the library: Download mpstenson/cloudflare-ai 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/ */
mpstenson / cloudflare-ai example snippets
// config for mpstenson/CloudflareAI
return [
'api_url' => 'https://api.cloudflare.com/client/v4',
'account_id' => env('CLOUDFLARE_ACCOUNT_ID', ''),
'api_token' => env('CLOUDFLARE_API_TOKEN', ''),
'default_model' => env('CLOUDFLARE_DEFAULT_MODEL', 'meta/llama-3-8b-instruct'),
'default_speech_to_text_model' => env('CLOUDFLARE_DEFAULT_SPEECH_TO_TEXT_MODEL', 'openai/whisper'),
'default_image_classification_model' => env('CLOUDFLARE_DEFAULT_IMAGE_CLASSIFICATION_MODEL', 'microsoft/resnet-50'),
];
use mpstenson\CloudflareAI\CloudflareAI;
$response = CloudflareAI::runModel([
'messages' => [
['role' => 'system', 'content' => 'You are a friendly assistant'],
['role' => 'user', 'content' => 'Why is pizza so good'],
]
],'meta/llama-2-7b-chat-int8');
use mpstenson\CloudflareAI\CloudflareAI;
$whisper = CloudflareAI::runSpeechToText(fopen(storage_path().'/app/public/test.mp3', 'r'),'openai/whisper');
bash
php artisan vendor:publish --tag="cloudflare-ai-config"
CLOUDFLARE_DEFAULT_SPEECH_TO_TEXT_MODEL