跳到正文
GitHub·· 9 天前AI 评分12

himanshiiii03/ai-study-assistant-chatbot:基于 Java 与 Gemini API 的全栈 AI 学习问答机器人

himanshiiii03/ai-study-assistant-chatbot

AI 导读

开发者 himanshiiii03 发布全栈 AI 学习问答应用 ai-study-assistant-chatbot,前端 HTML/JS 经 Java 17+ 内置 HTTP 服务器调用 Google Gemini API,回答学习问题并将对话存入 SQLite,刷新页面可重新加载历史记录。

正文

Folders and files

NameName

Last commit message

Last commit date

backend

backend

frontend

frontend

screenshots

screenshots

.gitignore

.gitignore

README.md

README.md

A full-stack AI chatbot web app that answers study questions and saves every conversation in a SQL database.

Features

  • Chat page where you ask study questions and get simple AI explanations
  • Conversation history saved in SQLite and reloaded when you refresh the page
  • The AI remembers the last 10 messages, so follow-up questions work
  • Automatic retry when the AI service is busy

Tech Stack

  • Backend: Java 17+ (built-in HTTP server, java.net.http client)
  • Database: SQLite (via JDBC)
  • Frontend: HTML, CSS, JavaScript
  • AI: Google Gemini API
  • Libraries: Gson, sqlite-jdbc, slf4j-api

How It Works

Browser (HTML/JS) → Java server → Gemini API → reply is saved in SQLite → reply is shown in the browser.

Project Structure

backend/    Java server (Server.java)
frontend/   Chat page (index.html)
database/   SQLite file is created here at first run
lib/        Jar libraries (download steps below)

How to Run (Windows PowerShell)

  1. Install JDK 17 or newer.
  2. Get a Gemini API key from https://aistudio.google.com/apikey
  3. Download the libraries into lib/:
cd lib
curl.exe -L -o gson-2.10.1.jar https://repo1.maven.org/maven2/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar
curl.exe -L -o sqlite-jdbc-3.45.1.0.jar https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar
curl.exe -L -o slf4j-api-1.7.36.jar https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar
cd ..
  1. Set your API key (never commit it):
$env:AI_API_KEY = "your_key_here"
  1. Compile and run:
cd backend
javac -cp "../lib/*" Server.java
java -cp ".;../lib/*" Server
  1. Open http://localhost:8080 in your browser.

Notes

  • The model name is set in Server.java (MODEL). Change it if your key supports a different model.
  • The API key is read from the AI_API_KEY environment variable and is not stored in the code.

来源:GitHub · github.com