mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
* fix redirect language code prefixes * rename: cn -> zh, jp -> ja * remove hardcoded ja / zh references * remove hardcoded 'english' references * renamed variable names and dict keys to language agnostic names * fix: add missing language helper methods to PRAnalyzer - Add get_language_directory() method - Initialize source_language and target_languages from config - Fixes AttributeError when generating mixed PR errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * test: kitchen sink workflow validation v2 This PR validates the translation workflow after config-driven refactoring: Changes: - Add new test file: test-workflow-validation.mdx - Modify existing file: introduction.mdx - Update docs.json navigation Tests: - New file translation (add workflow) - Existing file translation (update workflow) - Navigation sync across languages - Config-driven language codes (zh/ja instead of cn/jp) - Source language abstraction (no hardcoded "English") Expected workflow behavior: 1. Detect changes in en/ directory 2. Translate new file to zh and ja 3. Update modified file translations 4. Sync docs.json for all language sections 5. Commit translated files automatically 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: update workflow paths to use zh/ja instead of cn/jp Aligns workflow trigger paths with the zh/ja language directory rename. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Revert "fix: update workflow paths to use zh/ja instead of cn/jp" This reverts commit9587b7cc5d. * Revert "test: kitchen sink workflow validation v2" This reverts commit4abdd69fd2. * fix: update workflow paths in doc analyze workflow to use zh/ja instead of cn/jp * Refactor/language codes (#240) * test: kitchen sink workflow validation v2 This PR validates the translation workflow after config-driven refactoring: Changes: - Add new test file: test-workflow-validation.mdx - Modify existing file: introduction.mdx - Update docs.json navigation Tests: - New file translation (add workflow) - Existing file translation (update workflow) - Navigation sync across languages - Config-driven language codes (zh/ja instead of cn/jp) - Source language abstraction (no hardcoded "English") Expected workflow behavior: 1. Detect changes in en/ directory 2. Translate new file to zh and ja 3. Update modified file translations 4. Sync docs.json for all language sections 5. Commit translated files automatically 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: update workflow paths to use zh/ja instead of cn/jp Aligns workflow trigger paths with the zh/ja language directory rename. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Revert "fix: update workflow paths to use zh/ja instead of cn/jp" This reverts commit9587b7cc5d. * Revert "test: kitchen sink workflow validation v2" This reverts commit4abdd69fd2. * fix: update workflow paths in doc analyze workflow to use zh/ja instead of cn/jp --------- Co-authored-by: Claude <noreply@anthropic.com> * fix: update workflow files to use 'source' instead of 'english' After refactoring the PR analyzer to use 'source' for source language PRs (instead of hardcoded 'english'), the workflow files need to match. Changes: - sync_docs_analyze.yml: pr_type == 'source' (was 'english') - sync_docs_update.yml: PR_TYPE != 'source' check - Updated all comments from "English" to "source language" - Updated all pr_type values in JSON from "english" to "source" This ensures the workflows trigger correctly with the refactored config-driven language system. Related: language code refactoring (cn/jp → zh/ja) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix/workflow source language references (#245) * test: kitchen sink workflow validation v2 This PR validates the translation workflow after config-driven refactoring: Changes: - Add new test file: test-workflow-validation.mdx - Modify existing file: introduction.mdx - Update docs.json navigation Tests: - New file translation (add workflow) - Existing file translation (update workflow) - Navigation sync across languages - Config-driven language codes (zh/ja instead of cn/jp) - Source language abstraction (no hardcoded "English") Expected workflow behavior: 1. Detect changes in en/ directory 2. Translate new file to zh and ja 3. Update modified file translations 4. Sync docs.json for all language sections 5. Commit translated files automatically 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: update workflow paths to use zh/ja instead of cn/jp Aligns workflow trigger paths with the zh/ja language directory rename. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Revert "fix: update workflow paths to use zh/ja instead of cn/jp" This reverts commit9587b7cc5d. * Revert "test: kitchen sink workflow validation v2" This reverts commit4abdd69fd2. * fix: update workflow paths in doc analyze workflow to use zh/ja instead of cn/jp * fix: update workflow files to use 'source' instead of 'english' After refactoring the PR analyzer to use 'source' for source language PRs (instead of hardcoded 'english'), the workflow files need to match. Changes: - sync_docs_analyze.yml: pr_type == 'source' (was 'english') - sync_docs_update.yml: PR_TYPE != 'source' check - Updated all comments from "English" to "source language" - Updated all pr_type values in JSON from "english" to "source" This ensures the workflows trigger correctly with the refactored config-driven language system. Related: language code refactoring (cn/jp → zh/ja) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> * fix * fix docs.json language codes * rename previous version docs: cn -> zh, jp -> ja * rm duplicate redirect entires --------- Co-authored-by: Claude <noreply@anthropic.com>
120 lines
4.0 KiB
Plaintext
120 lines
4.0 KiB
Plaintext
---
|
||
title: "循环"
|
||
icon: "infinity"
|
||
---
|
||
|
||
<Note> ⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考[英文原版](/en/use-dify/nodes/loop)。</Note>
|
||
|
||
|
||
循环节点执行重复性工作流,每个循环都基于前一个循环的结果进行构建。与迭代处理数组元素独立不同,循环创建的是随着每次重复而演进的渐进式工作流。
|
||
|
||
## 循环 vs 迭代
|
||
|
||
了解何时使用每种重复模式:
|
||
|
||
<Tabs>
|
||
<Tab title="循环">
|
||
**顺序处理** - 每个循环依赖于先前的结果
|
||
|
||
**渐进式改进** - 输出在迭代过程中得到改善或演化
|
||
|
||
**状态管理** - 变量在循环中持续存在并累积
|
||
|
||
**使用场景** - 内容优化、问题解决、质量保证
|
||
</Tab>
|
||
|
||
<Tab title="迭代">
|
||
**独立处理** - 每个项目单独处理
|
||
|
||
**并行执行** - 项目可以同时处理
|
||
|
||
**批量操作** - 对多个数据点应用相同操作
|
||
|
||
**使用场景** - 数据转换、批量处理、并行分析
|
||
</Tab>
|
||
</Tabs>
|
||
|
||
## 配置
|
||
|
||
### 循环变量
|
||
|
||
定义在循环迭代中持续存在并在循环完成后仍可访问的变量。这些变量维护状态并实现渐进式工作流。
|
||
|
||
### 终止条件
|
||
|
||
配置循环何时停止执行:
|
||
|
||
**循环终止条件** - 确定何时退出的表达式(例如,`quality_score > 0.9`)
|
||
|
||
**最大循环次数** - 防止无限循环的安全限制
|
||
|
||
**退出循环节点** - 达到此节点时立即终止
|
||
|
||
<Info>
|
||
当满足终止条件、达到最大次数或执行退出循环节点时,循环终止。如果未指定条件,循环将继续直到达到最大次数。
|
||
</Info>
|
||
|
||
## 基础循环示例
|
||
|
||
生成随机数,直到找到小于 50 的数:
|
||
|
||
<Frame caption="用于随机数生成的基础循环工作流">
|
||
<img src="https://assets-docs.dify.ai/2025/04/282013c48b46d3cc4ebf99323da10a31.png" alt="基础循环工作流" />
|
||
</Frame>
|
||
|
||
**工作流步骤:**
|
||
1. **代码节点**生成 1-100 之间的随机整数
|
||
2. **条件分支节点**检查数字是否小于 50
|
||
3. **模板节点**为小于 50 的数字返回 "done" 以触发循环终止
|
||
4. 循环继续直到满足终止条件
|
||
|
||
<Frame caption="循环执行步骤和结果">
|
||
<img src="https://assets-docs.dify.ai/2025/04/9d9fb4db7093521000ac735a26f86962.png" alt="循环执行步骤" />
|
||
</Frame>
|
||
|
||
## 高级循环示例
|
||
|
||
通过迭代改进创建诗歌,每个版本都基于前一个版本构建:
|
||
|
||
<video controls src="https://assets-docs.dify.ai/2025/04/7ecfc04458aa38e721baaa5f6355486c.mp4" width="100%" />
|
||
|
||
**循环变量:**
|
||
- `num` - 计数器,从 0 开始,每次迭代递增
|
||
- `verse` - 文本变量,保存当前诗歌版本
|
||
|
||
**工作流逻辑:**
|
||
1. **条件分支节点**检查 `num > 3` 以确定何时退出
|
||
2. **大型语言模型节点**基于前一版本生成改进的诗歌
|
||
3. **变量赋值器**更新计数器和诗歌内容
|
||
4. **退出循环节点**在 4 个改进循环后终止
|
||
|
||
大型语言模型提示词引用当前诗句和迭代上下文:
|
||
|
||
```text
|
||
You are a European literary figure creating poetic verses.
|
||
|
||
Current verse: {{verse}}
|
||
|
||
Refine and improve this poem based on your previous work.
|
||
```
|
||
|
||
## 常见使用场景
|
||
|
||
**内容优化** - 通过多次大型语言模型审查逐步改进文本、代码或设计,直到达到质量标准。
|
||
|
||
**问题解决** - 将复杂问题分解为迭代步骤,其中每个循环基于先前的进展处理下一个逻辑部分。
|
||
|
||
**研究工作流** - 基于每个搜索循环的发现,迭代搜索、分析和优化研究查询。
|
||
|
||
**质量保证** - 重进直到满足所有标准。
|
||
|
||
## 最佳实践
|
||
|
||
**定义明确的退出条件** - 确保循环具有特定的、可测量的终止条件,以防止无限执行。
|
||
|
||
**设置合理限制** - 根据预期复杂性和处理需求使用适当的最大迭代次数。
|
||
|
||
**有效管理状态** - 使用循环变量在迭代中维护必要信息,同时避免不必要的数据累积。
|
||
|
||
**监控进度** - 包含日志记录或进度指示器来跟踪循环执行,特别是对于长时间运行的过程。
|