langchain-learning/README.md
2026-04-12 17:39:33 +08:00

84 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# LangChain Learning
[![](https://img.shields.io/badge/version-0.0.1-blue.svg)](https://github.com/your-repo/langchain-learning)
[![](https://img.shields.io/badge/python-3.11+-green.svg)](https://www.python.org/)
[![](https://img.shields.io/badge/LangChain-v1.2-orange.svg)](https://www.langchain.com/)
> LangChain 框架学习项目,集成 SiliconFlow API
## 功能特性
- **多 LLM 集成**:支持 OpenAI API、SiliconFlow 及 LangChain 抽象层
- **流式响应**:实时流式输出,带来更好的使用体验
- **实战示例**:从基础到进阶的使用模式
## 快速开始
### 1. 安装依赖
```bash
pip install langchain>=1.2.15 langchain-community>=0.4.1 langchain-siliconflow>=1.0.0 requests>=2.33.1
```
### 2. 配置环境变量
在项目根目录创建 `.env` 文件:
```env
SILICONFLOW_API_KEY=your_api_key_here
SILICONFLOW_BASE_URL=https://api.siliconflow.cn/v1
```
### 3. 运行示例
**直接调用 APIrequests**
```bash
python helloworld/helloworld.py
```
**LangChain + ChatOpenAI 接口**
```bash
python helloworld/helloworld_langchain_openai.py
```
**LangChain + ChatSiliconFlow**
```bash
python helloworld/helloworld_siliconflow.py
```
**OpenAI 客户端 + SiliconFlow**
```bash
python helloworld/openai_siliconflow.py
```
## 项目结构
```
langchain-learning/
├── helloworld/
│ ├── helloworld.py # 直接调用 SiliconFlow API
│ ├── helloworld_langchain_openai.py # LangChain + ChatOpenAI
│ ├── helloworld_siliconflow.py # LangChain + ChatSiliconFlow
│ └── openai_siliconflow.py # OpenAI 客户端 + SiliconFlow
├── main.py # 入口文件
├── pyproject.toml # 项目配置
└── README.md
```
## 可用模型
- `deepseek-ai/DeepSeek-R1-0528-Qwen3-8B`
- `Qwen/Qwen3.5-4B`
## 技术栈
| 类别 | 技术 |
|------|------|
| 框架 | LangChain |
| LLM 提供商 | SiliconFlow |
| 语言 | Python 3.11+ |
## 许可证
MIT License