PHP code example of lzhx00 / laravel-llm-client
1. Go to this page and download the library: Download lzhx00/laravel-llm-client 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/ */
lzhx00 / laravel-llm-client example snippets
'providers' => [
// ...
Lzhx00\LLMClient\LLMClientServiceProvider::class,
],
'aliases' => [
// ...
'LLMClient' => Lzhx00\LLMClient\Facades\LLMClient::class,
],
return [
'default' => env('LLM_DEFAULT_PROVIDER', 'openai'),
'providers' => [
'openai' => [
'api_key' => env('OPENAI_API_KEY'),
'default_model' => 'gpt-3.5-turbo',
'embedding_model' => 'text-embedding-3-small',
'options' => [
'temperature' => 0.7,
// ...other OpenAI-specific options
],
],
'ollama' => [
'base_url' => env('OLLAMA_BASE_URL', 'http://localhost:11434'),
'default_model' => 'llama3',
'embedding_model' => 'nomic-embed-text',
'options' => [
'temperature' => 0.5,
// ...other Ollama-specific options
],
],
// ...other providers
],
];
$response = LLMClient::generate('Say hello in English.');
$response = LLMClient::use('ollama')->generate('Say hello in English.');
$response = LLMClient::model('llama3')->with(['temperature' => 0.5])->generate('Say hello.');
$vector = LLMClient::use('ollama')->embed('hello world');
// Specify embedding model
$vector = LLMClient::embedModel('nomic-embed-text')->embed('hello world');
LLMClient::generateStream('Tell me a joke.', [], function($chunk) {
echo $chunk;
});
$models = LLMClient::use('gemini')->models();
bash
php artisan vendor:publish --tag=llm-client-config