{"id":15021801,"url":"https://github.com/devscast/lugha","last_synced_at":"2025-04-10T20:12:16.603Z","repository":{"id":242505239,"uuid":"809220186","full_name":"devscast/lugha","owner":"devscast","description":"Lugha is a PHP Generative AI Framework to build chatbot, RAG systems and AI-powered applications","archived":false,"fork":false,"pushed_at":"2025-03-06T04:28:36.000Z","size":174,"stargazers_count":27,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-24T17:52:51.788Z","etag":null,"topics":["artificial-intelligence","framework","generative-ai","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devscast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-02T03:59:18.000Z","updated_at":"2025-03-18T02:52:59.000Z","dependencies_parsed_at":"2024-11-22T01:24:03.305Z","dependency_job_id":"85c8427a-b7a8-47f3-814e-1b0bbf7a0862","html_url":"https://github.com/devscast/lugha","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":"0.16666666666666663","last_synced_commit":"5939738cdd94021fcc151409e258cb4006353c78"},"previous_names":["devscast/lugha"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devscast%2Flugha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devscast%2Flugha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devscast%2Flugha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devscast%2Flugha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devscast","download_url":"https://codeload.github.com/devscast/lugha/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248288361,"owners_count":21078903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","framework","generative-ai","symfony"],"created_at":"2024-09-24T19:57:05.089Z","updated_at":"2025-04-10T20:12:16.581Z","avatar_url":"https://github.com/devscast.png","language":"PHP","readme":"# Lugha - yet another PHP Generative AI Framework\n\n![Lint](https://github.com/devscast/lugha/actions/workflows/lint.yml/badge.svg)\n![Test](https://github.com/devscast/lugha/actions/workflows/test.yml/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/devscast/lugha/version)](https://packagist.org/packages/devscast/lugha)\n[![Total Downloads](https://poser.pugx.org/devscast/lugha/downloads)](https://packagist.org/packages/devscast/lugha)\n[![License](https://poser.pugx.org/devscast/lugha/license)](https://packagist.org/packages/devscast/lugha)\n\n\u003e [!NOTE]  \n\u003e Work in progress.\n\nLugha from Swahili meaning \"Language\" is a PHP Generative AI Framework that provides a simple and easy way to interact with various AI providers.\nThe main idea is to provide a unified provider-agnostic API for AI models, making it easier to switch between providers.\n\nThis project is highly inspired by [LangChain](https://www.langchain.com/) and [LLPhant](https://github.com/theodo-group/LLPhant/), designed \nfor Chatbot, RAG (Retrieval-Augmented Generation) based applications with integration of Embeddings, Completion and Reranking models.\n\n*supported providers:*\n\n| Provider   | Link                                                | Features               |\n|------------|-----------------------------------------------------|------------------------|\n| OpenAI     | [openai.com](https://openai.com)                    | Completion, Embeddings |\n| Mistral    | [mistral.ai](https://mistral.ai/)                   | Completion, Embeddings |\n| Google     | [ai.google](https://ai.google/)                     | Completion, Embeddings |\n| GitHub     | [github.com](https://github.com/marketplace/models) | Completion, Embeddings |\n| Anthropic  | [anthropic.com](https://www.anthropic.com/)         | Completion             |\n| Voyager.ai | [voyageai.com](https://www.voyageai.com/)           | Embeddings, Reranking  |\n| Ollama     | [ollama.com](https://ollama.com/)                   | Completion, Embeddings | \n| Deepseek   | [deepseek.com](https://deepseek.com)                | completion             |\n\n\n\n## Installation\n```bash\ncomposer require devscast/lugha\n```\n\n## Usage\n\n### Embeddings\nEmbeddings are a type of word representation that allows words with similar meaning to have a similar representation.\nthey can be used to find the similarity between words, phrases, or sentences.\nuseful for document classification, clustering, and information retrieval.\n\n```php\n$client = ClientFactory::create(Provider::GOOGLE);\n$embeddings = $client-\u003eembeddings(\n    prompt: 'Hello, world!', \n    config: new EmbeddingsConfig(\n        model: 'text-embedding-004',\n        dimensions: 512\n    )\n)-\u003eembedding;\n```\n\n### Completion\nCompletion models are designed to generate human-like text based on the input prompt.\n\n```php\n$client = ClientFactory::create(Provider::OPENAI);\n```\n\n- completion from a single prompt\n```php\n$completion = $client-\u003ecompletion(\n    input: 'Hello, world!', \n    config: new CompletionConfig(\n        model: 'gpt-3.5-turbo',\n        temperature: 0.5,\n        maxTokens: 100,\n        frequencyPenalty: 0.5,\n        presencePenalty: 0.5\n    )\n)-\u003ecompletion;\n```\n\n- completion from a chat history (conversation)\n```php\n$completion = $client-\u003echat(\n    input: History::fromMessages([\n        new Message('You are a chatbot, expert in philosophy', Role::SYSTEM),\n        new Message('what is the meaning of life ?', Role::USER)\n    ]),\n    config: new ChatConfig(model: 'gpt-4-turbo')\n)-\u003ecompletion;\n```\n\n- completion with tool calling\n```php\n#[ToolDefinition(\n    name: 'get_weather',\n    description: 'Get the weather for a location on a specific date.',\n    parameters: [\n        new ToolParameter('location', 'string', 'The location to get the weather for.', required: true),\n        new ToolParameter('date', 'string', 'The date to get the weather for.', required: true),\n    ],\n    strict: true\n)]\nclass WeatherProvider\n{\n    public function __invoke(string $location, string $date): string\n    {\n        return \"The weather in $location on $date is sunny.\";\n    }\n}\n\n$completion = $client-\u003ecompletion(\n    input: 'What is the weather in Lubumbashi on January 16th ?',\n    config: new CompletionConfig(model: 'gpt-4-turbo'),\n    tools: [new WeatherProvider()] \n)-\u003ecompletion;\n```\n\n### Reranking\nReranking models are designed to re-rank a list of documents based on the input prompt.\nuseful for search engines, recommendation systems, and information retrieval.\n\n```php  \n$client = ClientFactory::create(Provider::VOYAGER);\n\n$reRankedDocuments = $client-\u003ereranking(\n    prompt: 'What is the meaning of life ?',\n    documents: [\n        new Document('The best way to predict the future is to create it.'),\n        new Document('The only way to do great work is to love what you do.'),\n        new Document('Life is short, smile while you still have teeth.'),\n        new Document('The best time to plant a tree was 20 years ago. The second best time is now.')\n    ],\n    config: new RerankingConfig(model: 'voyager-1.0', topK: 3)\n)-\u003edocuments;\n```\n\n## Contributors\n\n\u003ca href=\"https://github.com/devscast/lugha/graphs/contributors\" title=\"show all contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=devscast/lugha\" alt=\"contributors\"/\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":["LLM Frameworks"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevscast%2Flugha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevscast%2Flugha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevscast%2Flugha/lists"}