Download the PHP package rhaymison/elephant_chain without Composer
On this page you can find all versions of the php package rhaymison/elephant_chain. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rhaymison/elephant_chain
More information about rhaymison/elephant_chain
Files in rhaymison/elephant_chain
Package elephant_chain
Short Description LLM chain for PHP projects
License Apache-2.0
Informations about the package elephant_chain
Elephant Chain 🐘 - A Powerful Library for PHP Environments with LLMs
Welcome to Elephant Chain 🐘, a robust library crafted to seamlessly integrate Large Language Models (LLMs) into PHP environments. Whether you're developing sophisticated natural language processing applications or enhancing your PHP projects with AI capabilities, Elephant Chain equips you with the tools and functionalities to achieve this effortlessly and efficiently.
Key Features
- Seamless Integration: Easily incorporate LLMs into your existing PHP projects with minimal setup.
- High Performance: Optimized for performance, ensuring fast AI-powered applications.
- Flexibility: Supports a variety of LLMs, allowing you to select the model that best suits your needs.
- User-Friendly: Straightforward and intuitive, making it accessible for developers of all skill levels.
- Comprehensive Documentation: Detailed documentation and examples to help you quickly get started and fully utilize the library's capabilities.
Table of Contents
- Installation
- Basic Usage
- Available Models
- OpenAi
- Gemini
- Mistral
- Ollama
- Loaders
- TXT Files
- PDF Loaders
- CSV Loaders
- Doc Loaders
- Chains
- Chain
- RetrieverChain
- SequentialChain
- TabularChain
- ChatMemoryChain
- Embedding
- OpenAi Embeddings
- Gemini Embeddings
- Mistral Embeddings
- Ollama Embeddings
- Vector Databases
- ElephantVectors
- ChromaDB
- Tools
- Wikipedia
- DuckDuckGo
Installation
To get started with Elephant Chain, follow these simple steps:
- Installation: Install the library using Composer:
Basic Usage
Available Models
Elephant Chain currently supports the use of models from OpenAI and Gemini. Integration with Mixtral and LlamaCPP is currently being implemented. Here are examples of how to initialize and use these models:
OpenAi
You must pass your integration key with your api. The model used by default is the gpt3.5 turbo and with a temperature of 0.5
Gemini
You must provide your Gemini API key and pass the temperature if you want, by default it is set to 0.5
Mistral
You must pass your integration key with the mistral and choose one of the available models. By default the model is: mistral-large-latest and with temperature: 0.5
Ollama
Add the ollama endpoint and select the model you want to use and have downloaded in your ollama environment
Loaders
TXT Files
The TxtLoader
class allows you to load and process text files for use within Elephant Chain.
The first parameter is the directory, the second is the chunk size and the third is the overlapping window.
If you want to load only one txt file you can use this method and the last two parameters remain chunk and overlaping
PDF Loaders
The PdfLoader
class enables you to load and extract text from PDF documents, making it easy to integrate document data
into your workflows.
CSV Loaders
Doc Loaders
This class allows you to load only .doc files and not docx files. You can load an entire directory or just a single file.
Chains
Chain
The Chain
class is the fundamental building block for creating and managing sequences of operations in Elephant Chain.
RetrieverChain
The RetrieverChain
class extends the functionality of Chain
by incorporating mechanisms to retrieve relevant data
based on provided prompts.
SequentialChain
The SequentialChain
class allows you to create a series of dependent operations, where the output of one operation
serves as the input for the next.
If you wish, you can include a retriever chain at the beginning, end or middle of the chain. Just ensure that the exit must be passed forward.
TabularChain
The TabularChain class loads data from CSV/XLSX spreadsheets and applies user-defined transformations and filters to the extracted data. This class enables flexible manipulation and analysis of data through dynamically generated functions.
ChatMemoryChain
If you want to add memory to your conversation. You can use the Memory chat with the memory template. A memory cell will be stored and you can manipulate, remove or clear it whenever you want. ChainMemory accepts the template and name of the chat room you want to create.
The memory is added automatically and you don't need to worry about it. If you want to start the conversation with a memory, just pass it as the third parameter to the chatTemplate... The ChatMemoryChain already has a native getMemory function that you can use.
LARAVEL USAGE
Now we have this beautiful result
Embedding
Using embeddings in ElephantChain is very simple. The Embedding Function interface means that all embedding models offer the same return, making their implementation easy and quick.
OpenAi Embeddings
Gemini Embeddings
Mistral Embeddings
Ollama Embeddings
Vector Databases
ElephantVectors
The ElephantVectors
class provides functionalities to store, manage, and query vectorized data, enabling efficient
similarity searches and advanced data retrieval operations.
If you don't want to have a vector database, you can use ElephantVectors which provides document embeddings and allows
you to perform the searches directly to the model.
ChromaDB
The ChromaDB
class offers robust capabilities for handling vectorized data, including storage, management, and
querying, optimized for high-performance vector similarity searches.
Basic usage
The $documents variable has a 3-position array where the first is the ids, followed by the metadata and the third by the chunks. All arrays correspond to each other.
Usage example with OpenAI model
Usage example with Gemini and passing the embeddings function
LARAVEL USAGE
Now we can interact with your VectorsDatabase
Now we have this beautiful result
Tools
Tools are powerful instruments that you can add to your inferences. Below you can check out some of the available tools ps: Till this moment the tools are only available for simple Chain
Wikipedia
This tool searches Wikipedia and aggregates the information in the context of the user's question. The parameter passed in the constructor is the limit of search results.
DuckDuckGo
This powerful tool performs advanced searches on DuckDuck and adds important information to your prompt. You just need to specify the region where you want to perform the search.
prompt example with duckduckGo
All versions of elephant_chain with dependencies
codewithkyrian/chromadb-php Version dev-main
openai-php/client Version dev-main
spatie/pdf-to-text Version dev-main
gemini-api-php/client Version dev-main
ext-mbstring Version *
partitech/php-mistral Version dev-main
modelflow-ai/ollama Version 0.2.x-dev
phpoffice/phpword Version dev-master
ncjoes/office-converter Version dev-master
ext-curl Version *
symfony/dom-crawler Version ^6.0
symfony/css-selector Version ^6.0