-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Set up a complete knowledge base workflow in the loop body, debug prompts that the knowledge base write node cannot be used as the end node #4476
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ import Dagre from '@/workflow/plugins/dagre' | |
| import { initDefaultShortcut } from '@/workflow/common/shortcut' | ||
| import LoopBodyContainer from '@/workflow/nodes/loop-body-node/LoopBodyContainer.vue' | ||
| import { WorkflowMode } from '@/enums/application' | ||
| import { WorkFlowInstance } from '@/workflow/common/validate' | ||
| import { WorkFlowInstance, KnowledgeWorkFlowInstance } from '@/workflow/common/validate' | ||
| import { t } from '@/locales' | ||
| import { disconnectByFlow } from '@/workflow/common/teleport' | ||
| const loop_workflow_mode = inject('loopWorkflowMode') || WorkflowMode.ApplicationLoop | ||
|
|
@@ -21,7 +21,10 @@ const props = defineProps<{ nodeModel: any }>() | |
| const containerRef = ref() | ||
| const LoopBodyContainerRef = ref<InstanceType<typeof LoopBodyContainer>>() | ||
| const validate = () => { | ||
| const workflow = new WorkFlowInstance(lf.value.getGraphData(), WorkflowMode.ApplicationLoop) | ||
| const workflow = | ||
| loop_workflow_mode == WorkflowMode.ApplicationLoop | ||
| ? new WorkFlowInstance(lf.value.getGraphData(), WorkflowMode.ApplicationLoop) | ||
| : new KnowledgeWorkFlowInstance(lf.value.getGraphData(), WorkflowMode.KnowledgeLoop) | ||
| return Promise.all(lf.value.graphModel.nodes.map((element: any) => element?.validate?.())) | ||
| .then(() => { | ||
| const loop_node_id = props.nodeModel.properties.loop_node_id | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no major structural issues or obvious bugs in your provided code snippet. However, here are a few areas where improvements can be made for clarity and maintainability:
Here's the updated code snippet with these suggestions: import Dagre from '@/workflow/plugins/dagre';
import { initDefaultShortcut } from '@/workflow/common/shortcut';
import LoopBodyContainer from '@/workflow/nodes/loop-body-node/LoopBodyContainer.vue';
import { WorkflowMode } from '@/enums/application';
import { WorkFlowInstance, KnowledgeWorkFlowInstance } from '@/workflow/common/validate';
import { t } from '@/locales';
import { disconnectByFlow } from '@/workflow/common/teleport';
const loop_workflow_mode = inject('loopWorkflowMode') || WorkflowMode.ApplicationLoop;
const props = defineProps<{ nodeModel: any }>();
const containerRef = ref();
const LoopBodyContainerRef = ref<InstanceType<typeof LoopBodyContainer>>();
const validate = () => {
const workflow =
loop_workflow_mode === WorkflowMode.ApplicationLoop
? new WorkFlowInstance(lf.value.getGraphData(), WorkflowMode.ApplicationLoop)
: new KnowledgeWorkFlowInstance(lf.value.getGraphData(), WorkflowMode.KnowledgeLoop);
return Promise.all(lf.value.graphModel.nodes.map((element: any) => element?.validate?.()))
.then(() => {
const loop_node_id = props.nodeModel.properties.loop_node_id;
// Use template literal for more organized string
console.log(t("Validate completed successfully.", { node_id: loop_node_id }));
// Rest of the validation logic may follow...
})
.catch((error) => {
console.error(t("Validation failed:", { error_message: error.message }));
})
.finally(() => {});
};These changes improve readability and maintainability within your codebase. |
||
|
|
||
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.
After reviewing the provided code, here are some observations and suggested improvements:
Duplicated Logic: The
is_valid_work_flowmethod checks both data source nodes and loop start nodes depending on whether the workflow mode is knowledge. This logic can be refactored into a single function to improve maintainability.Code Duplication: There are multiple occurrences of similar logic to filter nodes. Refactoring these blocks can reduce redundancy.
Edge Cases Missing:
DataSource,LoopStartNode) are correctly handled in validation methods.Logging and Error Handling: Consider adding more comprehensive logging and better error messages to help with debugging and user experience.
Performance Optimization: If there's a lot of processing happening during certain functions, consider optimizing loops or using data structures that allow faster lookups.
Here's an optimized version of the relevant parts:
This version consolidates and simplifies the logic while maintaining readability and robustness. Make sure to adjust the error messages and exception handling according to your application's needs.