Polyscope——面向 Laravel 的以代理为先的开发环境

LLPhant: A PHP Generative AI Framework Inspired by LangChain

最后更新于 经过

LLPhant: A PHP Generative AI Framework Inspired by LangChain image

LLPhant is a PHP library for building Generative AI applications in PHP. Created by Maxime Thoonsen, it provides a unified interface for working with multiple LLM providers including OpenAI, Anthropic, Mistral, LM Studio, and Ollama. The library is inspired by LangChain and LLamaIndex, bringing similar patterns to PHP developers.

Multi-Provider LLM Support

LLPhant abstracts away provider differences so you can switch between AI services with minimal code changes. Whether you are using OpenAI's GPT models, Anthropic's Claude, Mistral, LM Studio, or running local models through Ollama, the interface remains consistent:

// OpenAI
$chat = 新的 OpenAIChat ();
$响应 = $chat -> generateText 'What is the capital of France?' (英文):
// Anthropic Claude
$chat = 新的 AnthropicChat 新的 AnthropicConfig AnthropicConfig :: CLAUDE_3_5_SONNET ));
$响应 = $chat -> generateText 'What is the capital of France?' (英文):
// Local models via Ollama
$配置 = 新的 OllamaConfig ();
$配置 -> 模型 = 'llama2' ;
$chat = 新的 OllamaChat ($config);

The library also supports streaming responses for real-time chat interfaces, token usage tracking for cost monitoring, and vision capabilities for image analysis.

Embeddings and Vector Storage

LLPhant includes a complete pipeline for building Retrieval-Augmented Generation (RAG) applications. You can read documents from various sources (PDF, Word, text files), split them into chunks, generate embeddings, and store them in your preferred vector database:

// Read and process documents
$reader = 新的 FileDataReader __你__ '/documents' (英文):
文档 = $reader -> getDocuments ();
// Split into chunks for embedding
$splitDocuments = DocumentSplitter :: splitDocuments ($documents, 800 (英文):
// Generate embeddings
$embeddingGenerator = 新的 OpenAI3SmallEmbeddingGenerator ();
$embeddedDocuments = $embeddingGenerator -> embedDocuments ($splitDocuments);
// Store in PostgreSQL with pgvector
$vectorStore = 新的 DoctrineVectorStore ($entityManager, 文档 ::班级 (英文):
$vectorStore -> addDocuments ($embeddedDocuments);
// Search for similar content
$embedding = $embeddingGenerator -> embedText 'search query' (英文):
$结果 = $vectorStore -> similaritySearch ($embedding, 5 (英文):

Vector store support includes Doctrine (PostgreSQL with pgvector), Redis, Elasticsearch, MongoDB, ChromaDB, Qdrant, Milvus, AstraDB, OpenSearch, Pinecone, and Typesense.

Question Answering with RAG

The QuestionAnswering class handles the entire RAG workflow: retrieving relevant documents from your vector store and generating contextualized responses:

使用 LLPhant\Query\SemanticSearch\QuestionAnswering ;
$qa = 新的 QuestionAnswering ($vectorStore, $embeddingGenerator, $chat);
$响应 = $qa -> answerQuestion 'What are the main topics covered in the documentation?' (英文):

You can customize the system message template to control how the AI uses retrieved context, add guardrails for safety, and implement multi-query transformations to improve retrieval quality.

Function Calling and Tools

LLPhant supports function calling (tools), allowing your LLM to interact with external APIs and services. Define your tools as PHP classes and the LLM can decide when to invoke them based on the conversation context.

You can learn more about LLPhant and find detailed documentation at llphant.readthedocs.orgGitHub 存储库

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

归档于:
立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
了解软科技

以每小时 20 美元的价格聘请具备人工智能专业知识的 Laravel 开发人员。48 小时内即可开始工作。

访问 Acquaint Softtech
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
几天内即可获得 Laravel 代码审查徽标的专家指导

几天内即可获得 Laravel 代码审查方面的专家指导

专家级代码审查!两位拥有 10 年以上 Laravel 开发经验的开发者将为您提供清晰、实用的反馈,帮助团队构建更优质的应用程序。

几天内即可获得 Laravel 代码审查方面的专家指导
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
MongoDB 徽标

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB
Laravel Mobile Pass: Generate Apple Wallet and Google Wallet Passes image

Laravel Mobile Pass: Generate Apple Wallet and Google Wallet Passes

阅读文章
PHPverse 2026 Returns June 9th image

PHPverse 2026 Returns June 9th

阅读文章
LLPhant: A PHP Generative AI Framework Inspired by LangChain image

LLPhant: A PHP Generative AI Framework Inspired by LangChain

阅读文章
Debounceable Queued Jobs in Laravel 13.6.0 image

Debounceable Queued Jobs in Laravel 13.6.0

阅读文章
Build Custom Middleware for Query Performance Monitoring and Optimization in Laravel with MongoDB image

Build Custom Middleware for Query Performance Monitoring and Optimization in Laravel with MongoDB

阅读文章
Laravel API Starter Kits Are Coming Soon! image

Laravel API Starter Kits Are Coming Soon!

阅读文章