1. Go to this page and download the library: Download llm-speak/core 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/ */
llm-speak / core example snippets
use LLMSpeak\Core\NeuralModels\CompletionsModel;
class SomeModel extends CompletionsModel
{
// Optional: override the default provider/model from config
protected string $connection = 'oaic';
protected string $model_id = 'gpt-3.5-turbo-instruct';
}
use LLMSpeak\Core\NeuralModels\InferenceModel;
class SomeModel extends InferenceModel
{
// Optional: override the default provider/model from config
protected string $connection = 'oaic';
protected string $model_id = 'gpt-3.5-turbo-instruct';
}
use LLMSpeak\Core\NeuralModels\EmbeddingsModel;
class SomeModel extends EmbeddingsModel
{
// Optional: override the default provider/model from config
protected string $connection = 'oaic';
protected string $model_id = 'text-embedding-ada-002';
}
use LLMSpeak\Core\NeuralModels\TokenizationModel;
class SomeTokenizerModel extends TokenizationModel
{
// Optional: override the default provider/model from config
protected string $connection = 'x-ai';
protected string $model_id = 'grok-4-0709';
}
use App\NeuralModels\Embeddings\OllamaEmbeddingsModel;
// Start tokenization query
$model = new OneShotModel();
// Build prompts
$query = $model->where('prompt', 'Why is the sky blue?');
$query = $model->wherePrompt('Why is the sky blue?');
$query = $model->whereIn('prompt', ['Why is the sky blue?', 'What is Rayleigh scattering?']);
$query = $model->wherePrompt('Why is the sky blue?')->wherePrompt('What is Rayleigh scattering?');
// Execute
$modelCollection = $model->get(); // Collection of models (responses)
$tokensModel = $model->first(); // Single model (latest response)
$modelCollection = (new Chatmodel())
->where('message', 'Why is the sky blue?')
->get();
$model = (new Chatmodel())
->where('message', 'Why is the sky blue?')
->first();
$query = (new Chatmodel())->newQuery();
$query = $query->where('message', 'Why is the sky blue?');
$modelCollection = $query->get();
$model = (new Chatmodel())
->where('message', 'Why is the sky blue?')
->whereTemperature(0.7) // Set temperature that controls randomness
->first();
// Max tokens to use in response
$model->whereMaxTokens($max_tokens);
// Penalize new tokens based on their existing frequency in the text so far
$model->whereFrequencyPenalty($frequency_penalty);
// Penalize new tokens based on whether they appear in the text so far
$model->wherePresencePenalty($presence_penalty);
// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
$model->whereSeed($seed);
// Number of completions to generate for each prompt
$model->whereN($n);
// Modify the behavior of the model with system instructions
$model->whereSystemInstructions($instructions);
// Add tool functions for the model to request.
$model->whereTools($user_id);
use App\NeuralModels\Embeddings\OllamaEmbeddingsModel;
// Start tokenization query
$model = new OneShotModel();
// Build prompts
$query = $model->where('prompt', 'Why is the sky blue?');
$query = $model->wherePrompt('Why is the sky blue?');
$query = $model->whereIn('prompt', ['Why is the sky blue?', 'What is Rayleigh scattering?']);
$query = $model->wherePrompt('Why is the sky blue?')->wherePrompt('What is Rayleigh scattering?');
// Execute
$modelCollection = $model->get(); // Collection of models (responses)
$tokensModel = $model->first(); // Single model (latest response)
$modelCollection = (new OneShotModel())
->where('prompt', 'Why is the sky blue?')
->get();
$model = (new OneShotModel())
->where('prompt', 'Why is the sky blue?')
->first();
$query = (new OneShotModel())->newQuery();
$query = $query->where('prompt', 'Why is the sky blue?');
$modelCollection = $query->get();
$model = (new OneShotModel())
->where('prompt', 'Why is the sky blue?')
->whereTemperature(0.7) // Set temperature that controls randomness
->first();
// Max tokens to use in response
$model->whereMaxTokens($max_tokens);
// Penalize new tokens based on their existing frequency in the text so far
$model->whereFrequencyPenalty($frequency_penalty);
// Penalize new tokens based on whether they appear in the text so far
$model->wherePresencePenalty($presence_penalty);
// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
$model->whereSeed($seed);
// Number of completions to generate for each prompt
$model->whereN($n);
use App\NeuralModels\Embeddings\OllamaEmbeddingsModel;
// Start tokenization query
$model = new OllamaEmbeddingsModel();
// Build prompts
$query = $model->where('text', 'Why is the sky blue?');
$query = $model->whereInput('Why is the sky blue?');
$query = $model->whereIn('text', ['Why is the sky blue?', 'What is Rayleigh scattering?']);
$query = $model->whereInput('Why is the sky blue?')->whereInput('What is Rayleigh scattering?');
// Execute
$modelCollection = $model->get(); // Collection of models (responses)
$tokensModel = $model->first(); // Single model (latest response)
$modelCollection = (new OllamaEmbeddingsModel())
->where('input', 'Why is the sky blue?')
->get();
$model = (new OllamaEmbeddingsModel())
->where('input', 'Why is the sky blue?')
->first();
$query = (new OllamaEmbeddingsModel())->newQuery();
$query = $query->where('input', 'Why is the sky blue?');
$modelCollection = $query->get();
$model = (new OAICEmbeddingsModel())
->where('input', 'Why is the sky blue?')
->whereDimensions(1536) // Set dimension if needed
->first();
$model->whereEncodingFormat($encoding_format);
$model->whereUser($user_id);
$model->whereTitle($title);
$model->whereTaskType($task_type);
use App\NeuralModels\Tokenizations\GrokTokensModel;
// Start tokenization query
$model = new GrokTokensModel();
// Build prompts
$query = $model->where('text', 'Why is the sky blue?');
$query = $model->whereText('Why is the sky blue?');
$query = $model->whereIn('text', ['Why is the sky blue?', 'What is Rayleigh scattering?']);
$query = $model->whereText('Why is the sky blue?')->whereText('What is Rayleigh scattering?');
// Execute
$modelCollection = $model->get(); // Collection of models (responses)
$tokensModel = $model->first(); // Single model (latest response)
$modelCollection = (new GrokTokensModel())
->where('text', 'Why is the sky blue?')
->get();
$model = (new GrokTokensModel())
->where('text', 'Why is the sky blue?')
->first();
$query = (new GrokTokensModel())->newQuery();
$query = $query->where('text', 'Why is the sky blue?');
$modelCollection = $query->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.