feat: add fixed questions and improve authentication

This commit is contained in:
吉鑫升 committed 2026-08-21 17:58:39 +08:00
1 parent 8af4fed89d
commit 4c9f75f31e
42 files changed
+4008 -200

No files matched your search

@@ -0,0 +1,51 @@
"""Create administrator-managed exact-match fixed questions.
Revision ID: 20260821_01
Revises: 20260816_01
Create Date: 2026-08-21
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql
revision = "20260821_01"
down_revision = "20260816_01"
branch_labels = None
depends_on = None
def upgrade() -> None:
bind = op.get_bind()
if sa.inspect(bind).has_table("fixed_questions"):
return
long_text = sa.Text().with_variant(mysql.LONGTEXT(), "mysql")
op.create_table(
"fixed_questions",
sa.Column("id", sa.String(length=64), primary_key=True),
sa.Column("question", sa.Text(), nullable=False),
sa.Column("question_hash", sa.String(length=64), nullable=False),
sa.Column("answer", long_text, nullable=False),
sa.Column("enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("sort_order", sa.Integer(), nullable=False, server_default="0"),
sa.Column("updated_by", sa.String(length=64), nullable=True),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
sa.UniqueConstraint(
"question_hash",
name="uq_fixed_questions_question_hash",
),
)
op.create_index(
"ix_fixed_questions_question_hash",
"fixed_questions",
["question_hash"],
unique=False,
)
def downgrade() -> None:
bind = op.get_bind()
if sa.inspect(bind).has_table("fixed_questions"):
op.drop_table("fixed_questions")
@@ -0,0 +1,44 @@
"""Add configurable fixed-answer streaming speed.
Revision ID: 20260821_02
Revises: 20260821_01
Create Date: 2026-08-21
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
revision = "20260821_02"
down_revision = "20260821_01"
branch_labels = None
depends_on = None
def upgrade() -> None:
bind = op.get_bind()
inspector = sa.inspect(bind)
if not inspector.has_table("fixed_questions"):
return
columns = {column["name"] for column in inspector.get_columns("fixed_questions")}
if "tokens_per_second" not in columns:
op.add_column(
"fixed_questions",
sa.Column(
"tokens_per_second",
sa.Integer(),
nullable=False,
server_default="100",
),
)
def downgrade() -> None:
bind = op.get_bind()
inspector = sa.inspect(bind)
if not inspector.has_table("fixed_questions"):
return
columns = {column["name"] for column in inspector.get_columns("fixed_questions")}
if "tokens_per_second" in columns:
op.drop_column("fixed_questions", "tokens_per_second")