Skip to content

fix: Dialogue node context type is not required #1926

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 1 commit into from
Dec 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ChatNodeSerializer(serializers.Serializer):

model_params_setting = serializers.DictField(required=False, error_messages=ErrMessage.integer("模型参数相关设置"))

dialogue_type = serializers.CharField(required=True, error_messages=ErrMessage.char("上下文类型"))
dialogue_type = serializers.CharField(required=False, allow_blank=True, allow_null=True,
error_messages=ErrMessage.char("上下文类型"))


class IChatNode(INode):
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 code looks generally correct, but there are a few improvements that can be made:

  1. Field Name Consistency: The model_params_setting field currently has an empty dictionary as its default value while other fields like dialogue_type use required=True. It might make sense to set all required fields to either true or false.

  2. Allow Blank/Null for Dialogue Type: While allowing blank/null values is allowed with allow_blank=True, it's good practice to ensure this behavior aligns with the expectations of your application's design. If you plan on having dialogue types not specified at times, this makes sense.

  3. Comments: There is no clear documentation or comments explaining what each part of the code does. Adding comments could help future maintainers understand the purpose and functionality of the classes/interfaces.

Here's a suggested update:

class ChatNodeSerializer(serializers.Serializer):
    """
    Serializer for a chat node entity.
    """

    model_params_setting = serializers.DictField(required=False,
                                                error_messages={
                                                    "integer": "模型参数相关设置必须是一个字典"
                                                })

    dialogue_type = serializers.CharField(
        # Allow blank and null values if dialogue type is optional
        allow_blank=True, allow_null=True,

        # Required unless there is specific context where it should be left empty/blank/null
        required=False,
        error_messages={
            "char": "上下文类型不能为空或者为空白字符串或null"
        }
    )

# Assuming IChatNode would inherit from BaseINode (if needed)

Key Points:

  • Consistent Default Values: Ensure that all required fields have consistent requirements (required=True or required=False).
  • Docstrings: Add docstrings and comments to describe the roles and purposes of the class and fields where appropriate.
  • Error Messages: Clearly define what constitutes valid input for each field using descriptive messages.

Expand Down
Loading