|
| 1 | +# Symfony AI - Demo Application |
| 2 | + |
| 3 | +Symfony application demoing Symfony AI components. |
| 4 | + |
| 5 | +## Examples |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +What you need to run this demo: |
| 12 | + |
| 13 | +* Internet Connection |
| 14 | +* Terminal & Browser |
| 15 | +* [Git](https://git-scm.com/) & [GitHub Account](https://github.com) |
| 16 | +* [Docker](https://www.docker.com/) with [Docker Compose Plugin](https://docs.docker.com/compose/) |
| 17 | +* Your Favorite IDE or Editor |
| 18 | +* An [OpenAI API Key](https://platform.openai.com/docs/api-reference/create-and-export-an-api-key) |
| 19 | + |
| 20 | +## Technology |
| 21 | + |
| 22 | +This small demo sits on top of following technologies: |
| 23 | + |
| 24 | +* [PHP >= 8.4](https://www.php.net/releases/8.4/en.php) |
| 25 | +* [Symfony 7.3 incl. Twig, Asset Mapper & UX](https://symfony.com/) |
| 26 | +* [Bootstrap 5](https://getbootstrap.com/docs/5.0/getting-started/introduction/) |
| 27 | +* [OpenAI's GPT & Embeddings](https://platform.openai.com/docs/overview) |
| 28 | +* [ChromaDB Vector Store](https://www.trychroma.com/) |
| 29 | +* [FrankenPHP](https://frankenphp.dev/) |
| 30 | + |
| 31 | +## Setup |
| 32 | + |
| 33 | +The setup is split into three parts, the Symfony application, the OpenAI configuration, and initializing the Chroma DB. |
| 34 | + |
| 35 | +### 1. Symfony App |
| 36 | + |
| 37 | +Checkout the repository, start the docker environment and install dependencies: |
| 38 | + |
| 39 | +```shell |
| 40 | +git clone git@github.com:symfony/ai-demo.git |
| 41 | +cd ai-demo |
| 42 | +docker compose up -d |
| 43 | +docker compose run composer install |
| 44 | +``` |
| 45 | + |
| 46 | +Now you should be able to open https://localhost/ in your browser, |
| 47 | +and the chatbot UI should be available for you to start chatting. |
| 48 | + |
| 49 | +> [!NOTE] |
| 50 | +> You might have to bypass the security warning of your browser with regard to self-signed certificates. |
| 51 | +
|
| 52 | +### 2. OpenAI Configuration |
| 53 | + |
| 54 | +For using GPT and embedding models from OpenAI, you need to configure an OpenAI API key as environment variable. |
| 55 | +This requires you to have an OpenAI account, create a valid API key and set it as `OPENAI_API_KEY` in `.env.local` file. |
| 56 | + |
| 57 | +```shell |
| 58 | +echo "OPENAI_API_KEY='sk-...'" > .env.local |
| 59 | +``` |
| 60 | + |
| 61 | +Verify the success of this step by running the following command: |
| 62 | + |
| 63 | +```shell |
| 64 | +docker compose exec app bin/console debug:dotenv |
| 65 | +``` |
| 66 | + |
| 67 | +You should be able to see the `OPENAI_API_KEY` in the list of environment variables. |
| 68 | + |
| 69 | +### 3. Chroma DB Initialization |
| 70 | + |
| 71 | +The [Chroma DB](https://www.trychroma.com/) is a vector store that is used to store embeddings of the chatbot's context. |
| 72 | + |
| 73 | +To initialize the Chroma DB, you need to run the following command: |
| 74 | + |
| 75 | +```shell |
| 76 | +docker compose exec app bin/console app:blog:embed -vv |
| 77 | +``` |
| 78 | + |
| 79 | +Now you should be able to run the test command and get some results: |
| 80 | + |
| 81 | +```shell |
| 82 | +docker compose exec app bin/console app:blog:query |
| 83 | +``` |
| 84 | + |
| 85 | +**Don't forget to set up the project in your favorite IDE or editor.** |
| 86 | + |
| 87 | +## Functionality |
| 88 | + |
| 89 | +* The chatbot application is a simple and small Symfony 7.3 application. |
| 90 | +* The UI is coupled to a [Twig LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html), that integrates different `Chat` implementations on top of the user's session. |
| 91 | +* You can reset the chat context by hitting the `Reset` button in the top right corner. |
| 92 | +* You find three different usage scenarios in the upper navbar. |
0 commit comments