A practice project built with LangChain, Pydantic, and Streamlit to demonstrate prompt-based routing, parallel response generation, structured output, and a simple chat interface.
This project implements an AI tutor chatbot where the user can select a response category and an explanation level before asking a question.
The chatbot supports three response categories:
- General Intuition — prioritizes theoretical and general explanations.
- Programming Intuition — prioritizes programming concepts, approaches, code, and short explanations.
- Mathematical Intuition — prioritizes mathematical concepts, terminology, equations, and explanations alongside equations.
The user can also select an explanation level:
- Beginner-Friendly
- Intermediate
- Deep Intuition
The application uses ChatGroq as the chat model and provides a Streamlit-based interface with chat history.
- Chatbot interface built with Streamlit.
- User-selectable response category.
- User-selectable explanation level.
PromptTemplatefor constructing prompts.RunnableBranchfor category-based routing.RunnableParallelfor generating answer and summary outputs simultaneously.- Pydantic structured output using
PydanticOutputParser. - Chat history maintained with Streamlit session state.
- API credentials loaded through environment variables.
The project uses separate PromptTemplate objects for the three response categories. Each template receives the user's question, selected category, selected explanation level, and chat history as dynamic inputs.
This keeps prompt construction separate from model invocation and allows the chatbot to change its behavior according to the user's selections.
RunnableBranch routes the user's request according to the selected response category.
Programming Intuition → Programming Chain
Mathematical Intuition → Mathematical Chain
General Intuition → General Chain
The implementation checks category_input and selects the corresponding prompt chain.
RunnableParallel is used to run two response pipelines from the same user request:
User Question
│
▼
RunnableParallel
┌───────┴───────┐
▼ ▼
Summary Answer
Both outputs are generated through the conditional response chain and parsed into the project's structured Pydantic response format.
The project defines a Response Pydantic model containing:
answersummaryconfidencecategorykeywords
PydanticOutputParser is used to validate model output against this schema.
GenAi-Assignment-1/
│
├── app.py # Streamlit application and chatbot flow
├── chatbot.py # ChatGroq model configuration
├── prompts.py # PromptTemplate definitions
├── schemas.py # Pydantic response schema and output parsers
├── requirements.txt # Python dependencies
├── .env.example # Example environment-variable configuration
├── .gitignore # Ignores the local .env file
└── README.md # Project documentation
- Python
- LangChain
- LangChain Core
- ChatGroq
- Pydantic
- Streamlit
- python-dotenv
git clone https://github.com/FuadTasin/GenAi-Assignment-1.git
cd GenAi-Assignment-1python -m venv .venvActivate it on macOS/Linux:
source .venv/bin/activateOn Windows:
.venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root and add the API key required by the ChatGroq configuration.
Do not commit the .env file. The repository's .gitignore excludes .env.
streamlit run app.pyThe application follows this general workflow:
User Question
│
├── Response Category
│
└── Explanation Level
│
▼
RunnableBranch
┌──────┼──────┐
▼ ▼ ▼
General Math Programming
└──────┼──────┘
▼
RunnableParallel
┌───┴───┐
▼ ▼
Summary Answer
└───┬───┘
▼
Pydantic Structured Output
│
▼
Streamlit Chat UI
The application also keeps the conversation in st.session_state.chat_history and passes the history into the response prompts so previous conversation context can be considered.
This project was created primarily as a practice/learning assignment to understand and demonstrate LangChain Runnable components, prompt templates, Pydantic structured output, and Streamlit integration.
It is intentionally a relatively simple chatbot rather than a production-ready application.
- Chat model
- PromptTemplate
- Pydantic Structured Output
- RunnableBranch
- RunnableParallel
- Streamlit chat interface
- Chat history
-
requirements.txt -
.envexcluded from Git
Fuad Tasin
GitHub: https://github.com/FuadTasin