Explorar el Código

example on orm typing (#23322)

tags/1.8.0
Asuka Minato hace 2 meses
padre
commit
58165c3951
No account linked to committer's email address
Se han modificado 4 ficheros con 10 adiciones y 9 borrados
  1. 1
    0
      api/core/helper/encrypter.py
  2. 3
    3
      api/models/account.py
  3. 2
    2
      api/models/dataset.py
  4. 4
    4
      api/models/model.py

+ 1
- 0
api/core/helper/encrypter.py Ver fichero



if not (tenant := db.session.query(Tenant).where(Tenant.id == tenant_id).first()): if not (tenant := db.session.query(Tenant).where(Tenant.id == tenant_id).first()):
raise ValueError(f"Tenant with id {tenant_id} not found") raise ValueError(f"Tenant with id {tenant_id} not found")
assert tenant.encrypt_public_key is not None
encrypted_token = rsa.encrypt(token, tenant.encrypt_public_key) encrypted_token = rsa.encrypt(token, tenant.encrypt_public_key)
return base64.b64encode(encrypted_token).decode() return base64.b64encode(encrypted_token).decode()



+ 3
- 3
api/models/account.py Ver fichero



id: Mapped[str] = mapped_column(StringUUID, server_default=sa.text("uuid_generate_v4()")) id: Mapped[str] = mapped_column(StringUUID, server_default=sa.text("uuid_generate_v4()"))
name: Mapped[str] = mapped_column(String(255)) name: Mapped[str] = mapped_column(String(255))
encrypt_public_key = db.Column(sa.Text)
encrypt_public_key: Mapped[Optional[str]] = mapped_column(sa.Text)
plan: Mapped[str] = mapped_column(String(255), server_default=sa.text("'basic'::character varying")) plan: Mapped[str] = mapped_column(String(255), server_default=sa.text("'basic'::character varying"))
status: Mapped[str] = mapped_column(String(255), server_default=sa.text("'normal'::character varying")) status: Mapped[str] = mapped_column(String(255), server_default=sa.text("'normal'::character varying"))
custom_config: Mapped[Optional[str]] = mapped_column(sa.Text) custom_config: Mapped[Optional[str]] = mapped_column(sa.Text)
upgrade_mode: Mapped[UpgradeMode] = mapped_column(String(16), nullable=False, server_default="exclude") upgrade_mode: Mapped[UpgradeMode] = mapped_column(String(16), nullable=False, server_default="exclude")
exclude_plugins: Mapped[list[str]] = mapped_column(sa.ARRAY(String(255)), nullable=False) # plugin_id (author/name) exclude_plugins: Mapped[list[str]] = mapped_column(sa.ARRAY(String(255)), nullable=False) # plugin_id (author/name)
include_plugins: Mapped[list[str]] = mapped_column(sa.ARRAY(String(255)), nullable=False) # plugin_id (author/name) include_plugins: Mapped[list[str]] = mapped_column(sa.ARRAY(String(255)), nullable=False) # plugin_id (author/name)
created_at = db.Column(DateTime, nullable=False, server_default=func.current_timestamp())
updated_at = db.Column(DateTime, nullable=False, server_default=func.current_timestamp())
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp())
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp())

+ 2
- 2
api/models/dataset.py Ver fichero

created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp()) created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp())
updated_by = mapped_column(StringUUID, nullable=True) updated_by = mapped_column(StringUUID, nullable=True)
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp()) updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.current_timestamp())
embedding_model = db.Column(String(255), nullable=True) # TODO: mapped_column
embedding_model_provider = db.Column(String(255), nullable=True) # TODO: mapped_column
embedding_model = mapped_column(String(255), nullable=True)
embedding_model_provider = mapped_column(String(255), nullable=True)
collection_binding_id = mapped_column(StringUUID, nullable=True) collection_binding_id = mapped_column(StringUUID, nullable=True)
retrieval_model = mapped_column(JSONB, nullable=True) retrieval_model = mapped_column(JSONB, nullable=True)
built_in_field_enabled: Mapped[bool] = mapped_column(sa.Boolean, nullable=False, server_default=sa.text("false")) built_in_field_enabled: Mapped[bool] = mapped_column(sa.Boolean, nullable=False, server_default=sa.text("false"))

