A Streamlit-based intelligent chat application that integrates Azure OpenAI and Azure Cognitive Search services to provide document-based question answering capabilities.
- Direct Chat Interface: Direct conversation with Azure OpenAI GPT models
- Document Search & Chat: Question-answering based on indexed documents using Azure Cognitive Search
- Multi-Purpose Templates: Pre-configured for antenna parts selection and IT helpdesk scenarios
- Configuration Management: Web-based settings panel for Azure service configuration
- Index Management: Built-in tools to create and manage Azure Cognitive Search indexes
- Home: Basic chat interface using Azure OpenAI directly
- Settings: Configuration panel for Azure services and index management
- Upload File: File upload functionality (placeholder)
- Chat: Advanced chat with document search capabilities using Cognitive Search
webapp.py: Main Streamlit application with user interfacecog_search.py: Azure Cognitive Search integration and OpenAI helperscredentials.py: Configuration settings and service credentialsrequirements.txt: Python dependencies
-
Azure OpenAI Service
- Deployed GPT-35-Turbo model
- Text-Davinci-003 model
- API endpoint and access keys
-
Azure Cognitive Search
- Search service instance
- API keys with admin permissions
-
Azure Storage Account
- Blob storage container for documents
- Connection string and access keys
-
Azure Cognitive Services
- Multi-service cognitive services resource
- API keys for text processing
-
Clone the repository
git clone https://github.com/memasanz/streamlitsearchapp.git cd streamlitsearchapp -
Install dependencies
pip install streamlit pip install streamlit-chat pip install streamlit-option-menu pip install openai pip install langchain pip install faiss-cpu pip install transformers pip install pandas pip install numpy pip install requests
-
Configure Azure services
Edit
credentials.pywith your Azure service details:# Azure OpenAI Configuration AZURE_OPENAI_ENDPOINT = "https://your-openai-service.openai.azure.com/" AZURE_OPENAI_KEY = "your-openai-api-key" # Azure Cognitive Search Configuration COG_SEARCH_RESOURCE = "your-search-service-name" COG_SEARCH_KEY = "your-search-api-key" COG_SEARCH_INDEX = "your-index-name" # Azure Storage Configuration STORAGE_CONNECTION_STRING = "your-storage-connection-string" STORAGE_ACCOUNT = "your-storage-account-name" STORAGE_KEY = "your-storage-key"
streamlit run webapp.pyThe application will start on http://localhost:8501
- Configure Services: Navigate to the "Settings" tab and enter your Azure service credentials
- Create Search Index: Use the "Create Index" button to set up your Cognitive Search index
- Upload Documents: Upload documents to your Azure Storage container for indexing
- Simple conversation interface with Azure OpenAI
- Uses GPT-35-Turbo model for responses
- No document context - general purpose chat
- Ask questions about your uploaded documents
- Uses Cognitive Search to find relevant content
- Combines search results with OpenAI for comprehensive answers
The application includes pre-configured templates for specific use cases:
XTG_TEMPPLATE_ORIG = """
You are an antenna part selector chat bot.
You are given sections of a catalog of antennas.
Each document section includes the part number at the beginning...
"""TTEC_questiontemplate = """
You are an IT HelpDesk Chat Bot.
You are to answer questions based on the context provided...
"""- GPT-35-Turbo: For chat conversations
- Text-Davinci-003: For document-based Q&A
- Text-Search-Curie: For embeddings and similarity search
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Streamlit UI │────│ Azure OpenAI │────│ Azure Cognitive│
│ │ │ │ │ Search │
│ - Chat Interface│ │ - GPT Models │ │ │
│ - Settings │ │ - Embeddings │ │ - Document Index│
│ - File Upload │ │ - Text Generation│ │ - Search & Rank │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
└────────────────────────┼────────────────────────┘
│
┌──────────────────┐
│ Azure Storage │
│ │
│ - Document Store │
│ - Blob Container │
└──────────────────┘
The application provides built-in tools to:
- Create data sources pointing to your Azure Storage
- Set up cognitive skillsets for document processing
- Create and configure search indexes
- Run indexers to process and index documents
- Chat history is maintained in Streamlit session state
- Settings can be updated dynamically
- Message reset functionality available
-
Authentication Errors
- Verify Azure service credentials in
credentials.py - Ensure API keys have proper permissions
- Check endpoint URLs are correct
- Verify Azure service credentials in
-
Search Not Working
- Confirm Cognitive Search index exists
- Verify documents are uploaded to storage container
- Check indexer has run successfully
-
Chat Responses Incomplete
- Increase
max_tokensin OpenAI configuration - Verify model deployment names match configuration
- Increase
Set DEBUG = "1" in credentials.py to enable additional logging.
- Never commit actual API keys to version control
- Use environment variables for production deployments
- Regularly rotate API keys and connection strings
- Implement proper access controls for Azure resources
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is provided as-is for demonstration purposes. Please ensure compliance with Azure service terms and conditions.
For issues and questions:
- Check the troubleshooting section above
- Review Azure service documentation
- Open an issue in the GitHub repository