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

feat: 修改标注时可以选择默认知识库 #1606

Merged
merged 1 commit into from
Nov 12, 2024
Merged

Conversation

shaohuzhang1
Copy link
Contributor

feat: 修改标注时可以选择默认知识库 --story=1016833 --user=王孝刚 对话日志-修改标注时可以选择默认知识库 #229 https://www.tapd.cn/57709429/s/1608846

--story=1016833 --user=王孝刚 对话日志-修改标注时可以选择默认知识库 #229 https://www.tapd.cn/57709429/s/1608846
Copy link

f2c-ci-robot bot commented Nov 12, 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 Nov 12, 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

}
formRef.value?.clearValidate()
documentDialogVisible.value = true
}
onMounted(() => {
changeDayHandle(history_day.value)
getDetail()

Choose a reason for hiding this comment

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

这个代码的主要问题是关于元素的绑定和使用,以及一些小错误。

首先,document.loadingdocument.dialogLoading 应该是相同的变量名(没有分隔符),且不应为对象形式定义。其次,多个方法需要正确地从父组件获取或传递参数,并且函数之间可以简化调用来提高代码逻辑的一致性和简洁度。

建议进行一些简单的重构:

<script setup>
import * as api from "@/api/chat";
import { computed, nextTick } from "vue";

// Initialize or access variables here...
{
  this.$nextTick(() => {
    // ...
  });
}

onUpdate($route) {
   console.log("路由发生变化");
}

methods: {
 onBeforeDestroy() {},
}
</script>

...
</style>

此外,我注意到你提到有一个叫做 logApi 的变量,这与你的示例无关,但你可以将其删除:

const logApi = {
  postChatRecordLog(...args) {}
};

最后要注意的是,在 setup 函数中引入外部导入语句可能会导致编译时错误或运行时异常,请确保只在必要的位置导入这些模块。

# 批量保存聊天记录
ChatRecord.objects.bulk_update(chat_record_list, ['improve_paragraph_id_list'])

return paragraph_ids, dataset_id

Choose a reason for hiding this comment

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

该类中存在多处不规范的地方:

  1. 在初始化时,序列化器的参数没有使用大写并错误地将Model更改为MODEL

  2. embedding_by_paragraph, get_embedding_model_id_by_dataset_id 应在 settings.models_provider 文件夹中的函数下而不是直接导入。这些是外部依赖。

  3. delete_post_improve 方法应该重命名为 clean_and_delete_post_improve 并且添加逻辑来确保所有的输入都是有效的,同时返回一个布尔值结果(删除成功/失败)而非删除数据后执行的操作。

  4. transaction.atomic() 完全是不必要的,并可能导致额外的风险或性能下降,在实际应用中通常被替换成 try-except 风险处理策略。这一步可以删除它以实现简洁性增强。

  5. 调试代码块应该明确指出需要调整的内容:这里似乎是在模拟数据库操作,但是由于缺少实际验证和清理语句导致代码难以理解,因此应将其置于方法内部进行严格的单元测试或集成测试环境进行验证。

  6. 这里还有一条错误信息未修复,“AppApiException(500)”并没有被捕捉到。

修正上述问题之后,以下为重构后的详细示例:

from django.db import transaction

class PostImproveSerializer(serializers.Serializer):
    dataset_id = UUIDField(required=True)
    document_id = UUIDField(required=True)
    chat_ids = ListField(child=UUIDField())
    
    def is_valid(self, *, exc=False):
        if not Document.objects.filter(uuid1()).exists():  # 更改类型以便于识别是否通过uuid1创建表
            raise serializers.ValidationError(
                {
                    'error': ('Document id must be uuid'),
                },
            )  # 坏在这里:不能抛出异常
        
        self.dataset_id = DatasetIDField()
        
        if Document.objects.filter(id=self.context["document_id"], dataset_id=<YOUR_DATASET_ID>).exclude(**{"uuid_uuid1": False}).exists():
            if self.context and "dataset_id" in self.context:
                if self.instance.pk:           # 没有实例化对象 -> 自动默认为空
                    self.validated_data.pop("pk", None)

@transaction.atomic
def clean_and_delete_post_improve(request, instance=None):  # 修改request to handle post / pre request operations
    if isinstance(request, Request):
        response.data = {"success": True, "message": "Success"}
        context.clear()

    chat_records = [ChatRecord.objects.get(pk=pk) for pk in self.context['chat_ids'].strip(', ').split(",")]

    if len([rec for rec in chat_records]) < len(self.context['chat_ids']):
        success = False
    else:
        success = True
    
    response.data = {            
        "success": success,
        "chat_records": [{'answer_text': r.answer_text,'question_id':r.question},]     
    }

if instance:
    delete_instance(instance)
else:
    create_serializer(data=request.data).is_valid(raise_exception=True)

请注意这是修改示例,根据具体需求继续调整。

description='知识库id'),

]


class VoteApi(ApiMixin):
@staticmethod

Choose a reason for hiding this comment

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

在您的代码中,我注意到一些未闭合的标签和缩进问题,请注意更新:

class VoteApi(ApiMix):

@wxg0103 wxg0103 merged commit 4e615db into main Nov 12, 2024
4 of 5 checks passed
@wxg0103 wxg0103 deleted the pr@main@feat_1016833 branch November 12, 2024 09:54
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.

3 participants