-
Notifications
You must be signed in to change notification settings - Fork 364
modify skill #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
modify skill #1055
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,144 @@ | ||
| # 工具 | ||
| # 内置与扩展工具(lazyllm.tools) | ||
|
|
||
| 提供一些内置的工具用于Agent直接调用 | ||
| 以下工具均来自 **lazyllm.tools**,可供 Agent 直接或通过 `fc_register` 包装后调用。搜索类从 `lazyllm.tools.tools` 导入,其余从 `lazyllm.tools` 导入。 | ||
|
|
||
| ##GoogleSearch | ||
| --- | ||
|
|
||
| 通过 Google 搜索指定的关键词。 | ||
| ## 搜索类工具 | ||
|
|
||
| ### GoogleSearch | ||
|
|
||
| 通过 Google Custom Search API 搜索指定关键词。 | ||
|
|
||
| 参数: | ||
|
|
||
| - custom_search_api_key (str) – 用户申请的 Google API key。 | ||
| - search_engine_id (str) – 用户创建的用于检索的搜索引擎 id。 | ||
| - timeout (int, default: 10 ) – 搜索请求的超时时间,单位是秒,默认是 10。 | ||
| - proxies (Dict[str, str], default: None ) – 请求时所用的代理服务。格式参考 https://www.python-httpx.org/advanced/proxies。 | ||
| - search_engine_id (str) – 用户创建的搜索引擎 id。 | ||
| - timeout (int, default: 10) – 请求超时时间(秒)。 | ||
| - proxies (Dict[str, str], default: None) – 代理配置。 | ||
|
|
||
| ```python | ||
| from lazyllm.tools.tools import GoogleSearch | ||
|
|
||
| key = '<your_google_search_api_key>' | ||
| cx = '<your_search_engine_id>' | ||
|
|
||
| google = GoogleSearch(custom_search_api_key=key, search_engine_id=cx) | ||
| res = google(query='商汤科技', date_restrict='m1') | ||
| ``` | ||
|
|
||
| ## TencentSearch | ||
| ### TencentSearch | ||
|
|
||
| 腾讯搜索接口封装类,用于调用腾讯云的内容搜索服务。 | ||
| 提供对腾讯云搜索API的封装,支持关键词搜索和结果处理。 | ||
| 腾讯云内容搜索 API 封装,支持关键词搜索与结果处理。 | ||
|
|
||
| 参数: | ||
|
|
||
| - secret_id (str) – 腾讯云API密钥ID,用于身份认证 | ||
| - secret_key (str) – 腾讯云API密钥,用于身份认证 | ||
| - secret_id (str) – 腾讯云 API 密钥 ID。 | ||
| - secret_key (str) – 腾讯云 API 密钥。 | ||
|
|
||
| ```python | ||
| from lazyllm.tools.tools import TencentSearch | ||
| secret_id = '<your_secret_id>' | ||
| secret_key = '<your_secret_key>' | ||
| searcher = TencentSearch(secret_id, secret_key) | ||
|
|
||
| searcher = TencentSearch(secret_id='<your_secret_id>', secret_key='<your_secret_key>') | ||
| res = searcher('calculus') | ||
| ``` | ||
|
|
||
| ### 其他搜索工具 | ||
|
|
||
| | 工具 | 说明 | 导入方式 | | ||
| |------|------|----------| | ||
| | BingSearch | Bing 搜索 | `from lazyllm.tools.tools import BingSearch` | | ||
| | BochaSearch | 博查搜索 API | `from lazyllm.tools.tools import BochaSearch` | | ||
| | WikipediaSearch | 维基百科检索 | `from lazyllm.tools.tools import WikipediaSearch` | | ||
| | ArxivSearch | arXiv 论文检索 | `from lazyllm.tools.tools import ArxivSearch` | | ||
| | StackOverflowSearch | Stack Overflow 检索 | `from lazyllm.tools.tools import StackOverflowSearch` | | ||
| | SemanticScholarSearch | Semantic Scholar 学术检索 | `from lazyllm.tools.tools import SemanticScholarSearch` | | ||
| | GoogleBooksSearch | Google 图书检索 | `from lazyllm.tools.tools import GoogleBooksSearch` | | ||
|
|
||
| --- | ||
|
|
||
| ## 通用工具 | ||
|
|
||
| | 工具 | 说明 | 导入方式 | | ||
| |------|------|----------| | ||
| | HttpTool | 发起 HTTP 请求,可封装任意 REST API 供 Agent 调用 | `from lazyllm.tools import HttpTool` | | ||
| | Weather | 天气查询 | `from lazyllm.tools.tools import Weather` | | ||
| | Calculator | 数学计算 | `from lazyllm.tools.tools import Calculator` | | ||
| | JsonExtractor | 从文本中提取 JSON | `from lazyllm.tools.tools import JsonExtractor` | | ||
| | JsonConcentrator | 合并/聚合 JSON 结构 | `from lazyllm.tools.tools import JsonConcentrator` | | ||
|
|
||
| --- | ||
|
|
||
| ## SQL / 数据工具 | ||
|
|
||
| ### SqlManager | ||
|
|
||
| 管理数据库连接与表结构,执行 SQL、获取表信息等,常与 SqlCall 配合实现自然语言转 SQL。 | ||
|
|
||
| - 支持 SQLite、PostgreSQL、MySQL 等;远程库需填写 user、password、host、port。 | ||
| - 常用方法: `get_all_tables`, `execute_query`, `execute_commit`, `create_table`, `set_desc` 等。 | ||
|
|
||
| ```python | ||
| from lazyllm.tools import SqlManager | ||
|
|
||
| sql_manager = SqlManager(db_path='/path/to/db.sqlite') # 或指定 user/password/host/port | ||
| tables = sql_manager.get_all_tables() | ||
| result = sql_manager.execute_query('SELECT * FROM t LIMIT 10') | ||
| ``` | ||
|
|
||
| ### SqlCall | ||
|
|
||
| 将自然语言与表结构信息交给 LLM 生成 SQL,再通过 SqlManager 执行,适合与 ReactAgent 组合为 SQL Agent。 | ||
|
|
||
| ```python | ||
| from lazyllm.tools import SqlManager, SqlCall, fc_register, ReactAgent | ||
|
|
||
| sql_manager = SqlManager(db_path='/path/to/db.sqlite') | ||
| sql_call = SqlCall(llm, sql_manager, use_llm_for_sql_result=False) # 可选参数见 API 文档 | ||
|
|
||
| @fc_register('tool') | ||
| def query_db(query: str) -> str: | ||
| return sql_call(query) | ||
|
|
||
| agent = ReactAgent(llm, tools=['query_db']) | ||
| agent('查询销售额最高的前 5 个产品') | ||
| ``` | ||
|
|
||
| 更多示例见本目录 [basic.md](basic.md) 与 [agent.md](agent.md),或项目主 docs 内 Cookbook(sql_agent、tabular 等)。 | ||
|
|
||
| --- | ||
|
|
||
| ## 代码与能力类 | ||
|
|
||
| ### CodeGenerator | ||
|
|
||
| 基于 LLM 生成代码,可与 FunctionCallAgent 等组合实现“自然语言 → 代码 → 执行”的代码 Agent。 | ||
|
|
||
| ```python | ||
| from lazyllm.tools import CodeGenerator, FunctionCallAgent, fc_register | ||
|
|
||
| gen = CodeGenerator(llm, prompt='根据用户需求生成可执行代码,只返回代码本身。') | ||
|
|
||
| @fc_register('tool') | ||
| def run_code(requirement: str) -> str: | ||
| code = gen(requirement) | ||
| # 可选:在沙箱中执行 code | ||
| return code | ||
|
|
||
| agent = FunctionCallAgent(llm, tools=['run_code']) | ||
| agent('写一个函数计算斐波那契数列前 n 项') | ||
| ``` | ||
|
|
||
| ### MCPClient | ||
|
|
||
| 连接 MCP 服务器(本地或 SSE),获取 MCP 提供的工具列表,可直接作为 Agent 的 tools 使用。用法见 [基础组件 - MCPClient](../assets/agent/basic.md#4-mcpclient)。 | ||
|
|
||
| --- | ||
|
|
||
| ## 小结 | ||
|
|
||
| - **搜索与通用工具**: `lazyllm.tools.tools` 中的 Search、Weather、Calculator、Json*。 | ||
| - **SQL / 数据**: `lazyllm.tools` 的 SqlManager、SqlCall(以及 MongoDBManager、DBManager 等)。 | ||
| - **代码与 MCP**: `lazyllm.tools` 的 CodeGenerator、MCPClient;ToolManager、SkillManager 等见 Agent 模块文档。 | ||
| - **自定义工具**: 使用 `fc_register('tool')` 注册函数,见 [基础组件](../assets/agent/basic.md)。 | ||
|
|
||
| 更多参数与用法见本页上文及 [references/agent.md](../../references/agent.md)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # 在线模型平台与 API Key 环境变量(本地参考) | ||
|
|
||
| 使用 OnlineModule 或 AutoModel 调用线上模型前,需在对应平台申请 API Key,并设置下列环境变量(断网环境下仅作配置参考;实际申请需联网访问各平台)。 | ||
|
|
||
| ## 通用格式 | ||
|
|
||
| ```bash | ||
| export LAZYLLM_<平台环境变量名>_API_KEY=<你的 key> | ||
| ``` | ||
|
|
||
| ## 平台与环境变量 | ||
|
|
||
| | 平台 | 环境变量 | | ||
| |------------|----------| | ||
| | 日日新 SenseNova | `LAZYLLM_SENSENOVA_API_KEY`,可选 `LAZYLLM_SENSENOVA_SECRET_KEY` | | ||
| | OpenAI | `LAZYLLM_OPENAI_API_KEY` | | ||
| | 智谱 GLM | `LAZYLLM_GLM_API_KEY` | | ||
| | Kimi | `LAZYLLM_KIMI_API_KEY` | | ||
| | 通义千问 Qwen | `LAZYLLM_QWEN_API_KEY` | | ||
| | 豆包 Doubao | `LAZYLLM_DOUBAO_API_KEY` | | ||
| | 硅基流动 SiliconFlow | `LAZYLLM_SILICONFLOW_API_KEY` | | ||
| | MiniMax | `LAZYLLM_MINIMAX_API_KEY` | | ||
| | AI Ping | `LAZYLLM_AIPING_API_KEY` | | ||
| | DeepSeek | `LAZYLLM_DEEPSEEK_API_KEY` | | ||
|
|
||
| 说明:日日新可使用“仅 API Key”或“AK + SK”两种方式;其他平台一般只需配置对应 `_API_KEY`。完整列表与申请方式见项目主文档(需联网时查阅)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # CLI 使用(本地参考) | ||
|
|
||
| LazyLLM 命令行用于依赖安装、模型部署与运行服务。完整参数见项目 `docs/zh/API Reference/cli.md` 或 `docs/en/API Reference/cli.md`。 | ||
|
|
||
| ## lazyllm deploy | ||
|
|
||
| - **模型部署**(默认):`lazyllm deploy <模型名> [--framework vllm|lightllm|lmdeploy|...] [--chat=true] [key=value ...]` | ||
| - 支持框架:vllm、lightllm、lmdeploy、infinity、embedding、mindie、auto | ||
| - 其他参数以 `key=value` 形式传入 | ||
| - **MCP 服务**:`lazyllm deploy mcp_server <cmd> [args...]`,可选 `-e VAR value`、`--sse-port`、`--sse-host`、`--allow-origin`、`--pass-environment` | ||
|
|
||
| ## lazyllm install | ||
|
|
||
| - **组件组**:`lazyllm install embedding chat finetune`(可多选) | ||
| - **指定包**:`lazyllm install openai sentence-transformers`(可多选) | ||
|
|
||
| ## lazyllm run | ||
|
|
||
| - **聊天服务**:`lazyllm run chatbot --model <模型> [--framework vllm|lightllm|lmdeploy]` | ||
| - **RAG 服务**:`lazyllm run rag --model <模型> [--framework ...] --documents <文档路径>` | ||
| - **工作流**:`lazyllm run <workflow.json>` | ||
| - **训练/推理服务**:`lazyllm run training_service`、`lazyllm run infer_service` | ||
|
|
||
| 注意:`chatbot` 与 `rag` 的 `source` 与 `framework` 互斥,仅能从预设选项中选择。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # 环境依赖(本地参考) | ||
|
|
||
| 本文档为 skill 本地摘要,完整安装与系统差异见项目根目录下 `docs/zh/Home/environment.md` 或 `docs/en/Home/environment.md`。 | ||
|
|
||
| ## 安装 LazyLLM | ||
|
|
||
| ```bash | ||
| pip install lazyllm | ||
| ``` | ||
|
|
||
| 按需安装功能组件(推荐使用 CLI): | ||
|
|
||
| ```bash | ||
| lazyllm install embedding # 嵌入相关 | ||
| lazyllm install chat # 对话相关 | ||
| lazyllm install finetune # 微调相关 | ||
| ``` | ||
|
|
||
| ## 依赖与场景 | ||
|
|
||
| - **微调(alpaca-lora)**: datasets, deepspeed, faiss-cpu, fire, gradio, numpy, peft, torch, transformers | ||
| - **微调(collie)**: collie-lm, numpy, peft, torch, transformers, datasets, deepspeed, fire | ||
| - **推理(lightllm)**: lightllm | ||
| - **推理(vllm)**: vllm | ||
|
|
||
| ## 基础依赖(核心) | ||
|
|
||
| fastapi, loguru, pydantic, requests, uvicorn, cloudpickle, gradio, gradio_client, protobuf, setuptools 等。具体版本以项目 `pyproject.toml` / `requirements` 为准。 | ||
|
|
||
| ## 使用在线模型前 | ||
|
|
||
| 请配置对应平台的 API Key 环境变量,见 [api_key_platforms.md](api_key_platforms.md)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Launcher(本地参考) | ||
|
|
||
| 分布式或集群任务通过 `lazyllm.launchers` 指定启动方式。完整 API 见项目 `docs/zh/API Reference/launcher.md` 或 `docs/en/API Reference/launcher.md`。 | ||
|
|
||
| ## 常用 Launcher | ||
|
|
||
| | 名称 | 说明 | | ||
| |------|------| | ||
| | EmptyLauncher | 空启动器,常用于本地单进程或测试 | | ||
| | RemoteLauncher | 远程节点启动,可指定 nnode、nproc、ngpus 等 | | ||
| | SlurmLauncher | 基于 Slurm 调度 | | ||
| | ScoLauncher | 基于 Sco 调度 | | ||
| | K8sLauncher | 基于 Kubernetes | | ||
| | Job | 作业封装 | | ||
|
|
||
| ## 使用示例 | ||
|
|
||
| ```python | ||
| from lazyllm import launchers | ||
|
|
||
| # 单机多卡 | ||
| launchers.remote(ngpus=4) | ||
|
|
||
| # 微调 / 部署时传入 | ||
| model = lazyllm.TrainableModule('qwen2-1.5b').finetune_method( | ||
| lazyllm.finetune.llamafactory, | ||
| launcher=launchers.remote(ngpus=4) | ||
| ) | ||
| ``` | ||
|
|
||
| Flow 中带 launcher 的组件也可传入 `launcher=lazyllm.launchers.empty()` 等,见 [references/flow.md](../../references/flow.md) 与 [deploy_framework.md](../finetune/deploy_framework.md)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # 本地模型与流式输出(本地参考) | ||
|
|
||
| 本文档为 skill 本地摘要,完整内容见项目 `docs/zh/Best Practice/LocalModel.md` 或 `docs/en/Best Practice/LocalModel.md`。 | ||
|
|
||
| ## 启用流式输出 | ||
|
|
||
| ```python | ||
| import lazyllm | ||
| model = lazyllm.TrainableModule('qwen2-1.5b', stream=True) | ||
| ``` | ||
|
|
||
| ## 使用 StreamCallHelper 迭代输出 | ||
|
|
||
| ```python | ||
| model = lazyllm.StreamCallHelper(model) | ||
| for msg in model('hello'): | ||
| print(msg) | ||
| ``` | ||
|
|
||
| 当模型在 Flow 中时,应包装最外层 Flow: | ||
|
|
||
| ```python | ||
| model = lazyllm.TrainableModule('qwen2-1.5b', stream=True) | ||
| ppl = lazyllm.pipeline(model) | ||
| ppl = lazyllm.StreamCallHelper(ppl) | ||
| for msg in ppl('hello'): | ||
| print(msg) | ||
| ``` | ||
|
|
||
| ## 流式输出配置 | ||
|
|
||
| 可传入字典配置前缀、后缀与颜色: | ||
|
|
||
| ```python | ||
| stream_config = { | ||
| 'color': 'green', | ||
| 'prefix': 'AI: ', | ||
| 'prefix_color': 'blue', | ||
| 'suffix': 'End\n', | ||
| 'suffix_color': 'red' | ||
| } | ||
| model = lazyllm.TrainableModule('qwen2-1.5b', stream=stream_config) | ||
| ``` | ||
|
|
||
| 在线模型使用 `OnlineModule(..., stream=True)` 即可启用流式。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # 微调相关资源(本地参考) | ||
|
|
||
| 以下为微调相关文档与依赖项目的本地说明,完整教程与外部文档需在项目主 docs 或联网环境下查阅。 | ||
|
|
||
| - **微调教程**:见项目内 `docs/zh/Tutorial/` 或 `docs/en/Tutorial/`(如 Tutorial 9 等)。 | ||
| - **LLaMA-Factory**:LazyLLM 使用 LLaMA-Factory 作为大模型微调后端之一;详细用法见项目依赖与 [finetune_framework.md](finetune_framework.md)、[fintune_example.md](fintune_example.md)。 | ||
| - **FlagEmbedding**:用于嵌入与重排模型微调;详细用法见项目依赖与 [finetune_framework.md](finetune_framework.md)。 | ||
| - **Flow 数据流编排**:见 [references/flow.md](../../references/flow.md)。 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Store 与数据源参考(本地说明) | ||
|
|
||
| 各 Store(OceanBase、SenseCore、OpenSearch、ElasticSearch、Chroma、Milvus 等)的详细连接字段与配置项以对应产品文档为准。 | ||
| 本 skill 内仅做用法摘要;完整字段说明需在联网时查阅各产品官方文档。 | ||
|
|
||
| - **OceanBase**:连接与字段见 OceanBase 官方文档。 | ||
| - **SenseCore**:存储与配置见 SenseCore 使用手册。 | ||
| - **OpenSearch / Elasticsearch**:`uris` 等配置见各自官方 API 文档。 | ||
| - **Chroma / Milvus**:支持的参数字段见各自官方文档。 | ||
|
|
||
| 本目录下 [store.md](store.md) 提供基础用法与示例;扩展配置请参考项目主 docs 或上述产品文档(需联网)。 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好,在文件名
fintune_example.md中存在一个拼写错误,应该是finetune_example.md。这个错误会导致链接失效,建议修正。