# Generated by Django 5.2.1 on 2025-07-11 07:44

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="AIApiKey",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="名称", max_length=255, verbose_name="名称"
                    ),
                ),
                (
                    "platform",
                    models.CharField(
                        choices=[
                            ("AzureOpenAI", "OpenAI 微软"),
                            ("OpenAI", "OpenAI"),
                            ("Ollama", "Ollama"),
                            ("YiYan", "文心一言"),
                            ("XingHuo", "讯飞星火"),
                            ("TongYi", "通义千问"),
                            ("StableDiffusion", "StableDiffusion"),
                            ("Midjourney", "Midjourney"),
                            ("Suno", "Suno"),
                            ("DeepSeek", "DeepSeek"),
                            ("DouBao", "字节豆包"),
                            ("HunYuan", "腾讯混元"),
                            ("SiliconFlow", "硅基流动"),
                            ("ZhiPu", "智谱"),
                            ("MiniMax", "MiniMax"),
                            ("Moonshot", "月之暗灭"),
                            ("BaiChuan", "百川智能"),
                        ],
                        db_comment="平台",
                        max_length=100,
                        verbose_name="平台",
                    ),
                ),
                (
                    "api_key",
                    models.CharField(
                        db_comment="密钥", max_length=255, verbose_name="密钥"
                    ),
                ),
                (
                    "url",
                    models.CharField(
                        blank=True,
                        db_comment="自定义 API 地址",
                        max_length=255,
                        null=True,
                        verbose_name="自定义 API 地址",
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        choices=[(0, "禁用"), (1, "启用")],
                        db_comment="状态",
                        default=0,
                        verbose_name="状态",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI API 密钥",
                "verbose_name_plural": "AI API 密钥",
                "db_table": "ai_api_key",
            },
        ),
        migrations.CreateModel(
            name="Tool",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="工具名称", max_length=128, verbose_name="工具名称"
                    ),
                ),
                (
                    "description",
                    models.CharField(
                        blank=True,
                        db_comment="工具描述",
                        max_length=256,
                        null=True,
                        verbose_name="工具描述",
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        db_comment="状态", default=0, verbose_name="状态"
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 工具",
                "verbose_name_plural": "AI 工具",
                "db_table": "ai_tool",
            },
        ),
        migrations.CreateModel(
            name="AIModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="模型名字", max_length=64, verbose_name="模型名字"
                    ),
                ),
                (
                    "sort",
                    models.IntegerField(
                        db_comment="排序", default=0, verbose_name="排序"
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        choices=[(0, "禁用"), (1, "启用")],
                        db_comment="状态",
                        default=0,
                        verbose_name="状态",
                    ),
                ),
                (
                    "platform",
                    models.CharField(
                        db_comment="模型平台", max_length=32, verbose_name="模型平台"
                    ),
                ),
                (
                    "model",
                    models.CharField(
                        db_comment="模型标识", max_length=64, verbose_name="模型标识"
                    ),
                ),
                (
                    "temperature",
                    models.FloatField(
                        blank=True,
                        db_comment="温度参数",
                        null=True,
                        verbose_name="温度参数",
                    ),
                ),
                (
                    "max_tokens",
                    models.IntegerField(
                        blank=True,
                        db_comment="单条回复的最大 Token 数量",
                        null=True,
                        verbose_name="单条回复的最大 Token 数量",
                    ),
                ),
                (
                    "max_contexts",
                    models.IntegerField(
                        blank=True,
                        db_comment="上下文的最大 Message 数量",
                        null=True,
                        verbose_name="上下文的最大 Message 数量",
                    ),
                ),
                (
                    "key",
                    models.ForeignKey(
                        db_comment="API 秘钥编号",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="ai.aiapikey",
                        verbose_name="API 秘钥编号",
                    ),
                ),
            ],
            options={
                "verbose_name": "模型配置",
                "verbose_name_plural": "模型配置",
                "db_table": "ai_model",
            },
        ),
        migrations.CreateModel(
            name="ChatRole",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="角色名称", max_length=128, verbose_name="角色名称"
                    ),
                ),
                (
                    "avatar",
                    models.CharField(
                        db_comment="头像", max_length=256, verbose_name="头像"
                    ),
                ),
                (
                    "description",
                    models.CharField(
                        db_comment="角色描述", max_length=256, verbose_name="角色描述"
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        choices=[(0, "禁用"), (1, "启用")],
                        db_comment="状态",
                        default=0,
                        verbose_name="状态",
                    ),
                ),
                (
                    "sort",
                    models.IntegerField(
                        db_comment="角色排序", default=0, verbose_name="角色排序"
                    ),
                ),
                (
                    "public_status",
                    models.BooleanField(
                        db_comment="是否公开", default=False, verbose_name="是否公开"
                    ),
                ),
                (
                    "category",
                    models.CharField(
                        blank=True,
                        db_comment="角色类别",
                        max_length=32,
                        null=True,
                        verbose_name="角色类别",
                    ),
                ),
                (
                    "system_message",
                    models.CharField(
                        blank=True,
                        db_comment="角色上下文",
                        max_length=1024,
                        null=True,
                        verbose_name="角色上下文",
                    ),
                ),
                (
                    "model_id",
                    models.ForeignKey(
                        db_column="model_id",
                        db_comment="向量模型编号",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="ai.aimodel",
                        verbose_name="向量模型编号",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        db_comment="用户编号",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 聊天角色",
                "verbose_name_plural": "AI 聊天角色",
                "db_table": "ai_chat_role",
            },
        ),
        migrations.CreateModel(
            name="ChatMessage",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "conversation_id",
                    models.BigIntegerField(
                        db_comment="对话编号", verbose_name="对话编号"
                    ),
                ),
                (
                    "model",
                    models.CharField(
                        db_comment="模型标识", max_length=32, verbose_name="模型标识"
                    ),
                ),
                (
                    "type",
                    models.CharField(
                        choices=[("user", "用户发送"), ("assistant", "模型回复")],
                        db_comment="消息类型",
                        max_length=16,
                        verbose_name="消息类型",
                    ),
                ),
                (
                    "reply_id",
                    models.BigIntegerField(
                        blank=True,
                        db_comment="回复编号",
                        null=True,
                        verbose_name="回复编号",
                    ),
                ),
                (
                    "content",
                    models.CharField(
                        db_comment="消息内容", max_length=2048, verbose_name="消息内容"
                    ),
                ),
                (
                    "use_context",
                    models.BooleanField(
                        db_comment="是否携带上下文",
                        default=False,
                        verbose_name="是否携带上下文",
                    ),
                ),
                (
                    "segment_ids",
                    models.CharField(
                        blank=True,
                        db_comment="段落编号数组",
                        max_length=2048,
                        null=True,
                        verbose_name="段落编号数组",
                    ),
                ),
                (
                    "model_id",
                    models.ForeignKey(
                        db_column="model_id",
                        db_comment="向量模型编号",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="ai.aimodel",
                        verbose_name="向量模型编号",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        db_comment="用户编号",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户",
                    ),
                ),
                (
                    "role",
                    models.ForeignKey(
                        blank=True,
                        db_comment="聊天角色",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="ai.chatrole",
                        verbose_name="聊天角色",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 聊天消息",
                "verbose_name_plural": "AI 聊天消息",
                "db_table": "ai_chat_message",
            },
        ),
        migrations.CreateModel(
            name="ChatConversation",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        db_comment="对话标题", max_length=256, verbose_name="对话标题"
                    ),
                ),
                (
                    "pinned",
                    models.BooleanField(
                        db_comment="是否置顶", default=False, verbose_name="是否置顶"
                    ),
                ),
                (
                    "pinned_time",
                    models.DateTimeField(
                        blank=True,
                        db_comment="置顶时间",
                        null=True,
                        verbose_name="置顶时间",
                    ),
                ),
                (
                    "model",
                    models.CharField(
                        db_comment="模型标识", max_length=32, verbose_name="模型标识"
                    ),
                ),
                (
                    "system_message",
                    models.CharField(
                        blank=True,
                        db_comment="角色设定",
                        max_length=1024,
                        null=True,
                        verbose_name="角色设定",
                    ),
                ),
                (
                    "temperature",
                    models.FloatField(db_comment="温度参数", verbose_name="温度参数"),
                ),
                (
                    "max_tokens",
                    models.IntegerField(
                        db_comment="单条回复的最大 Token 数量",
                        verbose_name="单条回复的最大 Token 数量",
                    ),
                ),
                (
                    "max_contexts",
                    models.IntegerField(
                        db_comment="上下文的最大 Message 数量",
                        verbose_name="上下文的最大 Message 数量",
                    ),
                ),
                (
                    "model_id",
                    models.ForeignKey(
                        db_column="model_id",
                        db_comment="向量模型编号",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="ai.aimodel",
                        verbose_name="向量模型编号",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        db_comment="用户编号",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户",
                    ),
                ),
                (
                    "role",
                    models.ForeignKey(
                        blank=True,
                        db_comment="聊天角色",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="ai.chatrole",
                        verbose_name="聊天角色",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 聊天对话",
                "verbose_name_plural": "AI 聊天对话",
                "db_table": "ai_chat_conversation",
            },
        ),
        migrations.CreateModel(
            name="Knowledge",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="知识库名称",
                        max_length=255,
                        verbose_name="知识库名称",
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        db_comment="知识库描述",
                        null=True,
                        verbose_name="知识库描述",
                    ),
                ),
                (
                    "embedding_model",
                    models.CharField(
                        db_comment="向量模型标识",
                        max_length=32,
                        verbose_name="向量模型标识",
                    ),
                ),
                (
                    "top_k",
                    models.IntegerField(
                        db_comment="topK", default=0, verbose_name="topK"
                    ),
                ),
                (
                    "similarity_threshold",
                    models.FloatField(
                        db_comment="相似度阈值", verbose_name="相似度阈值"
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        choices=[(0, "禁用"), (1, "启用")],
                        db_comment="状态",
                        default=0,
                        verbose_name="状态",
                    ),
                ),
                (
                    "embedding_model_id",
                    models.ForeignKey(
                        db_column="embedding_model_id",
                        db_comment="向量模型编号",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="ai.aimodel",
                        verbose_name="向量模型编号",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 知识库",
                "verbose_name_plural": "AI 知识库",
                "db_table": "ai_knowledge",
            },
        ),
        migrations.AddField(
            model_name="chatrole",
            name="knowledge",
            field=models.ManyToManyField(
                blank=True,
                db_comment="关联的知识库",
                related_name="roles",
                to="ai.knowledge",
                verbose_name="关联的知识库",
            ),
        ),
        migrations.CreateModel(
            name="KnowledgeDocument",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="文档名称", max_length=255, verbose_name="文档名称"
                    ),
                ),
                (
                    "url",
                    models.CharField(
                        db_comment="文件 URL", max_length=1024, verbose_name="文件 URL"
                    ),
                ),
                ("content", models.TextField(db_comment="内容", verbose_name="内容")),
                (
                    "content_length",
                    models.IntegerField(db_comment="字符数", verbose_name="字符数"),
                ),
                (
                    "tokens",
                    models.IntegerField(
                        db_comment="token 数量", verbose_name="token 数量"
                    ),
                ),
                (
                    "segment_max_tokens",
                    models.IntegerField(
                        db_comment="分片最大 Token 数", verbose_name="分片最大 Token 数"
                    ),
                ),
                (
                    "retrieval_count",
                    models.IntegerField(
                        db_comment="召回次数", default=0, verbose_name="召回次数"
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        choices=[(0, "禁用"), (1, "启用")],
                        db_comment="状态",
                        default=0,
                        verbose_name="状态",
                    ),
                ),
                (
                    "knowledge",
                    models.ForeignKey(
                        db_comment="知识库",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="documents",
                        to="ai.knowledge",
                        verbose_name="知识库",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 知识库文档",
                "verbose_name_plural": "AI 知识库文档",
                "db_table": "ai_knowledge_document",
            },
        ),
        migrations.CreateModel(
            name="KnowledgeSegment",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "remark",
                    models.CharField(
                        blank=True,
                        db_comment="备注",
                        help_text="备注",
                        max_length=256,
                        null=True,
                        verbose_name="备注",
                    ),
                ),
                (
                    "creator",
                    models.CharField(
                        blank=True,
                        db_comment="创建人",
                        help_text="创建人",
                        max_length=64,
                        null=True,
                        verbose_name="创建人",
                    ),
                ),
                (
                    "modifier",
                    models.CharField(
                        blank=True,
                        db_comment="修改人",
                        help_text="修改人",
                        max_length=64,
                        null=True,
                        verbose_name="修改人",
                    ),
                ),
                (
                    "update_time",
                    models.DateTimeField(
                        auto_now=True,
                        db_comment="修改时间",
                        help_text="修改时间",
                        null=True,
                        verbose_name="修改时间",
                    ),
                ),
                (
                    "create_time",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_comment="创建时间",
                        help_text="创建时间",
                        null=True,
                        verbose_name="创建时间",
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_comment="是否软删除",
                        default=False,
                        verbose_name="是否软删除",
                    ),
                ),
                (
                    "content",
                    models.TextField(db_comment="分段内容", verbose_name="分段内容"),
                ),
                (
                    "content_length",
                    models.IntegerField(db_comment="字符数", verbose_name="字符数"),
                ),
                (
                    "tokens",
                    models.IntegerField(
                        db_comment="token 数量", verbose_name="token 数量"
                    ),
                ),
                (
                    "vector_id",
                    models.CharField(
                        blank=True,
                        db_comment="向量库的编号",
                        max_length=100,
                        null=True,
                        verbose_name="向量库的编号",
                    ),
                ),
                (
                    "retrieval_count",
                    models.IntegerField(
                        db_comment="召回次数", default=0, verbose_name="召回次数"
                    ),
                ),
                (
                    "status",
                    models.SmallIntegerField(
                        choices=[(0, "禁用"), (1, "启用")],
                        db_comment="状态",
                        default=0,
                        verbose_name="状态",
                    ),
                ),
                (
                    "document",
                    models.ForeignKey(
                        db_comment="文档",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="segments",
                        to="ai.knowledgedocument",
                        verbose_name="文档",
                    ),
                ),
                (
                    "knowledge",
                    models.ForeignKey(
                        db_comment="知识库",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="segments",
                        to="ai.knowledge",
                        verbose_name="知识库",
                    ),
                ),
            ],
            options={
                "verbose_name": "AI 知识库分段",
                "verbose_name_plural": "AI 知识库分段",
                "db_table": "ai_knowledge_segment",
            },
        ),
        migrations.AddField(
            model_name="chatrole",
            name="tools",
            field=models.ManyToManyField(
                blank=True,
                db_comment="关联的工具",
                related_name="roles",
                to="ai.tool",
                verbose_name="关联的工具",
            ),
        ),
    ]
