Skip to content

Commit 539fed7

Browse files
authored
modify skill (#1055)
1 parent c2cc491 commit 539fed7

File tree

17 files changed

+533
-248
lines changed

17 files changed

+533
-248
lines changed

docs/lazyllm-skill/SKILL.md

Lines changed: 184 additions & 174 deletions
Large diffs are not rendered by default.
Lines changed: 118 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,144 @@
1-
# 工具
1+
# 内置与扩展工具(lazyllm.tools)
22

3-
提供一些内置的工具用于Agent直接调用
3+
以下工具均来自 **lazyllm.tools**,可供 Agent 直接或通过 `fc_register` 包装后调用。搜索类从 `lazyllm.tools.tools` 导入,其余从 `lazyllm.tools` 导入。
44

5-
##GoogleSearch
5+
---
66

7-
通过 Google 搜索指定的关键词。
7+
## 搜索类工具
8+
9+
### GoogleSearch
10+
11+
通过 Google Custom Search API 搜索指定关键词。
812

913
参数:
1014

1115
- custom_search_api_key (str) – 用户申请的 Google API key。
12-
- search_engine_id (str) – 用户创建的用于检索的搜索引擎 id。
13-
- timeout (int, default: 10 ) – 搜索请求的超时时间,单位是秒,默认是 10
14-
- proxies (Dict[str, str], default: None ) – 请求时所用的代理服务。格式参考 https://www.python-httpx.org/advanced/proxies
16+
- search_engine_id (str) – 用户创建的搜索引擎 id。
17+
- timeout (int, default: 10) – 请求超时时间(秒)
18+
- proxies (Dict[str, str], default: None) – 代理配置
1519

1620
```python
1721
from lazyllm.tools.tools import GoogleSearch
1822

1923
key = '<your_google_search_api_key>'
2024
cx = '<your_search_engine_id>'
21-
2225
google = GoogleSearch(custom_search_api_key=key, search_engine_id=cx)
2326
res = google(query='商汤科技', date_restrict='m1')
2427
```
2528

26-
## TencentSearch
29+
### TencentSearch
2730

28-
腾讯搜索接口封装类,用于调用腾讯云的内容搜索服务。
29-
提供对腾讯云搜索API的封装,支持关键词搜索和结果处理。
31+
腾讯云内容搜索 API 封装,支持关键词搜索与结果处理。
3032

3133
参数:
3234

33-
- secret_id (str) – 腾讯云API密钥ID,用于身份认证
34-
- secret_key (str) – 腾讯云API密钥,用于身份认证
35+
- secret_id (str) – 腾讯云 API 密钥 ID。
36+
- secret_key (str) – 腾讯云 API 密钥。
3537

3638
```python
3739
from lazyllm.tools.tools import TencentSearch
38-
secret_id = '<your_secret_id>'
39-
secret_key = '<your_secret_key>'
40-
searcher = TencentSearch(secret_id, secret_key)
40+
41+
searcher = TencentSearch(secret_id='<your_secret_id>', secret_key='<your_secret_key>')
4142
res = searcher('calculus')
4243
```
44+
45+
### 其他搜索工具
46+
47+
| 工具 | 说明 | 导入方式 |
48+
|------|------|----------|
49+
| BingSearch | Bing 搜索 | `from lazyllm.tools.tools import BingSearch` |
50+
| BochaSearch | 博查搜索 API | `from lazyllm.tools.tools import BochaSearch` |
51+
| WikipediaSearch | 维基百科检索 | `from lazyllm.tools.tools import WikipediaSearch` |
52+
| ArxivSearch | arXiv 论文检索 | `from lazyllm.tools.tools import ArxivSearch` |
53+
| StackOverflowSearch | Stack Overflow 检索 | `from lazyllm.tools.tools import StackOverflowSearch` |
54+
| SemanticScholarSearch | Semantic Scholar 学术检索 | `from lazyllm.tools.tools import SemanticScholarSearch` |
55+
| GoogleBooksSearch | Google 图书检索 | `from lazyllm.tools.tools import GoogleBooksSearch` |
56+
57+
---
58+
59+
## 通用工具
60+
61+
| 工具 | 说明 | 导入方式 |
62+
|------|------|----------|
63+
| HttpTool | 发起 HTTP 请求,可封装任意 REST API 供 Agent 调用 | `from lazyllm.tools import HttpTool` |
64+
| Weather | 天气查询 | `from lazyllm.tools.tools import Weather` |
65+
| Calculator | 数学计算 | `from lazyllm.tools.tools import Calculator` |
66+
| JsonExtractor | 从文本中提取 JSON | `from lazyllm.tools.tools import JsonExtractor` |
67+
| JsonConcentrator | 合并/聚合 JSON 结构 | `from lazyllm.tools.tools import JsonConcentrator` |
68+
69+
---
70+
71+
## SQL / 数据工具
72+
73+
### SqlManager
74+
75+
管理数据库连接与表结构,执行 SQL、获取表信息等,常与 SqlCall 配合实现自然语言转 SQL。
76+
77+
- 支持 SQLite、PostgreSQL、MySQL 等;远程库需填写 user、password、host、port。
78+
- 常用方法: `get_all_tables`, `execute_query`, `execute_commit`, `create_table`, `set_desc` 等。
79+
80+
```python
81+
from lazyllm.tools import SqlManager
82+
83+
sql_manager = SqlManager(db_path='/path/to/db.sqlite') # 或指定 user/password/host/port
84+
tables = sql_manager.get_all_tables()
85+
result = sql_manager.execute_query('SELECT * FROM t LIMIT 10')
86+
```
87+
88+
### SqlCall
89+
90+
将自然语言与表结构信息交给 LLM 生成 SQL,再通过 SqlManager 执行,适合与 ReactAgent 组合为 SQL Agent。
91+
92+
```python
93+
from lazyllm.tools import SqlManager, SqlCall, fc_register, ReactAgent
94+
95+
sql_manager = SqlManager(db_path='/path/to/db.sqlite')
96+
sql_call = SqlCall(llm, sql_manager, use_llm_for_sql_result=False) # 可选参数见 API 文档
97+
98+
@fc_register('tool')
99+
def query_db(query: str) -> str:
100+
return sql_call(query)
101+
102+
agent = ReactAgent(llm, tools=['query_db'])
103+
agent('查询销售额最高的前 5 个产品')
104+
```
105+
106+
更多示例见本目录 [basic.md](basic.md)[agent.md](agent.md),或项目主 docs 内 Cookbook(sql_agent、tabular 等)。
107+
108+
---
109+
110+
## 代码与能力类
111+
112+
### CodeGenerator
113+
114+
基于 LLM 生成代码,可与 FunctionCallAgent 等组合实现“自然语言 → 代码 → 执行”的代码 Agent。
115+
116+
```python
117+
from lazyllm.tools import CodeGenerator, FunctionCallAgent, fc_register
118+
119+
gen = CodeGenerator(llm, prompt='根据用户需求生成可执行代码,只返回代码本身。')
120+
121+
@fc_register('tool')
122+
def run_code(requirement: str) -> str:
123+
code = gen(requirement)
124+
# 可选:在沙箱中执行 code
125+
return code
126+
127+
agent = FunctionCallAgent(llm, tools=['run_code'])
128+
agent('写一个函数计算斐波那契数列前 n 项')
129+
```
130+
131+
### MCPClient
132+
133+
连接 MCP 服务器(本地或 SSE),获取 MCP 提供的工具列表,可直接作为 Agent 的 tools 使用。用法见 [基础组件 - MCPClient](../assets/agent/basic.md#4-mcpclient)
134+
135+
---
136+
137+
## 小结
138+
139+
- **搜索与通用工具**: `lazyllm.tools.tools` 中的 Search、Weather、Calculator、Json*
140+
- **SQL / 数据**: `lazyllm.tools` 的 SqlManager、SqlCall(以及 MongoDBManager、DBManager 等)。
141+
- **代码与 MCP**: `lazyllm.tools` 的 CodeGenerator、MCPClient;ToolManager、SkillManager 等见 Agent 模块文档。
142+
- **自定义工具**: 使用 `fc_register('tool')` 注册函数,见 [基础组件](../assets/agent/basic.md)
143+
144+
更多参数与用法见本页上文及 [references/agent.md](../../references/agent.md)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 在线模型平台与 API Key 环境变量
2+
3+
使用 OnlineModule 或 AutoModel 调用线上模型前,需在对应平台申请 API Key,并设置下列环境变量(断网环境下仅作配置参考;实际申请需联网访问各平台)。
4+
5+
## 通用格式
6+
7+
```bash
8+
export LAZYLLM_<平台环境变量名>_API_KEY=<你的 key>
9+
```
10+
11+
## 平台与环境变量
12+
13+
| 平台 | 环境变量 | 申请/文档链接 |
14+
|------------|----------|---------------|
15+
| 日日新 SenseNova | `LAZYLLM_SENSENOVA_API_KEY`,可选 `LAZYLLM_SENSENOVA_SECRET_KEY` | [平台与 API 申请](https://platform.sensenova.cn/) |
16+
| OpenAI | `LAZYLLM_OPENAI_API_KEY` | [API Keys](https://platform.openai.com/api-keys) |
17+
| 智谱 GLM | `LAZYLLM_GLM_API_KEY` | [开放平台](https://open.bigmodel.cn/) |
18+
| Kimi | `LAZYLLM_KIMI_API_KEY` | [开放平台](https://platform.moonshot.cn/) |
19+
| 通义千问 Qwen | `LAZYLLM_QWEN_API_KEY` | [阿里云百炼](https://bailian.console.aliyun.com/) |
20+
| 豆包 Doubao | `LAZYLLM_DOUBAO_API_KEY` | [火山引擎](https://console.volcengine.com/ark) |
21+
| 硅基流动 SiliconFlow | `LAZYLLM_SILICONFLOW_API_KEY` | [SiliconFlow](https://cloud.siliconflow.cn/) |
22+
| MiniMax | `LAZYLLM_MINIMAX_API_KEY` | [MiniMax 开放平台](https://api.minimax.chat/) |
23+
| AI Ping | `LAZYLLM_AIPING_API_KEY` | - |
24+
| DeepSeek | `LAZYLLM_DEEPSEEK_API_KEY` | [DeepSeek 开放平台](https://platform.deepseek.com/) |
25+
26+
说明:日日新可使用“仅 API Key”或“AK + SK”两种方式;其他平台一般只需配置对应 `_API_KEY`。完整列表与申请方式见项目主文档(需联网时查阅)。
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# CLI 使用
2+
3+
LazyLLM 命令行用于依赖安装、模型部署与运行服务。完整参数见项目 `docs/zh/API Reference/cli.md``docs/en/API Reference/cli.md`
4+
5+
## lazyllm deploy
6+
7+
- **模型部署**(默认):`lazyllm deploy <模型名> [--framework vllm|lightllm|lmdeploy|...] [--chat=true] [key=value ...]`
8+
- 支持框架:vllm、lightllm、lmdeploy、infinity、embedding、mindie、auto
9+
- 其他参数以 `key=value` 形式传入
10+
- **MCP 服务**`lazyllm deploy mcp_server <cmd> [args...]`,可选 `-e VAR value``--sse-port``--sse-host``--allow-origin``--pass-environment`
11+
12+
## lazyllm install
13+
14+
- **组件组**`lazyllm install embedding chat finetune`(可多选)
15+
- **指定包**`lazyllm install openai sentence-transformers`(可多选)
16+
17+
## lazyllm run
18+
19+
- **聊天服务**`lazyllm run chatbot --model <模型> [--framework vllm|lightllm|lmdeploy]`
20+
- **RAG 服务**`lazyllm run rag --model <模型> [--framework ...] --documents <文档路径>`
21+
- **工作流**`lazyllm run <workflow.json>`
22+
- **训练/推理服务**`lazyllm run training_service``lazyllm run infer_service`
23+
24+
注意:`chatbot``rag``source``framework` 互斥,仅能从预设选项中选择。
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 环境依赖
2+
3+
本文档为 skill 本地摘要,完整安装与系统差异见项目根目录下 `docs/zh/Home/environment.md``docs/en/Home/environment.md`
4+
5+
## 安装 LazyLLM
6+
7+
```bash
8+
pip install lazyllm
9+
```
10+
11+
按需安装功能组件(推荐使用 CLI):
12+
13+
```bash
14+
lazyllm install embedding # 嵌入相关
15+
lazyllm install chat # 对话相关
16+
lazyllm install finetune # 微调相关
17+
```
18+
19+
## 依赖与场景
20+
21+
- **微调(alpaca-lora)**: datasets, deepspeed, faiss-cpu, fire, gradio, numpy, peft, torch, transformers
22+
- **微调(collie)**: collie-lm, numpy, peft, torch, transformers, datasets, deepspeed, fire
23+
- **推理(lightllm)**: lightllm
24+
- **推理(vllm)**: vllm
25+
26+
## 基础依赖(核心)
27+
28+
fastapi, loguru, pydantic, requests, uvicorn, cloudpickle, gradio, gradio_client, protobuf, setuptools 等。具体版本以项目 `pyproject.toml` / `requirements` 为准。
29+
30+
## 使用在线模型前
31+
32+
请配置对应平台的 API Key 环境变量,见 [api_key_platforms.md](api_key_platforms.md)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Launcher
2+
3+
分布式或集群任务通过 `lazyllm.launchers` 指定启动方式。完整 API 见项目 `docs/zh/API Reference/launcher.md``docs/en/API Reference/launcher.md`
4+
5+
## 常用 Launcher
6+
7+
| 名称 | 说明 |
8+
|------|------|
9+
| EmptyLauncher | 空启动器,常用于本地单进程或测试 |
10+
| RemoteLauncher | 远程节点启动,可指定 nnode、nproc、ngpus 等 |
11+
| SlurmLauncher | 基于 Slurm 调度 |
12+
| ScoLauncher | 基于 Sco 调度 |
13+
| K8sLauncher | 基于 Kubernetes |
14+
| Job | 作业封装 |
15+
16+
## 使用示例
17+
18+
```python
19+
from lazyllm import launchers
20+
21+
# 单机多卡
22+
launchers.remote(ngpus=4)
23+
24+
# 微调 / 部署时传入
25+
model = lazyllm.TrainableModule('qwen2-1.5b').finetune_method(
26+
lazyllm.finetune.llamafactory,
27+
launcher=launchers.remote(ngpus=4)
28+
)
29+
```
30+
31+
Flow 中带 launcher 的组件也可传入 `launcher=lazyllm.launchers.empty()` 等,见 [references/flow.md](../../references/flow.md)[deploy_framework.md](../finetune/deploy_framework.md)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 本地模型与流式输出
2+
3+
本文档为 skill 本地摘要,完整内容见项目 `docs/zh/Best Practice/LocalModel.md``docs/en/Best Practice/LocalModel.md`
4+
5+
## 启用流式输出
6+
7+
```python
8+
import lazyllm
9+
model = lazyllm.TrainableModule('qwen2-1.5b', stream=True)
10+
```
11+
12+
## 使用 StreamCallHelper 迭代输出
13+
14+
```python
15+
model = lazyllm.StreamCallHelper(model)
16+
for msg in model('hello'):
17+
print(msg)
18+
```
19+
20+
当模型在 Flow 中时,应包装最外层 Flow:
21+
22+
```python
23+
model = lazyllm.TrainableModule('qwen2-1.5b', stream=True)
24+
ppl = lazyllm.pipeline(model)
25+
ppl = lazyllm.StreamCallHelper(ppl)
26+
for msg in ppl('hello'):
27+
print(msg)
28+
```
29+
30+
## 流式输出配置
31+
32+
可传入字典配置前缀、后缀与颜色:
33+
34+
```python
35+
stream_config = {
36+
'color': 'green',
37+
'prefix': 'AI: ',
38+
'prefix_color': 'blue',
39+
'suffix': 'End\n',
40+
'suffix_color': 'red'
41+
}
42+
model = lazyllm.TrainableModule('qwen2-1.5b', stream=stream_config)
43+
```
44+
45+
在线模型使用 `OnlineModule(..., stream=True)` 即可启用流式。

docs/lazyllm-skill/assets/finetune/fintune_example.md renamed to docs/lazyllm-skill/assets/finetune/finetune_example.md

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 微调相关资源
2+
3+
以下为微调相关文档与依赖项目的本地说明,完整教程与外部文档需在项目主 docs 或联网环境下查阅。
4+
5+
- **微调教程**:见项目内 `docs/zh/Tutorial/``docs/en/Tutorial/`(如 Tutorial 9 等)。
6+
- **LLaMA-Factory**:LazyLLM 使用 LLaMA-Factory 作为大模型微调后端之一;详细用法见项目依赖与 [finetune_framework.md](finetune_framework.md)[finetune_example.md](finetune_example.md)
7+
- **FlagEmbedding**:用于嵌入与重排模型微调;详细用法见项目依赖与 [finetune_framework.md](finetune_framework.md)
8+
- **Flow 数据流编排**:见 [references/flow.md](../../references/flow.md)

docs/lazyllm-skill/assets/rag/store.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ store_conf = {
6464
},
6565
}
6666

67-
OceanBase支持的字段详细参考: [oceanbase官方文档](https://www.oceanbase.com/docs/oceanbase-database-cn)
67+
OceanBase 支持的字段详细参考: [Store 与数据源参考](store_external_refs.md)
6868

6969
#### SenseCoreStore
7070

7171
基于SenseCore的存储类,提供基于SenseCore的文档存储和检索功能,支持大规模文档管理和高效查询。
7272

73-
SenseCore的使用手册参考: [SenseCore官方文档](https://www.sensecore.cn/help#storage)
73+
SenseCore 使用手册参考: [Store 与数据源参考](store_external_refs.md)
7474

7575
### Segment Store(切片存储类型)
7676

@@ -100,7 +100,7 @@ store_conf = {
100100
}
101101
}
102102

103-
OpenSearch支持的字段详细参考: [opensearch官方文档](https://opensearch-project.github.io/opensearch-py/api-ref/clients/opensearch_client.html)
103+
OpenSearch 支持的字段详细参考: [Store 与数据源参考](store_external_refs.md)
104104

105105
#### ElasticSearchStore
106106

@@ -129,7 +129,7 @@ store_conf = {
129129
}
130130
}
131131

132-
ElasticSearch支持的字段详细参考: [elasticsearch官方文档](https://www.elastic.co/docs/api/doc/elasticsearch/)
132+
ElasticSearch 支持的字段详细参考: [Store 与数据源参考](store_external_refs.md)
133133

134134
### Vector Store(向量存储类型)
135135

@@ -160,7 +160,7 @@ store_conf = {
160160
},
161161
}
162162

163-
Chroma支持的字段详细参考: [chroma官方文档](https://docs.trychroma.com/)
163+
Chroma 支持的字段详细参考: [Store 与数据源参考](store_external_refs.md)
164164

165165
#### MilvusStore
166166

@@ -195,7 +195,7 @@ store_conf = {
195195
},
196196
}
197197

198-
Milvus支持的字段详细参考: [milvus官方文档](https://milvus.io/docs/v2.3.0/index.md)
198+
Milvus 支持的字段详细参考: [Store 与数据源参考](store_external_refs.md)
199199

200200
## 基础使用
201201

0 commit comments

Comments
 (0)