{"id":31692443,"url":"https://github.com/afelix-95/genai-rag-app","last_synced_at":"2026-05-18T03:11:26.967Z","repository":{"id":315089208,"uuid":"1057888915","full_name":"afelix-95/GenAI-RAG-App","owner":"afelix-95","description":"This chatbot provides information about PSI-20 companies using Retrieval-Augmented Generation (RAG) with Azure AI Search and OpenAI GPT models. Ask questions about Portuguese stock market companies!","archived":false,"fork":false,"pushed_at":"2025-09-26T13:54:27.000Z","size":2675,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-08T14:14:47.723Z","etag":null,"topics":["azure-ai-foundry","azure-functions","azure-search","fastapi","generative-ai","rag-chatbot","tts"],"latest_commit_sha":null,"homepage":"","language":"Python","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/afelix-95.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-16T10:41:31.000Z","updated_at":"2025-10-04T16:19:44.000Z","dependencies_parsed_at":"2025-09-16T18:07:14.382Z","dependency_job_id":null,"html_url":"https://github.com/afelix-95/GenAI-RAG-App","commit_stats":null,"previous_names":["afelix-95/genai-rag-app"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/afelix-95/GenAI-RAG-App","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afelix-95%2FGenAI-RAG-App","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afelix-95%2FGenAI-RAG-App/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afelix-95%2FGenAI-RAG-App/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afelix-95%2FGenAI-RAG-App/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afelix-95","download_url":"https://codeload.github.com/afelix-95/GenAI-RAG-App/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afelix-95%2FGenAI-RAG-App/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["azure-ai-foundry","azure-functions","azure-search","fastapi","generative-ai","rag-chatbot","tts"],"created_at":"2025-10-08T14:06:39.331Z","updated_at":"2026-05-18T03:11:26.949Z","avatar_url":"https://github.com/afelix-95.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# GenAI-RAG-App\n\nThis project demonstrates an end-to-end generative AI chatbot pipeline with Retrieval-Augmented Generation (RAG) and text-to-speech (TTS), deployed serverlessly on Azure Functions. The app acts as a \"PSI 20 expert,\" using RAG on the companies' latest annual reports to answer questions about them. It leverages Azure AI Search for document retrieval, GPT-4o-mini-tts for generation and TTS, and FastAPI for API endpoints. The front-end provides a simple chat interface with TTS playback.\n\n## Project Overview\n\n- **Objective**: Build and deploy a generative AI chatbot that answers questions using RAG and provides spoken responses.\n- **Dataset**: Annual reports from PSI 20 companies (not included in repo due to size).\n- **Models**: GPT-4.1-mini for LLM, GPT-4o-mini-tts for TTS, and text-embedding-3-small for embeddings, integrated with Azure AI Search.\n- **Platform**: Azure Functions for serverless deployment, Azure AI Foundry for base model deployments, FastAPI for API, Azure AI Search for retrieval.\n\n## Semantic Kernel Integration\n\nThis project leverages **Microsoft Semantic Kernel** (SK) to orchestrate the AI pipeline, providing a structured and extensible framework for integrating multiple AI services.\n\n### Key Components\n\n- **Kernel Setup** (`api/semantic_kernel_setup.py`): Initializes the SK kernel with Azure OpenAI service integration\n- **RAG Plugin** (`RAGPlugin` class): Custom plugin containing kernel functions for RAG and TTS operations\n- **Kernel Functions**: Decorated methods that can be invoked by the kernel:\n  - `ProcessRAGQuery`: Handles document retrieval and response generation using Azure AI Search\n  - `TextToSpeech`: Converts generated text responses to audio using Azure OpenAI TTS\n\n### Orchestration Flow\n\n1. **Kernel Initialization**: Azure OpenAI service is registered with the kernel\n2. **Plugin Registration**: RAGPlugin is added to the kernel with defined functions\n3. **Query Processing**: User queries are processed through kernel invocation:\n   - RAG function retrieves relevant documents and generates contextual responses\n   - TTS function synthesizes audio from the text response\n4. **Response Assembly**: Kernel returns structured output with both text and audio data\n\n### Benefits\n\n- **Modularity**: Clean separation of AI operations through plugins and functions\n- **Extensibility**: Easy to add new AI capabilities or modify existing ones\n- **Type Safety**: KernelArguments provide structured parameter passing\n- **Async Support**: Native support for asynchronous operations in the pipeline\n\n## Repository Structure\n```\nretriever/         # Azure AI Search logic and LLM response generation (GPT-4.1-mini)\ngenerator/         # TTS audio synthesis modules (GPT-4o-mini-tts)\napi/               # FastAPI endpoints, Azure Functions triggers, Semantic Kernel orchestration\nfrontend/          # Chatbot UI, TTS playback\ntests/             # Unit tests, demo scripts\n.env.example       # Example config\nrequirements.txt   # Python dependencies\npackage.json       # Front-end dependencies\n```\n\n## Prerequisites\n\n- **Azure Subscription**: Active Azure account with access to Azure AI Services, Azure AI Search and Azure Functions.\n- **GitHub Repository**: Fork or clone this repository.\n- **Secrets**:\n  - `AZURE_SEARCH_ENDPOINT`, `AZURE_SEARCH_API_KEY`, `AZURE_SEARCH_INDEX`\n  - `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_DEPLOYMENT`, `TTS_MODEL_NAME`\n  - `EMBEDDING_MODEL_NAME`\n- **Tools**:\n  - Python 3.10+\n  - Node.js (for front-end)\n\n## Setup Instructions\n\n1. **Clone the Repository**:\n\t```bash\n\tgit clone https://github.com/afelix-95/genai-rag-app.git\n\tcd genai-rag-app\n\t```\n\n2. **Configure Azure Services**:\n\t- Set up Azure AI Search and Azure Functions resources.\n\n3. **Set Up Environment Variables**:\n\t- Copy `.env.example` to `.env` and fill in credentials for Azure AI Search and OpenAI.\n\n4. **Install Dependencies**:\n\t- Python: `pip install -r requirements.txt`\n\t- Front-end: `npm install` (if using React/JS)\n\n5. **Run Locally**:\n\t- Start the API server: `uvicorn api.main:app --reload`\n\t- Open the front-end in your browser: `http://localhost:8000/` (served by the API)\n\n6. **Deploy**:\n\t- **Azure Functions (API)**: The API is configured for Azure Functions deployment. Use the GitHub Actions workflow in `.github/workflows/deploy-functions.yml` for automated deployment.\n\t- **Azure Static Web Apps (Frontend)**: The frontend can be deployed separately to Azure Static Web Apps using the workflow in `.github/workflows/deploy-static-web-app.yml`.\n\t- **Manual Deployment**: Use Azure CLI or Azure Portal to deploy the Azure Functions app.\n\t- **Secrets Setup**: In your GitHub repository, add the following secrets:\n\t\t- `AZUREAPPSERVICE_PUBLISHPROFILE`: Azure Functions publish profile\n\t\t- `AZURE_STATIC_WEB_APPS_API_TOKEN`: Azure Static Web Apps deployment token\n\n## CI/CD and Deployment\n\nThis project uses GitHub Actions for automated deployment to Azure:\n\n- **Azure Functions (API Backend)**: Successfully deployed to `psi20expertapp` in Canada Central region\n- **Workflow**: `.github/workflows/main_psi20expertapp.yml` handles build and deployment\n- **Deployment Method**: Uses Azure CLI zip deployment\n\n### Deployment Steps\n\n1. **Set up Azure Resources**:\n   - Azure Functions app\n   - Azure AI Search service\n   - Azure OpenAI service with deployments for (recommended):\n     - `gpt-4.1-mini` (chat completions)\n     - `gpt-4o-mini-tts` (text-to-speech)\n     - `text-embedding-3-small` (embeddings)\n\n2. **Configure Environment Variables in Azure**:\n   ```bash\n   az functionapp config appsettings set --name your-app-name --resource-group your-resource-group --settings \\\n     AZURE_SEARCH_ENDPOINT=\"your-search-endpoint\" \\\n     AZURE_SEARCH_API_KEY=\"your-search-key\" \\\n     AZURE_SEARCH_INDEX=\"your-index-name\" \\\n     AZURE_OPENAI_API_KEY=\"your-openai-key\" \\\n     AZURE_OPENAI_ENDPOINT=\"your-openai-endpoint\" \\\n     CHAT_MODEL_NAME=\"your-llm-model\" \\\n     TTS_MODEL_NAME=\"your-tts-model\" \\\n     EMBEDDING_MODEL_NAME=\"your-embedding-model\"\n   ```\n\n3. **Deploy**:\n   - Push to `main` branch to trigger automated deployment\n   - Or run: `az functionapp deployment source config-zip --name psi20expertapp --resource-group psi20expertapp_group --src .`\n\n4. **Access the Application**:\n   - Frontend: `https://psi20expertapp-g4b4b0dnceebf0fk.canadacentral-01.azurewebsites.net/`\n   - API: `https://psi20expertapp-g4b4b0dnceebf0fk.canadacentral-01.azurewebsites.net/chat`\n\n## Pipeline Workflow\n\nThe application uses **Microsoft Semantic Kernel** to orchestrate the end-to-end AI pipeline:\n\n1. **User Query**: User submits a question via the front-end chat interface.\n2. **Semantic Kernel Orchestration**:\n   - Kernel invokes `RAGPlugin.ProcessRAGQuery` to retrieve relevant document snippets from Azure AI Search and generate contextual responses using GPT-4.1-mini\n   - Kernel invokes `RAGPlugin.TextToSpeech` to synthesize speech audio (MP3) from the response text using GPT-4o-mini-tts\n3. **Response**: API returns both text and base64-encoded audio data to the front-end for display and playback.\n\n### Technical Implementation\n\n- **Plugin Architecture**: Custom RAGPlugin encapsulates AI operations as kernel functions\n- **Service Integration**: Azure OpenAI services are registered with the kernel for unified access\n- **Async Processing**: All operations are handled asynchronously for optimal performance\n- **Error Handling**: Kernel provides structured error handling and logging\n\n## Dependencies\n\n- **Python**: See `requirements.txt` for backend dependencies (FastAPI, openai, python-dotenv, uvicorn, pytest, semantic-kernel)\n- **Node.js**: See `package.json` for front-end dependencies (minimal setup for static serving)\n\n## Monitoring and Outputs\n\n- **Azure Portal**: Monitor Azure Functions and AI Search usage, logs, and performance.\n- **API Logs**: Check FastAPI logs for errors and request traces.\n- **Front-end**: View chat and TTS playback in browser.\n\n## Troubleshooting\n\n- **Authentication Errors**: Verify environment variables and Azure credentials.\n- **Search/Model Issues**: Ensure Azure AI Search index is populated and OpenAI credentials are valid.\n- **TTS Audio Not Playing**: Check browser console for errors; ensure base64 audio data is being received.\n- **Semantic Kernel Errors**: Check kernel initialization and plugin registration; verify Azure OpenAI service configuration.\n- **Favicon 404 Errors**: These are normal and handled by returning 204 No Content to prevent repeated requests.\n- **Deployment Errors**: Check Azure Functions logs and configuration.\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafelix-95%2Fgenai-rag-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafelix-95%2Fgenai-rag-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafelix-95%2Fgenai-rag-app/lists"}