Skip to content

akash1331/prompt-flow-rag-AzureAi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure OpenAI Function App

A serverless Azure Functions application built with TypeScript that provides a chat interface powered by Azure OpenAI and RAG (Retrieval-Augmented Generation) capabilities.

🚀 Features

  • 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

📋 Prerequisites

🛠️ Installation

  1. Clone the repository

    git clone <repository-url>
    cd azure-openai-fn
  2. Install dependencies

    npm install
  3. 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>

🏃‍♂️ Local Development

  1. Build the project

    npm run build
  2. Start the function app locally

    npm start
  3. 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..."
    }

📁 Project Structure

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

🔧 Available Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm run watch - Watch for changes and recompile
  • npm run clean - Remove compiled output
  • npm start - Build and start the function locally
  • npm test - Run tests (placeholder)

🌐 API Reference

POST /api/chatHandler

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 message
  • 500 Internal Server Error - RAG endpoint error or server issue

🚀 Deployment

Deploy to Azure

  1. Login to Azure

    az login
  2. 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>
  3. 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>
  4. Deploy the function

    func azure functionapp publish <function-app-name>

🔐 Security Considerations

  • 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

🔍 Monitoring and Logging

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

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Troubleshooting

Common Issues

  1. Build Errors

    • Ensure TypeScript is installed: npm install -g typescript
    • Check Node.js version compatibility
  2. Function Not Starting

    • Verify Azure Functions Core Tools installation
    • Check host.json configuration
  3. RAG Endpoint Errors

    • Verify endpoint URL and API key
    • Check network connectivity
    • Review Azure OpenAI service status
  4. Environment Variables

    • Ensure .env file is in the root directory
    • Check variable names match exactly

Getting Help


Built with ❤️ using Azure Functions and TypeScript

About

This project has codebase for connecting to Prompt Flow in Azure AI Foundry.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published