Skip to content

Commit

Permalink
Merge pull request #50 from LAION-AI/bot_dev
Browse files Browse the repository at this point in the history
add first bits of jinja template support
  • Loading branch information
andreaskoepf committed Dec 23, 2022
2 parents 55c79b9 + 1276365 commit b4cdced
Show file tree
Hide file tree
Showing 32 changed files with 798 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: "build|stubs"
exclude: "build|stubs|^bot/templates/"

default_language_version:
python: python3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""add_auth_method_to_ix_person_username
Revision ID: 0daec5f8135f
Revises: 6368515778c5
Create Date: 2022-12-22 18:35:59.609013
"""
import sqlalchemy as sa # noqa: F401
from alembic import op

# revision identifiers, used by Alembic.
revision = "0daec5f8135f"
down_revision = "6368515778c5"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_person_username", table_name="person")
op.create_index("ix_person_username", "person", ["api_client_id", "username", "auth_method"], unique=True)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_person_username", table_name="person")
op.create_index("ix_person_username", "person", ["api_client_id", "username"], unique=False)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion backend/oasst_backend/api/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def acknowledge_task(
pr = PromptRepository(db, api_client, user=None)

# here we store the post id in the database for the task
pr.bind_frontend_post_id(task_id=task_id, post_id=ack_request.post_id)
logger.info(f"Frontend acknowledges task {task_id=}, {ack_request=}.")
pr.bind_frontend_post_id(task_id=task_id, post_id=ack_request.post_id)

except Exception:
logger.exception("Failed to acknowledge task.")
Expand Down
2 changes: 1 addition & 1 deletion backend/oasst_backend/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Person(SQLModel, table=True):
__tablename__ = "person"
__table_args__ = (Index("ix_person_username", "api_client_id", "username", unique=True),)
__table_args__ = (Index("ix_person_username", "api_client_id", "username", "auth_method", unique=True),)

id: Optional[UUID] = Field(
sa_column=sa.Column(
Expand Down
7 changes: 6 additions & 1 deletion backend/oasst_backend/prompt_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def lookup_person(self, user: protocol_schema.User) -> Person:
)
if person is None:
# user is unknown, create new record
person = Person(username=user.id, display_name=user.display_name, api_client_id=self.api_client.id)
person = Person(
username=user.id,
display_name=user.display_name,
api_client_id=self.api_client.id,
auth_method=user.auth_method,
)
self.db.add(person)
self.db.commit()
self.db.refresh(person)
Expand Down
2 changes: 2 additions & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
backend_url=settings.BACKEND_URL,
api_key=settings.API_KEY,
owner_id=settings.OWNER_ID,
template_dir=settings.TEMPLATE_DIR,
debug=settings.DEBUG,
)
bot.run()
2 changes: 1 addition & 1 deletion bot/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def nack_task(self, task_id: str, reason: str) -> None:
req = protocol_schema.TaskNAck(reason=reason)
return self.post(f"/api/v1/tasks/{task_id}/nack", req.dict())

def post_interaction(self, interaction: protocol_schema.Interaction) -> protocol_schema.TaskDone:
def post_interaction(self, interaction: protocol_schema.Interaction) -> protocol_schema.Task:
data = self.post("/api/v1/tasks/interaction", interaction.dict())
return self._parse_task(data)

0 comments on commit b4cdced

Please sign in to comment.