LLPhant/LLPhant
LLPhant - A comprehensive PHP Generative AI Framework using OpenAI GPT 4. Inspired by Langchain
TL;DR
LLPhant is a PHP library that lets you call large language models (OpenAI, Anthropic, Mistral, Ollama, etc.) and work with vector databases to build Retrieval‑Augmented Generation (RAG) or autonomous AI agents in PHP applications (Symfony, Laravel). It also bundles a Jev‑based classifier for safe, rubric‑style scoring.
What it does (in plain language)
- LLM access – Provides a thin wrapper around many popular LLM APIs (OpenAI, Anthropic, Mistral, Ollama, LM Studio, Atlas Cloud, Heabsy, LocalAI, etc.).
- Vector‑store integration – Lets you store document embeddings and perform similarity search, the core of RAG pipelines.
- Agent / QA helpers – Ready‑made classes for question‑answering, tool‑calling, and autonomous agents that can be dropped into a Symfony or Laravel project.
- JevClassifier – A safety/quality classifier (Noul, Choice, Score) that can flag prompt‑injection attacks and give rubric‑based scores, exposing token usage metadata.
- Framework friendly – Designed to work smoothly with the PHP frameworks Symfony and Laravel.
Who might use it
- PHP developers who want to add generative‑AI features (chatbots, document search, summarisation, autonomous agents) without leaving their familiar stack.
- Teams building internal tools on top of Laravel/Symfony that need to query LLMs or run RAG pipelines.
- Companies that already have PHP back‑ends and want to experiment with AI‑augmented services quickly.
How to get started (quick steps)
- Install via Composer:
(addcomposer require theodo-group/llphant--ignore-platform-req=ext-gdif the GD extension is missing.) - Configure an LLM provider – set the appropriate API key (e.g.,
OPENAI_API_KEY) and choose a driver (OpenAI,Anthropic,Ollama, …). - Create a vector store (e.g., using Pinecone, Milvus, or a local SQLite‑based store) and index your documents with the provided embedding helpers.
- Use a high‑level class like
QuestionAnsweringorAgentto run a RAG query or an autonomous workflow. - (Optional) Add Jev safety – export
JEV_API_KEYand instantiatenew JevClassifier()to get typed rubric scores and prompt‑injection detection.
What’s new / noteworthy
- Typed Jev classification – Supports three rubric types (
Noul,Choice,Score). Returned answers now includeinputTokensandoutputTokensfor cost tracking. - Prompt‑injection guard –
ClassifierPromptInjectionQueryTransformercan be plugged into the QA pipeline to filter malicious inputs. - Broad LLM support – Added drivers for newer services like Mistral, Atlas Cloud, Heabsy, and local‑run Ollama models (e.g., Llama 2).
Quick code sketch (illustrative, not exhaustive)
use LLPhant\LLM\OpenAI\OpenAIClient;
use LLPhant\VectorStore\Pinecone\PineconeStore;
use LLPhant\Agent\QuestionAnswering;
use LLPhant\Classifier\JevClassifier;
$llm = new OpenAIClient(apiKey: getenv('OPENAI_API_KEY'));
$vectorStore = new PineconeStore(apiKey: getenv('PINECONE_KEY'));
$qa = new QuestionAnswering($llm, $vectorStore);
// Optional safety layer
$classifier = new JevClassifier();
$qa->addTransformer($classifier->getPromptInjectionTransformer());
$response = $qa->ask('How does quantum entanglement work?');
print_r($response->content);
print "Tokens used: {$response->inputTokens} → {$response->outputTokens}\n";
Where to learn more
- Docs –
docs/folder or https://llphant.readthedocs.org - Video tutorials (French) – building a RAG app with Symfony, creating an autonomous agent.
- Slides & articles – see the linked Medium and SlideShare posts for deeper architectural discussion.
LLPhant is a genuine open‑source PHP project aimed at bringing generative‑AI and vector‑search capabilities to the PHP ecosystem.
Related
- Project
- Project
- Project
- Project
- Project