How serkanars/langchain-chatbot-with-azureopenai works
Project type and purpose
• This is a full-stack conversational AI application:
• A Streamlit-based frontend for interactive chat.
• A Flask API backend that exposes the chatbot.
• A core “Chatbot” module wrapping LangChain and AzureOpenAI.
• A utils module for shared helper functions.
File structure
• Top-level files:
• app.py → Flask REST API
• interface.py → Streamlit UI
• chatbot.py → Chatbot class (session management, chain construction)
• utils.py → Common helper functions (e.g., text preprocessing, logging)
• No database folder implies in-memory or ephemeral session management.
• .gitignore signals standard repo hygiene.
README for additional insights
• chatbot.py creates a user session, builds a LangChain chain, and returns history.
• utils.py bundles reusable routines.
• app.py exposes endpoints for sending/receiving chat messages.
• interface.py renders a chat widget and calls the Flask API.
Main components and interactions
a. Components
1. Streamlit UI (interface.py)
2. Flask API (app.py)
3. Chatbot Core (chatbot.py)
4. Utility Layer (utils.py)
5. LangChain SDK (chain builder)
6. AzureOpenAI Service (LLM endpoint)
b. Relationships & data flow
1. User → Streamlit UI
2. UI → HTTP POST → Flask API
3. API → instantiates Chatbot class → calls utils as needed
4. Chatbot builds/interacts with a LangChain chain → dispatches request to AzureOpenAI
5. AzureOpenAI returns LLM response → chain processes → Chatbot updates session history
6. Response flows back through API → UI
c. Architectural patterns
• Layered architecture: Presentation (Streamlit), API layer (Flask), Business Logic (Chatbot), Integration (LangChain & AzureOpenAI)
• Separation of concerns: UI vs. service vs. model integration vs. utilities
• Stateless REST interface with stateful session objects in memory
d. Key technologies
• Python 3.x, Flask (REST API), Streamlit (UI)
• LangChain SDK for chain composition
• AzureOpenAI for LLM inference
Detail
• Call out any helper functions from utils as side-calls off the Chatbot.