Skip to content

[Bug]: Chatbot not work - #281

Merged
omroy07 merged 2 commits into
omroy07:mainfrom
Techhackontime999:fix/chatbot-not-working
Sep 12, 2026
Merged

omroy07 merged 2 commits into
omroy07:mainfrom
Techhackontime999:fix/chatbot-not-working

Conversation

@Techhackontime999

Copy link
Copy Markdown
Contributor

Summary

Fixes the AI Tutor chatbot not working (#266). Root causes were verified across the frontend, backend, and container setup:

  • .env was never loaded — chatbot.py read GEMINI_API_KEY from the environment without calling load_dotenv(), so the documented cp .env.example .env workflow crashed at startup.
  • Default model was retired — the server defaulted to gemini-1.5-pro, which Google discontinued in 2025. Every request 404'd, hidden by the generic except.
  • Frontend couldn't reach the backend — home.js hardcoded http://127.0.0.1:5000 (broke over HTTPS/Docker) and review.js used a relative fetch(\"/chat\") that only existed on the Flask-served page (404 on the static host).
  • No chatbot in Docker — docker-compose.yml/Dockerfile shipped nginx static files only; no Flask service, no proxy for /chat.
  • Standalone page rendered undefined — templates/index.html had no response.ok handling and used onkeypress/unchecked innerHTML.

Changes

File What
chatbot.py Call load_dotenv(); default model gemini-2.5-flash; bind 0.0.0.0
.env.example Document GEMINI_MODEL; update API-key URL
chatbotConfig.js (new) Single configurable backend URL (default keeps local workflow)
chatbotApi.js (new) Shared window.chatbotPost helper used by home.js + review.js
home.js, review.js Use shared helper instead of hardcoded/mismatched URLs
home.html, review.html, review_mistakes.html Load config + API helper
vite.config.js Dev proxy for /chat and /explain_mistake
nginx.conf (new), Dockerfile Proxy AI Tutor routes to the chatbot container
Dockerfile.chatbot (new), docker-compose.yml Add the Flask chatbot service
templates/index.html response.ok handling, safe rendering, keydown listener

Verification

  • node --check passes on all modified/new JS files
  • python -m py_compile chatbot.py passes
  • Local workflow unchanged: python chatbot.py + open the site; optional npm run dev proxy path added

Closes #266

- Load .env via python-dotenv so 'cp .env.example .env' works (was exiting at startup)
- Default to a current Gemini model (gemini-2.5-flash); document GEMINI_MODEL
- Centralize the backend URL (chatbotConfig.js/chatbotApi.js) and use it from
  home.js and review.js — fixes hardcoded 127.0.0.1 URLs and the relative /chat 404
- Add a Vite dev proxy and nginx proxy for /chat and /explain_mistake
- Add the Flask chatbot service to Docker (Dockerfile.chatbot + docker-compose)
- Harden templates/index.html: response.ok handling, textContent, no onkeypress
- Bind Flask to 0.0.0.0 so containers / remote hosts can reach it

Closes omroy07#266
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

@Techhackontime999 is attempting to deploy a commit to the Om Roy's projects Team on Vercel.

A member of the Team first needs to authorize it.

google-generativeai depends on grpcio, whose native DLL is blocked by
Windows Application Control (WDAC) policies on some systems (verified:
'DLL load failed ... Application Control policy has blocked this file').

google-genai talks to Gemini over HTTPS (httpx) with no gRPC dependency,
so the AI Tutor runs on those machines too. It is also the SDK Google
recommends going forward and supports current models like gemini-3.5-flash.
@omroy07
omroy07 merged commit 76c2df3 into omroy07:main Sep 12, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Chatbot not work - 20

2 participants