+ 4
- 4
api/models/model.py Ver fichero

description: Mapped[str] = mapped_column(sa.Text, server_default=sa.text("''::character varying")) description: Mapped[str] = mapped_column(sa.Text, server_default=sa.text("''::character varying"))
mode: Mapped[str] = mapped_column(String(255)) mode: Mapped[str] = mapped_column(String(255))
icon_type: Mapped[Optional[str]] = mapped_column(String(255)) # image, emoji icon_type: Mapped[Optional[str]] = mapped_column(String(255)) # image, emoji
icon = db.Column(String(255))
icon = mapped_column(String(255))
icon_background: Mapped[Optional[str]] = mapped_column(String(255)) icon_background: Mapped[Optional[str]] = mapped_column(String(255))
app_model_config_id = mapped_column(StringUUID, nullable=True) app_model_config_id = mapped_column(StringUUID, nullable=True)
workflow_id = mapped_column(StringUUID, nullable=True) workflow_id = mapped_column(StringUUID, nullable=True)
message_tokens: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0")) message_tokens: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0"))
message_unit_price = mapped_column(sa.Numeric(10, 4), nullable=False) message_unit_price = mapped_column(sa.Numeric(10, 4), nullable=False)
message_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001")) message_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001"))
answer: Mapped[str] = db.Column(sa.Text, nullable=False) # TODO make it mapped_column
answer: Mapped[str] = mapped_column(sa.Text, nullable=False)
answer_tokens: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0")) answer_tokens: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0"))
answer_unit_price = mapped_column(sa.Numeric(10, 4), nullable=False) answer_unit_price = mapped_column(sa.Numeric(10, 4), nullable=False)
answer_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001")) answer_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001"))
app_id: Mapped[str] = mapped_column(StringUUID) app_id: Mapped[str] = mapped_column(StringUUID)
conversation_id: Mapped[Optional[str]] = mapped_column(StringUUID, sa.ForeignKey("conversations.id")) conversation_id: Mapped[Optional[str]] = mapped_column(StringUUID, sa.ForeignKey("conversations.id"))
message_id: Mapped[Optional[str]] = mapped_column(StringUUID) message_id: Mapped[Optional[str]] = mapped_column(StringUUID)
question = db.Column(sa.Text, nullable=True)
question = mapped_column(sa.Text, nullable=True)
content = mapped_column(sa.Text, nullable=False) content = mapped_column(sa.Text, nullable=False)
hit_count: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0")) hit_count: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0"))
account_id = mapped_column(StringUUID, nullable=False) account_id = mapped_column(StringUUID, nullable=False)
message_unit_price = mapped_column(sa.Numeric, nullable=True) message_unit_price = mapped_column(sa.Numeric, nullable=True)
message_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001")) message_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001"))
message_files = mapped_column(sa.Text, nullable=True) message_files = mapped_column(sa.Text, nullable=True)
answer = db.Column(sa.Text, nullable=True)
answer = mapped_column(sa.Text, nullable=True)
answer_token: Mapped[Optional[int]] = mapped_column(sa.Integer, nullable=True) answer_token: Mapped[Optional[int]] = mapped_column(sa.Integer, nullable=True)
answer_unit_price = mapped_column(sa.Numeric, nullable=True) answer_unit_price = mapped_column(sa.Numeric, nullable=True)
answer_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001")) answer_price_unit = mapped_column(sa.Numeric(10, 7), nullable=False, server_default=sa.text("0.001"))

Cargando…
Cancelar
Guardar