Skip to content
ุงู„ู…ุดุงุฑูŠุน

ุญูˆู„

๐Ÿณ StudyMate ๐Ÿฌ AI ๐Ÿฆ‹ LangChain ๐ŸนChatbot ๐Ÿ™ is ๐ŸŒบ an ๐Ÿ’ AI ๐Ÿต powered ๐ŸŽ educational ๐Ÿ‹ assistant ๐Ÿ built ๐Ÿซ‘ with LangChain ๐Ÿ‘ and ๐Ÿ” Large ๐ŸŒฐ Language ๐ŸŒฝ Models ๐Ÿšƒ to โœˆ deliver ๐Ÿš€ personalized ๐Ÿ›ซ context ๐Ÿ›ธ aware ๐ŸšŸ and ๐Ÿš  interactive ๐Ÿšข learning ๐Ÿ›ผ experiences ๐Ÿš

ุงู„ุชุนู„ู‘ู… ูˆุงู„ุชุนู„ูŠู…

ูƒูŠู ุชูู‚ุงุณ ู‡ุฐู‡ ุงู„ุฃุฑู‚ุงู…

57 ู†ุฌู…ุฉ0 ุงู„ุชูุฑุนุงุช +7 ุฎู„ุงู„ 24 ุณุงุนุฉ

ู…ุง ูŠู…ูƒู†ูƒ ูุนู„ู‡

  • Streamlit chat interface with conversation history
  • Groq chat model configured through a .env file
  • PromptTemplate objects with dynamic question and history variables
  • Programming, mathematics, and general routes with RunnableBranch

ุงู„ู†ู…ูˆ ุงู„ู…ู‚ุงุณ ู„ู„ู†ุฌูˆู…

ุฎู„ุงู„ 24 ุณุงุนุฉ
+ูง
ุฎู„ุงู„ 7 ุฃูŠุงู…
ุฌุงุฑู ุฌู…ุน ุงู„ุณุฌู„
ุฎู„ุงู„ 15 ูŠูˆู…ู‹ุง
ุฌุงุฑู ุฌู…ุน ุงู„ุณุฌู„
ุฎู„ุงู„ ุดู‡ุฑ
ุฌุงุฑู ุฌู…ุน ุงู„ุณุฌู„

ุชุบูŠู‘ุฑ ุตุงููŠ ุงู„ู†ุฌูˆู… ุฎู„ุงู„ ูุชุฑุงุช ู…ุชุฏุงุฎู„ุฉุŒ ูˆู„ูŠุณ ู…ุฌู…ูˆุนู‹ุง ูŠูˆู…ูŠู‹ุง. ุชุจู‚ู‰ ุงู„ู‚ูŠุงุณุงุช ุงู„ู…ูู‚ูˆุฏุฉ ูุงุฑุบุฉ. ุงู„ู†ุฌูˆู… ุชู‚ูŠุณ ุงู„ุงู‡ุชู…ุงู… ู„ุง ุฌูˆุฏุฉ ุงู„ุจุฑู…ุฌูŠุงุช.

StudyMate AI โ€” LangChain Chatbot

StudyMate AI is a beginner-friendly chatbot built with Streamlit and the latest LangChain Expression Language APIs. It routes questions to a specialized assistant, creates several useful outputs concurrently, and returns a validated Pydantic object.

Features

  • Streamlit chat interface with conversation history
  • Groq chat model configured through a .env file
  • PromptTemplate objects with dynamic question and history variables
  • Programming, mathematics, and general routes with RunnableBranch
  • Concurrent answer, summary, and keyword pipelines with RunnableParallel
  • Strict, validated structured output using Pydantic BaseModel
  • Optional Clear chat button
  • Friendly missing-key and API error messages

How the pipeline works

User question
     |
     v
RunnableBranch
  |-- Programming prompt
  |-- Mathematics prompt
  `-- General prompt (default)
     |
     v
RunnableParallel
  |-- Routed detailed answer
  |-- Short answer / summary
  `-- Keywords
     |
     v
Structured-output model
     |
     v
ChatbotResponse (Pydantic validation)
     |
     v
Streamlit chat UI

RunnableBranch

chatbot.py creates three prompt pipelines. Transparent keyword rules inspect the question, and RunnableBranch selects the programming or mathematics pipeline. If neither condition matches, LangChain runs the general pipeline as the default.

answer_branch = RunnableBranch(
    (_question_is("Programming"), programming_chain),
    (_question_is("Mathematics"), mathematics_chain),
    general_chain,
)

RunnableParallel

The selected detailed answer, a concise answer, and keywords all use the same user request. RunnableParallel starts these independent pipelines concurrently and returns their results in one dictionary.

parallel_outputs = RunnableParallel(
    answer=answer_branch,
    summary=summary_chain,
    keywords=keywords_chain,
    question=RunnableLambda(lambda data: data["question"]),
    category=RunnableLambda(lambda data: route_question(data["question"])),
)

Pydantic structured output

schemas.py defines ChatbotResponse with five required fields: answer, summary, confidence, category, and keywords. The Groq model is bound to this schema with with_structured_output(..., method="json_schema", strict=True). The application receives a Pydantic object and calls ChatbotResponse.model_validate as an additional validation boundary when a provider returns a dictionary.

The UI displays every field and includes an expandable JSON view so the exact validated structure is easy to inspect.

Project structure

chatbot-phitron/
|-- app.py              # Streamlit interface and chat history
|-- chatbot.py          # LangChain runnable pipeline
|-- prompts.py          # All PromptTemplate definitions
|-- schemas.py          # Pydantic response schema
|-- requirements.txt    # Pinned Python dependencies
|-- .env.example        # Safe environment variable template
|-- .gitignore          # Prevents secrets and local files being committed
`-- README.md

Installation

Python 3.10 or newer is recommended.

  1. Clone the repository and enter its directory:

    git clone <your-github-repository-url>
    cd chatbot-phitron
    
  2. Create and activate a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate
    

    On Windows PowerShell, activate it with:

    .venv\Scripts\Activate.ps1
    
  3. Install the dependencies:

    python -m pip install -r requirements.txt
    
  4. Copy the environment template:

    cp .env.example .env
    
  5. Create a key at Groq Console, then replace your_groq_api_key_here inside .env. Never commit the .env file.

Run the application

streamlit run app.py

Open the local address shown by Streamlit, normally http://localhost:8501.

Try these example questions:

  • Programming: Explain Python lists with a small example.
  • Mathematics: Solve 3x + 6 = 18 step by step.
  • General: Why is sleep important for learning?

Security

API keys are read from environment variables by python-dotenv. The real .env file and the local .venv directory are ignored by Git. Only .env.example should be committed.

ุงุณุชูƒุดู ู…ุดุงุฑูŠุน ู…ุดุงุจู‡ุฉ ูˆู…ุฑุชุจุทุฉ

ุฌุงุฑู ุงู„ุชุญู…ูŠู„โ€ฆ