php-llm/llm-chain

A slim PHP component with tooling around LLMs.

dev-main 2024-09-07 08:49 UTC

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

  1. Chat Example: OpenAI's GPT

    export OPENAI_API_KEY=sk-...
    php examples/chat-gpt-openai.php
  2. 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
  3. Chat Example: Anthropic's Claude

    export ANTHROPIC_API_KEY=sk-...
    php examples/chat-claude-anthropic.php

ToolChain Examples

  1. Simple Clock Tool

    export OPENAI_API_KEY=sk-...
    php examples/toolchain-clock.php
  2. Wikipedia Tool

    export OPENAI_API_KEY=sk-...
    php examples/toolchain-wikipedia.php
  3. SerpAPI Tool

    export OPENAI_API_KEY=sk-...
    export SERPAPI_API_KEY=...
    php examples/toolchain-serpapi.php

Structured Output

  1. Structured Output Example: OpenAI's GPT
    export OPENAI_API_KEY=sk-...
    php examples/structured-output-math.php