php-llm / llm-chain
A slim PHP component with tooling around LLMs.
Requires
- php: >=8.1
- phpdocumentor/reflection-docblock: ^5.4
- psr/cache: ^3.0
- psr/log: ^3.0
- symfony/http-client: ^6.4 || ^7.0
- symfony/property-access: ^7.1
- symfony/property-info: ^7.1
- symfony/serializer: ^7.1
- symfony/type-info: ^7.1
- symfony/uid: ^7.1
Requires (Dev)
- codewithkyrian/chromadb-php: ^0.2.1
- php-cs-fixer/shim: ^3.58
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.2
- probots-io/pinecone-php: ^1.0
- symfony/clock: ^6.4 || ^7.0
- symfony/console: ^6.4 || ^7.0
- symfony/var-dumper: ^6.4 || ^7.0
Suggests
- codewithkyrian/chromadb-php: For using the ChromaDB as retrieval vector store.
- probots-io/pinecone-php: For using the Pinecone as retrieval vector store.
- symfony/clock: For using the clock tool.
This package is auto-updated.
Last update: 2024-09-07 08:49:53 UTC
README
Simple PHP toolkit for building LLM chains.
This is not stable nor production ready, it's just a playground for me to experiment with LLMs. Abstractions, concepts and interfaces are not good at all and will definitely change.
Requirements
- PHP 8.1 or higher
Installation
The recommended way to install LlmChain is through Composer:
composer require php-llm/llm-chain
Supported Models & Runtimes
Currently supported models and runtimes:
Planned Models & Runtimes (not implemented yet):
Supported Stores
Currently supported stores:
- Chroma DB
- Azure AI Search
- Pinecone
Provided Tools
- SerpApi
- Clock
- Wikipedia
- Weather
Usage Examples
See examples to run example implementations using this library. Depending on the example you need to export needed environment variables for API keys or deployment configurations:
Chat Examples
-
Chat Example: OpenAI's GPT
export OPENAI_API_KEY=sk-... php examples/chat-gpt-openai.php
-
Chat Example: OpenAI's GPT With Azure
export AZURE_OPENAI_BASEURL=... // e.g. your-resource.openai.azure.com export AZURE_OPENAI_DEPLOYMENT=... export AZURE_OPENAI_VERSION=... // e.g. 2023-03-15-preview export AZURE_OPENAI_KEY=... php examples/chat-gpt-azure.php
-
Chat Example: Anthropic's Claude
export ANTHROPIC_API_KEY=sk-... php examples/chat-claude-anthropic.php
ToolChain Examples
-
Simple Clock Tool
export OPENAI_API_KEY=sk-... php examples/toolchain-clock.php
-
Wikipedia Tool
export OPENAI_API_KEY=sk-... php examples/toolchain-wikipedia.php
-
SerpAPI Tool
export OPENAI_API_KEY=sk-... export SERPAPI_API_KEY=... php examples/toolchain-serpapi.php
Structured Output
- Structured Output Example: OpenAI's GPT
export OPENAI_API_KEY=sk-... php examples/structured-output-math.php