Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store worker compliance check results, add initial scoring algorithm (#…
…1894) Closes #1892, This also refactors `models.py` into several model definition files by category.
- Loading branch information
1 parent
d8e1027
commit 5c6907f
Showing
6 changed files
with
185 additions
and
41 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...erver/alembic/versions/2023_02_26_1328-a2865908a537_add_worker_compliance_checks_to_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Add worker compliance checks to db | ||
Revision ID: a2865908a537 | ||
Revises: e7a4bffb424c | ||
Create Date: 2023-02-26 13:28:25.181340 | ||
""" | ||
import sqlalchemy as sa | ||
import sqlmodel | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a2865908a537" | ||
down_revision = "e7a4bffb424c" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"worker_compliance_check", | ||
sa.Column("id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("worker_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("compare_worker_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("start_time", sa.DateTime(), nullable=False), | ||
sa.Column("end_time", sa.DateTime(), nullable=True), | ||
sa.Column("responded", sa.Boolean(), nullable=False), | ||
sa.Column("error", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.Column("passed", sa.Boolean(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["worker_id"], | ||
["worker.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index( | ||
op.f("ix_worker_compliance_check_worker_id"), "worker_compliance_check", ["worker_id"], unique=False | ||
) | ||
op.create_index( | ||
op.f("ix_worker_compliance_check_compare_worker_id"), | ||
"worker_compliance_check", | ||
["compare_worker_id"], | ||
unique=False, | ||
) | ||
op.alter_column("chat", "user_id", existing_type=sa.VARCHAR(), nullable=False) | ||
op.create_index(op.f("ix_report_message_id"), "report", ["message_id"], unique=False) | ||
op.create_index(op.f("ix_vote_message_id"), "vote", ["message_id"], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f("ix_vote_message_id"), table_name="vote") | ||
op.drop_index(op.f("ix_report_message_id"), table_name="report") | ||
op.alter_column("chat", "user_id", existing_type=sa.VARCHAR(), nullable=True) | ||
op.drop_index(op.f("ix_worker_compliance_check_worker_id"), table_name="worker_compliance_check") | ||
op.drop_index(op.f("ix_worker_compliance_check_compare_worker_id"), table_name="worker_compliance_check") | ||
op.drop_table("worker_compliance_check") | ||
# ### end Alembic commands ### |
15 changes: 15 additions & 0 deletions
15
inference/server/oasst_inference_server/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .chat import DbChat, DbMessage, DbReport, DbVote | ||
from .user import DbUser | ||
from .worker import DbWorker, DbWorkerComplianceCheck, DbWorkerEvent, WorkerEventType | ||
|
||
__all__ = [ | ||
"DbChat", | ||
"DbMessage", | ||
"DbReport", | ||
"DbVote", | ||
"DbUser", | ||
"DbWorker", | ||
"DbWorkerComplianceCheck", | ||
"DbWorkerEvent", | ||
"WorkerEventType", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from uuid import uuid4 | ||
|
||
from sqlmodel import Field, Index, SQLModel | ||
|
||
|
||
class DbUser(SQLModel, table=True): | ||
__tablename__ = "user" | ||
__table_args__ = (Index("provider", "provider_account_id", unique=True),) | ||
|
||
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True) | ||
|
||
provider: str = Field(index=True) | ||
provider_account_id: str = Field(index=True) | ||
|
||
display_name: str = Field(nullable=False, max_length=256) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import datetime | ||
import enum | ||
from uuid import uuid4 | ||
|
||
import sqlalchemy as sa | ||
import sqlalchemy.dialects.postgresql as pg | ||
from oasst_shared.schemas import inference | ||
from sqlmodel import Field, Relationship, SQLModel | ||
|
||
|
||
class WorkerEventType(str, enum.Enum): | ||
connect = "connect" | ||
|
||
|
||
class DbWorkerComplianceCheck(SQLModel, table=True): | ||
__tablename__ = "worker_compliance_check" | ||
|
||
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True) | ||
worker_id: str = Field(foreign_key="worker.id", index=True) | ||
worker: "DbWorker" = Relationship(back_populates="compliance_checks") | ||
compare_worker_id: str = Field(foreign_key="worker.id", index=True) | ||
|
||
start_time: datetime.datetime = Field(default_factory=datetime.datetime.utcnow) | ||
end_time: datetime.datetime | None = Field(None, nullable=True) | ||
responded: bool = Field(default=False, nullable=False) | ||
error: str | None = Field(None, nullable=True) | ||
passed: bool = Field(default=False, nullable=False) | ||
|
||
|
||
class DbWorkerEvent(SQLModel, table=True): | ||
__tablename__ = "worker_event" | ||
|
||
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True) | ||
worker_id: str = Field(foreign_key="worker.id", index=True) | ||
worker: "DbWorker" = Relationship(back_populates="events") | ||
time: datetime.datetime = Field(default_factory=datetime.datetime.utcnow) | ||
event_type: WorkerEventType | ||
worker_config: inference.WorkerConfig | None = Field(None, sa_column=sa.Column(pg.JSONB)) | ||
|
||
|
||
class DbWorker(SQLModel, table=True): | ||
__tablename__ = "worker" | ||
|
||
id: str = Field(default_factory=lambda: str(uuid4()), primary_key=True) | ||
api_key: str = Field(default_factory=lambda: str(uuid4()), index=True) | ||
name: str | ||
|
||
compliance_checks: list[DbWorkerComplianceCheck] = Relationship(back_populates="worker") | ||
in_compliance_check: bool = Field(default=False, sa_column=sa.Column(sa.Boolean, server_default=sa.text("false"))) | ||
next_compliance_check: datetime.datetime | None = Field(None) | ||
events: list[DbWorkerEvent] = Relationship(back_populates="worker") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters