# Code-Teacher **Repository Path**: shishangyiwugu/Code-Teacher ## Basic Information - **Project Name**: Code-Teacher - **Description**: 基于 Streamlit + Ollama + MySQL 的本地私有化 AI 编程助手,专注代码解析与多轮对话。 - **Primary Language**: Python - **License**: GPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-22 - **Last Updated**: 2026-07-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: Agent ## README # Code Teacher 编程智能体 一个基于 **Streamlit + Ollama** 的本地编程助手,面向“代码讲解 + 工程实践”的问答场景。支持多轮对话、自动持久化聊天记录到 **MySQL**,适合本地私有化部署与二次定制。 ## 功能特性 - **编程智能体提示词**:更聚焦代码解释、排错与最佳实践 - **Streamlit 聊天 UI**:轻量上手、交互直观 - **MySQL 持久化**:自动建库建表,支持断线续聊 - **Modelfile 可替换**:快速定制/更换本地模型 ## 技术栈 - 前端:Streamlit - 模型:Ollama(本地模型) - 存储:MySQL(pymysql) ## 目录结构 ``` . ├── main.py ├── src │ ├── app.py │ ├── services │ │ └── llm_client.py │ └── storage │ ├── db_config.py │ └── db_utils.py ├── resources │ └── ollama │ └── Modelfile ├── docs │ └── apifox │ └── Ollama.apifox.json └── LICENSE ``` ## 环境要求 - Python 3.10+ - MySQL 8+(或兼容版本) - Ollama 已安装并启动 ## 快速开始 1. 安装依赖: ``` pip install streamlit ollama pymysql ``` 2. 修改数据库配置(默认连接本地 MySQL): `src/storage/db_config.py` 3. 创建本地模型(可选,使用默认 Modelfile): ``` ollama create code-teacher -f resources/ollama/Modelfile ``` 4. 启动应用: ``` streamlit run main.py ``` ## 使用方式 - 在输入框直接提问:编程问题、代码片段、报错信息 - 助手会返回讲解、排查思路与可运行示例 - 历史对话保存到 `chat_messages` 表,重启后可继续对话 ## 可配置项 | 位置 | 说明 | | ---------------------------------------- | ------------------------- | | `src/services/llm_client.py` | 模型名、系统提示词 | | `src/app.py` | UI 标题、欢迎语、提示文案 | | `get_response_list(..., max_history=20)` | 对话历史窗口大小 | | `src/storage/db_config.py` | MySQL 连接配置 | ## 数据库说明 应用启动时会自动创建数据库与表结构(若不存在),主要表: - `chat_messages`:存储角色、内容与时间戳 ## 许可证 本项目遵循 MIT License 开源协议