ngandu-dev/lugha

Lugha is a PHP Generative AI framework to build chatbot, RAG systems and AI-powered applications

Maintainers

Package info

github.com/ngandu-dev/lugha

pkg:composer/ngandu-dev/lugha

Transparency log

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 30

Open Issues: 0

1.0.1 2026-08-19 11:28 UTC

This package is auto-updated.

Last update: 2026-08-19 11:34:07 UTC


README

Latest Stable Version Total Downloads Quality Tests License

Important

Lugha is abandoned in favor of Symfony AI - github.com/symfony/ai. Please use the new repository for all future development, issues, and contributions.

Lugha from Swahili meaning "Language" is a PHP Generative AI Framework that provides a simple and easy way to interact with various AI providers. The main idea is to provide a unified provider-agnostic API for AI models, making it easier to switch between providers.

This project is highly inspired by LangChain and LLPhant, designed for Chatbot, RAG (Retrieval-Augmented Generation) based applications with integration of Embeddings, Completion and Reranking models.

Features

  • Provider-agnostic completion, embeddings, and reranking APIs
  • Chat history and tool calling
  • Document loaders, retrieval, and vector stores

Requirements

  • PHP 8.3 or later
  • Composer 2

supported providers:

Provider Link Features
OpenAI openai.com Completion, Embeddings
Mistral mistral.ai Completion, Embeddings
Google ai.google Completion, Embeddings
GitHub github.com Completion, Embeddings
Anthropic anthropic.com Completion
Voyager.ai voyageai.com Embeddings, Reranking
Ollama ollama.com Completion, Embeddings
Deepseek deepseek.com completion

Installation

composer require ngandu-dev/lugha

Usage

Embeddings

Embeddings are a type of word representation that allows words with similar meaning to have a similar representation. they can be used to find the similarity between words, phrases, or sentences. useful for document classification, clustering, and information retrieval.

$client = ClientFactory::create(Provider::GOOGLE);
$embeddings = $client->embeddings(
    prompt: 'Hello, world!', 
    config: new EmbeddingsConfig(
        model: 'text-embedding-004',
        dimensions: 512
    )
)->embeddings;

Completion

Completion models are designed to generate human-like text based on the input prompt.

$client = ClientFactory::create(Provider::OPENAI);
  • completion from a single prompt
$completion = $client->completion(
    input: 'Hello, world!', 
    config: new CompletionConfig(
        model: 'gpt-3.5-turbo',
        temperature: 0.5,
        maxTokens: 100,
        frequencyPenalty: 0.5,
        presencePenalty: 0.5
    )
)->completion;
  • completion from a chat history (conversation)
$completion = $client->chat(
    input: History::fromMessages([
        new Message('You are a chatbot, expert in philosophy', Role::SYSTEM),
        new Message('what is the meaning of life ?', Role::USER)
    ]),
    config: new ChatConfig(model: 'gpt-4-turbo')
)->completion;
  • completion with tool calling
#[ToolDefinition(
    name: 'get_weather',
    description: 'Get the weather for a location on a specific date.',
    parameters: [
        new ToolParameter('location', 'string', 'The location to get the weather for.', required: true),
        new ToolParameter('date', 'string', 'The date to get the weather for.', required: true),
    ],
    strict: true
)]
class WeatherProvider
{
    public function __invoke(string $location, string $date): string
    {
        return "The weather in $location on $date is sunny.";
    }
}

$completion = $client->completion(
    input: 'What is the weather in Lubumbashi on January 16th ?',
    config: new CompletionConfig(model: 'gpt-4-turbo'),
    tools: [new WeatherProvider()] 
)->completion;

Reranking

Reranking models are designed to re-rank a list of documents based on the input prompt. useful for search engines, recommendation systems, and information retrieval.

$client = ClientFactory::create(Provider::VOYAGER);

$reRankedDocuments = $client->reranking(
    prompt: 'What is the meaning of life ?',
    documents: [
        new Document('The best way to predict the future is to create it.'),
        new Document('The only way to do great work is to love what you do.'),
        new Document('Life is short, smile while you still have teeth.'),
        new Document('The best time to plant a tree was 20 years ago. The second best time is now.')
    ],
    config: new RerankingConfig(model: 'voyager-1.0', topK: 3)
)->documents;

Development

composer install
composer format
composer quality

Contributing

See CONTRIBUTING.md before opening an issue or pull request.

Security

Report vulnerabilities privately as described in SECURITY.md.

License

Released under the MIT License.

Contributors

Contributors