Skip to content
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
28 changes: 27 additions & 1 deletion apps/application/serializers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,33 @@ def append_chat_record(self, chat_record: ChatRecord):
else:
QuerySet(Chat).filter(id=self.chat_id).update(update_time=timezone.now())
# 插入会话记录
chat_record.save()
QuerySet(ChatRecord).update_or_create(id=chat_record.id,
create_defaults={'id': chat_record.id,
'chat_id': chat_record.chat_id,
"vote_status": chat_record.vote_status,
'problem_text': chat_record.problem_text,
'answer_text': chat_record.answer_text,
'answer_text_list': chat_record.answer_text_list,
'message_tokens': chat_record.message_tokens,
'answer_tokens': chat_record.answer_tokens,
'const': chat_record.const,
'details': chat_record.details,
'improve_paragraph_id_list': chat_record.improve_paragraph_id_list,
'run_time': chat_record.run_time,
'index': chat_record.index},
defaults={
"vote_status": chat_record.vote_status,
'problem_text': chat_record.problem_text,
'answer_text': chat_record.answer_text,
'answer_text_list': chat_record.answer_text_list,
'message_tokens': chat_record.message_tokens,
'answer_tokens': chat_record.answer_tokens,
'const': chat_record.const,
'details': chat_record.details,
'improve_paragraph_id_list': chat_record.improve_paragraph_id_list,
'run_time': chat_record.run_time,
'index': chat_record.index
})
ChatCountSerializer(data={'chat_id': self.chat_id}).update_chat()

def to_dict(self):
Expand Down
8 changes: 6 additions & 2 deletions ui/src/workflow/common/app-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ class AppNode extends HtmlResize.view {
children: globalFields,
})
}
result.push({
const value: any = {
value: this.props.model.id,
icon: this.props.model.properties.node_data?.icon,
label: this.props.model.properties.stepName,
type: this.props.model.type,
children: this.props.model.properties?.config?.fields || [],
})
}
if (this.props.model.properties.kind) {
value['kind'] = this.props.model.properties.kind
}
result.push(value)
return result
}
get_up_node_field_dict(contain_self: boolean, use_cache: boolean) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code contains several issues:

  1. Duplicate result Variable: You have two variables named result. This is unnecessary and can lead to confusion.

  2. Variable Scope Issues: In the second line of the function body, you create an object value, but it's then overwritten immediately without being used elsewhere in the function.

  3. Missing Return Statement: The function doesn't explicitly return anything after constructing the final structure.

  4. Lack of Cache Handling: There seems to be an unused parameter use_cache.

  5. Inconsistent Object Initialization: When appending to result, there’s inconsistency in how properties are added. Sometimes they're appended directly, sometimes as nested objects.

Here’s a revised version of the code with these issues addressed:

class AppNode extends HtmlResize.view {
  pushToResult(result: {}, nodeData): void {
    result.push({
      value: nodeData.id,
      icon: nodeData.properties.node_data?.icon,
      label: nodeData.properties.stepName,
      type: nodeData.type,
      children: nodeData.properties.config?.fields || [],
    });
    if(nodeData.properties.kind) {
      result[value]['kind'] = nodeData.properties.kind;
    }
  }

  render(model): {}[] | JSX.Element | null {
    return [
      <AppRow data={globalFields}></AppRow>,
      ...[].map(() => ({
        value: model.data!.id,
        icon: model.properties?.['node-data'].icon,
        label: model.properties?.stepName,
        type: model.type,
        children: model.properties?.config?.fields || [],
      })),
    ];
  }

  getUpNodeFieldDict(containSelf: boolean, useCache: boolean): void {}
}

Key Changes:

  • Removed duplicate result variable.
  • Consolidated property setting for direct assignment instead of nesting.
  • Added a helper method pushToResult to reduce redundancy.
  • Fixed inconsistent handling of nested properties.
  • Cleaned up formatting for better readability.

If you'd like further optimizations or additional changes, feel free to ask!

Expand Down
5 changes: 4 additions & 1 deletion ui/src/workflow/icons/tool-lib-node-icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
>
<img :src="item?.icon" alt="" />
</el-avatar>

<el-avatar v-else-if="item?.kind === 'data-source'" class="avatar-purple" shape="square">
<img src="@/assets/tool/icon_datasource.svg" style="width: 58%" alt="" />
</el-avatar>
<el-avatar v-else-if="item?.tool_type === 'DATA_SOURCE'" class="avatar-purple" shape="square">
<img src="@/assets/tool/icon_datasource.svg" style="width: 58%" alt="" />
</el-avatar>
Expand All @@ -23,6 +25,7 @@ const props = defineProps<{
name: string
icon: string
tool_type: string
kind?: string
}
}>()
</script>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The proposed code has a few minor adjustments to improve clarity and maintain consistency:

  1. Corrected the v-else-if condition for item.kind === 'data-source'.
  2. Added type annotations to make it more explicit what types each property should be.

Here's the corrected version:

@@ -8,7 +8,9 @@
 > 
   <el-avatar :src="item?.icon"></el-avatar>

---
+<el-avatar v-else-if="item?.kind === 'data-source'" class="avatar-purple" shape="square">
+  <img src="@/assets/tool/icon_datasource.svg" style="width: 58%;" alt="" />
+</el-avatar>

@@ -23,6 +25,7 @@ const props = defineProps<{
     name: string
     icon: string
     tool_type: string
+    kind?: string
 }>()
-</script>
++</script>

These changes address the inconsistencies in logic and clarify the expected structure of the input properties.

Expand Down
Loading