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

Conversation

shaohuzhang1
Copy link
Contributor

fix: Dialogue node context type is not required

Copy link

f2c-ci-robot bot commented Dec 27, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Dec 27, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -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.

@shaohuzhang1 shaohuzhang1 merged commit e379b8c into main Dec 27, 2024
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_workflow_chat_dialogue_type branch December 27, 2024 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant