Refactor project structure for better organization
- Move notebooks to dedicated notebooks/ directory - Create src/ directory for reusable code (utils/, chains/) - Add tests/ directory for unit tests - Add comprehensive .gitignore file - Update CLAUDE.md and README.md with new structure - Remove old app/ directory 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
06e205111e
commit
00d56a267d
|
|
@ -3,7 +3,10 @@
|
||||||
"allow": [
|
"allow": [
|
||||||
"Bash(git init:*)",
|
"Bash(git init:*)",
|
||||||
"Bash(git remote add:*)",
|
"Bash(git remote add:*)",
|
||||||
"Bash(git add:*)"
|
"Bash(git add:*)",
|
||||||
|
"Bash(git commit:*)",
|
||||||
|
"Bash(git push:*)",
|
||||||
|
"Bash(tree:*)"
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
*.so
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# Virtual Environment
|
||||||
|
venv/
|
||||||
|
env/
|
||||||
|
ENV/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
*.ipynb_checkpoints
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Data
|
||||||
|
data/*
|
||||||
|
!data/.gitkeep
|
||||||
|
|
||||||
|
# Models
|
||||||
|
models/*
|
||||||
|
!models/.gitkeep
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# FAISS indexes
|
||||||
|
*.faiss
|
||||||
|
*.index
|
||||||
25
CLAUDE.md
25
CLAUDE.md
|
|
@ -26,11 +26,23 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||||
## 代码结构
|
## 代码结构
|
||||||
|
|
||||||
### 目录组织
|
### 目录组织
|
||||||
- `/app/demo/`: 包含演示代码的 Jupyter notebook
|
```
|
||||||
- `demo1.ipynb`: 主要演示文件,包含 7 个核心示例
|
lang-demo1/
|
||||||
- `/models/`: 模型相关文件(目前为空)
|
├── notebooks/ # 学习笔记和示例
|
||||||
- `/data/`: 数据文件(目前为空)
|
│ ├── demo1.ipynb # 主要演示: LLM调用、提示词、解析器、向量、RAG、Agent
|
||||||
- `sample.ipynb`: 根目录的示例 notebook,展示环境配置和基础模型调用
|
│ └── sample.ipynb # 环境配置和基础调用示例
|
||||||
|
├── src/ # 可复用的源代码
|
||||||
|
│ ├── utils/ # 工具函数
|
||||||
|
│ └── chains/ # 自定义链
|
||||||
|
├── tests/ # 单元测试
|
||||||
|
├── data/ # 数据文件
|
||||||
|
├── models/ # 模型文件
|
||||||
|
├── .env # 环境变量 (不提交到 Git)
|
||||||
|
├── .gitignore # Git 忽略配置
|
||||||
|
├── requirements.txt # Python 依赖
|
||||||
|
├── README.md # 项目说明
|
||||||
|
└── CLAUDE.md # 本文件
|
||||||
|
```
|
||||||
|
|
||||||
### 核心功能模块
|
### 核心功能模块
|
||||||
|
|
||||||
|
|
@ -83,7 +95,8 @@ chain = prompt | llm
|
||||||
### 运行 Jupyter Notebooks
|
### 运行 Jupyter Notebooks
|
||||||
主要开发工作在 Jupyter notebook 中进行:
|
主要开发工作在 Jupyter notebook 中进行:
|
||||||
- 启动 Jupyter: `jupyter notebook` 或 `jupyter lab`
|
- 启动 Jupyter: `jupyter notebook` 或 `jupyter lab`
|
||||||
- 主要演示代码位于 `app/demo/demo1.ipynb`
|
- 主要演示代码位于 `notebooks/demo1.ipynb`
|
||||||
|
- 基础示例位于 `notebooks/sample.ipynb`
|
||||||
|
|
||||||
### 环境初始化模式
|
### 环境初始化模式
|
||||||
代码使用严格的环境变量检查:
|
代码使用严格的环境变量检查:
|
||||||
|
|
|
||||||
98
README.md
98
README.md
|
|
@ -1 +1,97 @@
|
||||||
**1** 开始
|
# LangChain 学习项目
|
||||||
|
|
||||||
|
这是一个 LangChain 学习演示项目,涵盖了从基础调用到高级应用(RAG、Agent)的完整示例。
|
||||||
|
|
||||||
|
## 项目结构
|
||||||
|
|
||||||
|
```
|
||||||
|
lang-demo1/
|
||||||
|
├── notebooks/ # Jupyter 学习笔记
|
||||||
|
│ ├── demo1.ipynb # 核心示例(7个主题)
|
||||||
|
│ └── sample.ipynb # 基础示例
|
||||||
|
├── src/ # 可复用代码
|
||||||
|
│ ├── utils/ # 工具函数
|
||||||
|
│ └── chains/ # 自定义链
|
||||||
|
├── tests/ # 单元测试
|
||||||
|
├── data/ # 数据文件
|
||||||
|
└── models/ # 模型文件
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 1. 安装依赖
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
主要依赖:
|
||||||
|
- `langchain` - LangChain 核心库
|
||||||
|
- `langchain-openai` - OpenAI 集成
|
||||||
|
- `langchain-community` - 社区工具
|
||||||
|
- `faiss-cpu` - 向量数据库
|
||||||
|
- `python-dotenv` - 环境变量管理
|
||||||
|
|
||||||
|
### 2. 配置环境变量
|
||||||
|
|
||||||
|
在项目根目录创建 `.env` 文件:
|
||||||
|
|
||||||
|
```env
|
||||||
|
# OpenAI API 配置
|
||||||
|
OPENAI_BASE_URL=你的API地址
|
||||||
|
OPENAI_API_KEY1=你的API密钥
|
||||||
|
|
||||||
|
# LangSmith 追踪配置(可选)
|
||||||
|
LANGSMITH_TRACING=true
|
||||||
|
LANGSMITH_API_KEY=你的LangSmith密钥
|
||||||
|
LANGSMITH_PROJECT=你的项目名
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 运行示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
jupyter notebook
|
||||||
|
# 或
|
||||||
|
jupyter lab
|
||||||
|
```
|
||||||
|
|
||||||
|
然后打开 `notebooks/demo1.ipynb` 开始学习。
|
||||||
|
|
||||||
|
## 学习内容
|
||||||
|
|
||||||
|
### 1. 基础 LLM 调用
|
||||||
|
使用 `ChatOpenAI` 进行基本的模型调用
|
||||||
|
|
||||||
|
### 2. 提示词模板
|
||||||
|
使用 `ChatPromptTemplate` 创建结构化提示词
|
||||||
|
|
||||||
|
### 3. 输出解析器
|
||||||
|
使用 `JsonOutputParser` 将输出解析为 JSON 格式
|
||||||
|
|
||||||
|
### 4. 向量存储
|
||||||
|
使用 FAISS 向量数据库存储和检索文档
|
||||||
|
|
||||||
|
### 5. RAG (检索增强生成)
|
||||||
|
结合向量检索和 LLM 实现知识问答
|
||||||
|
|
||||||
|
### 6. Agent 系统
|
||||||
|
使用 LangChain Agent 实现工具调用和自主决策
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
- **LLM**: GPT-4.1-nano (通过 OpenAI 兼容接口)
|
||||||
|
- **Embeddings**: text-embedding-3-small
|
||||||
|
- **向量数据库**: FAISS
|
||||||
|
- **Web 抓取**: BeautifulSoup4
|
||||||
|
- **开发环境**: Jupyter Notebook/Lab
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 代码中使用 `OPENAI_API_KEY1` 而不是标准的 `OPENAI_API_KEY`
|
||||||
|
- 向量数据存储在内存中,未做持久化
|
||||||
|
- `.env` 文件包含敏感信息,已在 `.gitignore` 中排除
|
||||||
|
|
||||||
|
## 学习资源
|
||||||
|
|
||||||
|
- [LangChain 官方文档](https://python.langchain.com/)
|
||||||
|
- [LangChain 中文文档](https://www.langchain.com.cn/)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue