add readme_zh
Browse files- examples/openai_README_zh.md +115 -0
examples/openai_README_zh.md
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
## API 服务器实现
|
3 |
+
|
4 |
+
LightRAG also provides a FastAPI-based server implementation for RESTful API access to RAG operations. This allows you to run LightRAG as a service and interact with it through HTTP requests.
|
5 |
+
LightRAG 还提供基于 FastAPI 的服务器实现,用于对 RAG 操作进行 RESTful API 访问。这允许您将 LightRAG 作为服务运行并通过 HTTP 请求与其交互。
|
6 |
+
|
7 |
+
### 设置 API 服务器
|
8 |
+
<details>
|
9 |
+
<summary>单击展开设置说明</summary>
|
10 |
+
|
11 |
+
1. 首先,确保您具有所需的依赖项:
|
12 |
+
```bash
|
13 |
+
pip install fastapi uvicorn pydantic
|
14 |
+
```
|
15 |
+
|
16 |
+
2. 设置您的环境变量:
|
17 |
+
```bash
|
18 |
+
export RAG_DIR="your_index_directory" # Optional: Defaults to "index_default"
|
19 |
+
export OPENAI_BASE_URL="Your OpenAI API base URL" # Optional: Defaults to "https://api.openai.com/v1"
|
20 |
+
export OPENAI_API_KEY="Your OpenAI API key" # Required
|
21 |
+
export LLM_MODEL="Your LLM model" # Optional: Defaults to "gpt-4o-mini"
|
22 |
+
export EMBEDDING_MODEL="Your embedding model" # Optional: Defaults to "text-embedding-3-large"
|
23 |
+
```
|
24 |
+
|
25 |
+
3. 运行API服务器:
|
26 |
+
```bash
|
27 |
+
python examples/lightrag_api_openai_compatible_demo.py
|
28 |
+
```
|
29 |
+
|
30 |
+
服务器将启动于 `http://0.0.0.0:8020`.
|
31 |
+
</details>
|
32 |
+
|
33 |
+
### API端点
|
34 |
+
|
35 |
+
API服务器提供以下端点:
|
36 |
+
|
37 |
+
#### 1. 查询端点
|
38 |
+
<details>
|
39 |
+
<summary>点击查看查询端点详情</summary>
|
40 |
+
|
41 |
+
- **URL:** `/query`
|
42 |
+
- **Method:** POST
|
43 |
+
- **Body:**
|
44 |
+
```json
|
45 |
+
{
|
46 |
+
"query": "Your question here",
|
47 |
+
"mode": "hybrid", // Can be "naive", "local", "global", or "hybrid"
|
48 |
+
"only_need_context": true // Optional: Defaults to false, if true, only the referenced context will be returned, otherwise the llm answer will be returned
|
49 |
+
}
|
50 |
+
```
|
51 |
+
- **Example:**
|
52 |
+
```bash
|
53 |
+
curl -X POST "http://127.0.0.1:8020/query" \
|
54 |
+
-H "Content-Type: application/json" \
|
55 |
+
-d '{"query": "What are the main themes?", "mode": "hybrid"}'
|
56 |
+
```
|
57 |
+
</details>
|
58 |
+
|
59 |
+
#### 2. 插入文本端点
|
60 |
+
<details>
|
61 |
+
<summary>单击可查看插入文本端点详细信息</summary>
|
62 |
+
|
63 |
+
- **URL:** `/insert`
|
64 |
+
- **Method:** POST
|
65 |
+
- **Body:**
|
66 |
+
```json
|
67 |
+
{
|
68 |
+
"text": "Your text content here"
|
69 |
+
}
|
70 |
+
```
|
71 |
+
- **Example:**
|
72 |
+
```bash
|
73 |
+
curl -X POST "http://127.0.0.1:8020/insert" \
|
74 |
+
-H "Content-Type: application/json" \
|
75 |
+
-d '{"text": "Content to be inserted into RAG"}'
|
76 |
+
```
|
77 |
+
</details>
|
78 |
+
|
79 |
+
#### 3. 插入文件端点
|
80 |
+
<details>
|
81 |
+
<summary>单击查看插入文件端点详细信息</summary>
|
82 |
+
|
83 |
+
- **URL:** `/insert_file`
|
84 |
+
- **Method:** POST
|
85 |
+
- **Body:**
|
86 |
+
```json
|
87 |
+
{
|
88 |
+
"file_path": "path/to/your/file.txt"
|
89 |
+
}
|
90 |
+
```
|
91 |
+
- **Example:**
|
92 |
+
```bash
|
93 |
+
curl -X POST "http://127.0.0.1:8020/insert_file" \
|
94 |
+
-H "Content-Type: application/json" \
|
95 |
+
-d '{"file_path": "./book.txt"}'
|
96 |
+
```
|
97 |
+
</details>
|
98 |
+
|
99 |
+
#### 4. 健康检查端点
|
100 |
+
<details>
|
101 |
+
<summary>点击查看健康检查端点详细信息</summary>
|
102 |
+
|
103 |
+
- **URL:** `/health`
|
104 |
+
- **Method:** GET
|
105 |
+
- **Example:**
|
106 |
+
```bash
|
107 |
+
curl -X GET "http://127.0.0.1:8020/health"
|
108 |
+
```
|
109 |
+
</details>
|
110 |
+
|
111 |
+
### 配置
|
112 |
+
|
113 |
+
可以使用环境变量配置API服务器:
|
114 |
+
- `RAG_DIR`: 存放RAG索引的目录 (default: "index_default")
|
115 |
+
- 应在代码中为您的特定 LLM 和嵌入模型提供商配置 API 密钥和基本 URL
|