ML Ecosystem in PHP

Learning examples

These examples will help you understand how you can use ML in PHP. They are not full-fledged applications, but they will help you understand the basics of working with ML in PHP.


Example with LLPhant

LLPhant is a lightweight framework to call LLMs from PHP. The snippet below sends a single prompt to OpenAI via LLPhant and prints the model response.

 
<?php

use LLPhant\Chat\Enums\ChatRole;
use 
LLPhant\Chat\Message;
use 
LLPhant\Chat\OpenAIChat;

$chat = new OpenAIChat();

$message = new Message();
$message->role ChatRole::User;
$message->content 'What is the capital of France? ';

$response $chat->generateText((string)$message);
echo 
$response;
Result: Memory: 0 Mb Time running: < 0.001 sec.
The capital of France is Paris.