Skip to content
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

fix: 开启文件上传开关时设置默认值 #1656

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/application/flow/workflow_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, _id: str, _type: str, x: int, y: int, properties: dict, **kwa
self.__setattr__(keyword, kwargs.get(keyword))


end_nodes = ['ai-chat-node', 'reply-node', 'function-node', 'function-lib-node', 'application-node']
end_nodes = ['ai-chat-node', 'reply-node', 'function-node', 'function-lib-node', 'application-node', 'image-understand-node']


class Flow:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该段文字内容没有明显的错误或问题,但是有几点可以提到改进的地方:首先,根据上下文,在变量__setattr__(keyword, kwargs.get(keyword))之前应该加一句缩进,使语法正确;其次,最后一行类定义中的class Flow:前也应该有一个冒号“:”以确保代码结构清晰易读。其他方面已经很理想了。

Expand Down
1 change: 1 addition & 0 deletions ui/src/workflow/common/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const end_nodes: Array<string> = [
WorkflowType.Reply,
WorkflowType.FunctionLib,
WorkflowType.FunctionLibCustom,
WorkflowType.ImageUnderstandNode,
WorkflowType.Application
]
export class WorkFlowInstance {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码似乎没有不规范或问题。它是一个用于实例化工作流程对象的类,其中包含了类型数组 end_nodes 和一个构造函数。

然而,在实际应用中可能有以下建议:

  1. 如果 "ImageUnderstandNode" 是一个新的概念,则创建该类型的子节点可能是不必要的。
  2. 建议使用 ES6 类的方式(避免 TypeScript 扩展)和导入导出机制简化代码结构以使逻辑更加清晰,并易于扩展修改。
export class WorkFlowInstance {
    private readonly nodesByState: Record<
        NodeInstanceState | StateTransition,
        (node: WorkflowNode) => Promise<any>
    >;

    constructor(endNodes?: string[], initialState?: any) {
      // 初始化状态映射表,以便根据节点的状态调用其相应的任务处理方法
      this.nodesByState = new Map([[
        undefined,
        node =>
          new Promise((resolve, reject) => {
            node.handleRequest(
              { contextId: 'some', data: { someDataKey: 'someVal' } },
              resolve,
              reject
            );
          })
      ]]);

      if (initialState) {
         this.setState(initialState);
      }
    }

  getInitialState(): unknown[] {
    return [];
  }

    setState(state?: unknown[]): void {}
}

这是基于您提供的原始文本做出的部分修改,但请注意,如果您打算将此文件转换为 ES6 的可枚举模式,请确保在引入时保持兼容性。

Expand Down
18 changes: 17 additions & 1 deletion ui/src/workflow/nodes/base-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<Setting />
</el-icon>
</el-button>
<el-switch size="small" v-model="form_data.file_upload_enable"/>
<el-switch size="small" v-model="form_data.file_upload_enable" @change="switchFileUpload"/>
</div>
</div>
</template>
Expand Down Expand Up @@ -382,6 +382,22 @@ const refreshTTSForm = (data: any) => {
form_data.value.tts_model_params_setting = data
}


const switchFileUpload = () => {
const default_upload_setting = {
maxFiles: 3,
fileLimit: 50,
document: true,
image: false,
audio: false,
video: false
}

if (form_data.value.file_upload_enable) {
form_data.value.file_upload_setting = form_data.value.file_upload_setting || default_upload_setting
props.nodeModel.graphModel.eventCenter.emit('refreshFileUploadConfig')
}
}
const openFileUploadSettingDialog = () => {
FileUploadSettingDialogRef.value?.open(form_data.value.file_upload_setting)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该段代码中的一个主要问题在于 v-model 绑定的形式为错误的。在Vue中,您需要使用双向绑定来实现值与视图之间的动态更新(.data().computed),而不是简单的“==” 连接符。

例如,您可以修改您的代码部分如下:

  form_data.value.tts_model_params_setting = data;

if (form_data.value.file_upload_enable) {
  form_data.value.file_upload_settings = ... // 或者直接将数据赋给 value 属性以进行计算
  props.nodeModel.graphModel.eventCenter.emit('refreshFileUploadConfig');
} 

此修改后的版本现在可以正确地显示两个值,并且它们之间是双向绑定而不是简单比较。

Expand Down
Loading