{"id":17094941,"url":"https://github.com/ezimuel/php-llm-examples","last_synced_at":"2025-04-12T23:13:34.737Z","repository":{"id":241178760,"uuid":"804258321","full_name":"ezimuel/php-llm-examples","owner":"ezimuel","description":"PHP examples about the usage of GenAI and LLM","archived":false,"fork":false,"pushed_at":"2024-08-14T17:03:45.000Z","size":1038,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T23:13:26.900Z","etag":null,"topics":["genai","llama3","llm","ollama","openai-api","php"],"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/ezimuel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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-05-22T08:55:06.000Z","updated_at":"2025-03-20T16:01:42.000Z","dependencies_parsed_at":"2024-09-01T00:00:59.602Z","dependency_job_id":"d148f635-3b3d-4f4b-ba90-291e5b982cf2","html_url":"https://github.com/ezimuel/php-llm-examples","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"105a281313af33220dd1d941346cc8e3d8282984"},"previous_names":["ezimuel/php-llm-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezimuel%2Fphp-llm-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezimuel%2Fphp-llm-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezimuel%2Fphp-llm-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezimuel%2Fphp-llm-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezimuel","download_url":"https://codeload.github.com/ezimuel/php-llm-examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643006,"owners_count":21138355,"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":["genai","llama3","llm","ollama","openai-api","php"],"created_at":"2024-10-14T14:25:09.608Z","updated_at":"2025-04-12T23:13:34.712Z","avatar_url":"https://github.com/ezimuel.png","language":"PHP","funding_links":[],"categories":["Learning Resources"],"sub_categories":["Utilities \u0026 Tools"],"readme":"# Examples of using LLM in PHP\n\nIn this repository, I collected some PHP examples about the usage \nof Generative AI and Large Language Model (LLM) in PHP.\n\nFor the PHP code, I used [LLPhant](https://github.com/theodo-group/LLPhant) and [openai-php/client](https://github.com/openai-php/client) projects. \nFor the LLM models I used [OpenAI](https://openai.com/) and [Llama 3](https://llama.meta.com/llama3/).\nFor semantic search, I used [Elasticsearch](https://github.com/elastic/elasticsearch)\nas vector database.\n\n## Configure the environment\n\nTo execute the examples you need to set some environment variables:\n\n```bash\nexport OPENAI_API_KEY=xxx\nexport ELASTIC_URL=https://yyy\nexport ELASTIC_API_KEY=zzz\n```\n\nIf you want to run Llama 3 locally you can install [Ollama](https://ollama.com/)\nrunning the following command (in this case you don't need `OPENAI_API_KEY`):\n\n```bash\nollama pull llama3\n```\n\nThis will install Llama3 and the model will be available through HTTP API at\n`http://localhost:11434/api/`.\n\nIf you want to interact with LLama 3 using a chat interface, you can execute\nthe following command:\n\n```bash\nollama run llama3\n```\n\n## Examples\n\nFor OpenAI API example usage look at the following scripts:\n\n- [openai_chat](src/openai_chat.php), a simple chat use case;\n- [openai_image](src/openai_image.php), generate an image using `dall-e-3` model;\n- [openai_speech](src/openai_speech.php), text-to-speech example using `tts-1` model;\n- [openai_moderation](src/openai_moderation.php), moderation using `text-moderation-latest` model;\n- [openai_function](src/openai_function.php), [function calling](https://platform.openai.com/docs/guides/function-calling) example;\n\nFor LLPhant examples you can see the following scripts:\n\n- [llphant_chat](src/llphant_chat.php), a simple chat use case;\n- [llphant_tool](src/llphant_tool.php), the function calling tool in LLPhant;\n\nThe Retrieval-Augmented Generation examples are in the [src/rag](src/rag/) folder.\n\nI divided the folderusing different embedding models: [ELSER](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html),\n[Llama3](https://llama.meta.com/llama3/) using ollama and GPT-3.5-turbo by [OpenAI](https://openai.com/).\n\nFor the RAG examples I used a simple PDF document that contains the [AI act](data/AI_act.pdf)\nregulation proposed by the European Union in July 2023.\nThis document is not part of the knowledge of `GPT-3.5-turbo` that is fixed to 2022.\nIn the examples we store the document in the vector database (Elasticsearch) using the\n`embedding.php` script, than we use the `qa.php` to ask for the question \"What is the AI act?\".\nUsing the RAG architecture we can expand the knowledge of the LLM, without fine-tuning the model,\nproviding also the sources (chunks) used to answer the question.\n\n## Copyright\n\nCopyright (C) 2024 by Enrico Zimuel\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezimuel%2Fphp-llm-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezimuel%2Fphp-llm-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezimuel%2Fphp-llm-examples/lists"}