mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: Log annotation acquisition details file type data cannot be serialized (#2579)
This commit is contained in:
parent
460de60019
commit
be31989ab9
|
|
@ -1,11 +1,11 @@
|
|||
# Generated by Django 4.2.13 on 2024-07-15 15:52
|
||||
|
||||
import application.models.application
|
||||
from django.db import migrations, models
|
||||
|
||||
import common.encoder.encoder
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('application', '0009_application_type_application_work_flow_and_more'),
|
||||
]
|
||||
|
|
@ -14,6 +14,6 @@ class Migration(migrations.Migration):
|
|||
migrations.AlterField(
|
||||
model_name='chatrecord',
|
||||
name='details',
|
||||
field=models.JSONField(default=dict, encoder=application.models.application.DateEncoder, verbose_name='对话详情'),
|
||||
field=models.JSONField(default=dict, encoder=common.encoder.encoder.SystemEncoder, verbose_name='对话详情'),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -6,15 +6,13 @@
|
|||
@date:2023/9/25 14:24
|
||||
@desc:
|
||||
"""
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.db import models
|
||||
from langchain.schema import HumanMessage, AIMessage
|
||||
|
||||
from common.encoder.encoder import SystemEncoder
|
||||
from common.mixins.app_model_mixin import AppModelMixin
|
||||
from dataset.models.data_set import DataSet
|
||||
from setting.models.model_management import Model
|
||||
|
|
@ -135,18 +133,6 @@ class VoteChoices(models.TextChoices):
|
|||
TRAMPLE = 1, '反对'
|
||||
|
||||
|
||||
class DateEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, uuid.UUID):
|
||||
return str(obj)
|
||||
if isinstance(obj, datetime.datetime):
|
||||
return obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||
if isinstance(obj, decimal.Decimal):
|
||||
return float(obj)
|
||||
else:
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
class ChatRecord(AppModelMixin):
|
||||
"""
|
||||
对话日志 详情
|
||||
|
|
@ -163,7 +149,7 @@ class ChatRecord(AppModelMixin):
|
|||
message_tokens = models.IntegerField(verbose_name="请求token数量", default=0)
|
||||
answer_tokens = models.IntegerField(verbose_name="响应token数量", default=0)
|
||||
const = models.IntegerField(verbose_name="总费用", default=0)
|
||||
details = models.JSONField(verbose_name="对话详情", default=dict, encoder=DateEncoder)
|
||||
details = models.JSONField(verbose_name="对话详情", default=dict, encoder=SystemEncoder)
|
||||
improve_paragraph_id_list = ArrayField(verbose_name="改进标注列表",
|
||||
base_field=models.UUIDField(max_length=128, blank=True)
|
||||
, default=list)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: SystemEncoder.py
|
||||
@date:2025/3/17 16:38
|
||||
@desc:
|
||||
"""
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||
|
||||
|
||||
class SystemEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, uuid.UUID):
|
||||
return str(obj)
|
||||
if isinstance(obj, datetime.datetime):
|
||||
return obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||
if isinstance(obj, decimal.Decimal):
|
||||
return float(obj)
|
||||
if isinstance(obj, InMemoryUploadedFile):
|
||||
return {'name': obj.name, 'size': obj.size}
|
||||
else:
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
# Generated by Django 4.2.18 on 2025-03-17 02:50
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
import common.encoder.encoder
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('setting', '0009_set_default_model_params_form'),
|
||||
]
|
||||
|
|
@ -16,13 +18,15 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
|
||||
('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')),
|
||||
('id', models.UUIDField(default=uuid.uuid1, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
|
||||
('id', models.UUIDField(default=uuid.uuid1, editable=False, primary_key=True, serialize=False,
|
||||
verbose_name='主键id')),
|
||||
('menu', models.CharField(max_length=128, verbose_name='操作菜单')),
|
||||
('operate', models.CharField(max_length=128, verbose_name='操作')),
|
||||
('user', models.JSONField(default=dict, verbose_name='用户信息')),
|
||||
('status', models.IntegerField(max_length=20, verbose_name='状态')),
|
||||
('ip_address', models.CharField(max_length=128, verbose_name='ip地址')),
|
||||
('details', models.JSONField(default=dict, verbose_name='详情')),
|
||||
('details',
|
||||
models.JSONField(default=dict, encoder=common.encoder.encoder.SystemEncoder, verbose_name='详情')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'log',
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import uuid
|
|||
|
||||
from django.db import models
|
||||
|
||||
from common.encoder.encoder import SystemEncoder
|
||||
from common.mixins.app_model_mixin import AppModelMixin
|
||||
|
||||
|
||||
|
|
@ -29,7 +30,7 @@ class Log(AppModelMixin):
|
|||
|
||||
ip_address = models.CharField(max_length=128, verbose_name="ip地址")
|
||||
|
||||
details = models.JSONField(verbose_name="详情", default=dict)
|
||||
details = models.JSONField(verbose_name="详情", default=dict, encoder=SystemEncoder)
|
||||
|
||||
class Meta:
|
||||
db_table = "log"
|
||||
|
|
|
|||
Loading…
Reference in New Issue