A serverless Azure Functions application built with TypeScript that provides a chat interface powered by Azure OpenAI and RAG (Retrieval-Augmented Generation) capabilities.
- Serverless Architecture: Built on Azure Functions for scalable, cost-effective deployment
- RAG Integration: Connects to Azure RAG endpoint for enhanced AI responses
- TypeScript: Fully typed for better development experience and code reliability
- HTTP Triggered: RESTful API endpoint for chat interactions
- Error Handling: Comprehensive error handling and logging
- Node.js (v18 or later)
- Azure Functions Core Tools
- Azure CLI (for deployment)
- Azure subscription with access to:
- Azure Functions
- Azure OpenAI Service
- Azure RAG endpoint
-
Clone the repository
git clone <repository-url> cd azure-openai-fn
-
Install dependencies
npm install
-
Configure environment variables
Create a
.env
file in the root directory:AZURE_RAG_ENDPOINT=<your-rag-endpoint-url> AZURE_RAG_API_KEY=<your-rag-api-key>
-
Build the project
npm run build
-
Start the function app locally
npm start
-
Test the endpoint
The chat handler will be available at:
POST http://localhost:7071/api/chatHandler
Example request:
{ "message": "Hello, how can you help me?" }
Example response:
{ "answer": "I'm an AI assistant powered by Azure OpenAI..." }
azure-openai-fn/
├── src/
│ └── functions/
│ └── chatHandler.ts # Main chat function handler
├── host.json # Azure Functions host configuration
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
npm run build
- Compile TypeScript to JavaScriptnpm run watch
- Watch for changes and recompilenpm run clean
- Remove compiled outputnpm start
- Build and start the function locallynpm test
- Run tests (placeholder)
Chat with the AI assistant using RAG-enhanced responses.
Request Body:
{
"message": "Your question or message here"
}
Response:
{
"answer": "AI-generated response"
}
Error Responses:
400 Bad Request
- Invalid JSON or missing message500 Internal Server Error
- RAG endpoint error or server issue
-
Login to Azure
az login
-
Create a Function App
az functionapp create \ --resource-group <resource-group-name> \ --consumption-plan-location <location> \ --runtime node \ --runtime-version 18 \ --functions-version 4 \ --name <function-app-name> \ --storage-account <storage-account-name>
-
Configure application settings
az functionapp config appsettings set \ --name <function-app-name> \ --resource-group <resource-group-name> \ --settings \ AZURE_RAG_ENDPOINT=<your-rag-endpoint> \ AZURE_RAG_API_KEY=<your-rag-api-key>
-
Deploy the function
func azure functionapp publish <function-app-name>
- API Keys: Store sensitive information like API keys in Azure Key Vault or Function App settings
- Authentication: Consider implementing authentication for production use
- CORS: Configure CORS settings if accessed from web applications
- Rate Limiting: Implement rate limiting to prevent abuse
The function app includes:
- Application Insights integration for monitoring
- Structured logging for debugging
- Error tracking and performance metrics
Monitor your function in the Azure portal under:
- Function App → Monitor
- Application Insights → Logs
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Build Errors
- Ensure TypeScript is installed:
npm install -g typescript
- Check Node.js version compatibility
- Ensure TypeScript is installed:
-
Function Not Starting
- Verify Azure Functions Core Tools installation
- Check
host.json
configuration
-
RAG Endpoint Errors
- Verify endpoint URL and API key
- Check network connectivity
- Review Azure OpenAI service status
-
Environment Variables
- Ensure
.env
file is in the root directory - Check variable names match exactly
- Ensure
- Check the Azure Functions documentation
- Review Azure OpenAI documentation
- Open an issue in this repository
Built with ❤️ using Azure Functions and TypeScript