Skip to content

Commit

Permalink
Added readable exception if no posts were found for task
Browse files Browse the repository at this point in the history
  • Loading branch information
mjagkow authored and andreaskoepf committed Dec 29, 2022
1 parent c5053ed commit 4ead078
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/oasst_backend/exceptions.py
Expand Up @@ -34,6 +34,7 @@ class OasstErrorCode(IntEnum):
INVALID_TASK_TYPE = 2004
USER_NOT_SPECIFIED = 2005
NO_THREADS_FOUND = 2006
NO_REPLIES_FOUND = 2007
WORK_PACKAGE_NOT_FOUND = 2100
WORK_PACKAGE_EXPIRED = 2101
WORK_PACKAGE_PAYLOAD_TYPE_MISMATCH = 2102
Expand Down
2 changes: 2 additions & 0 deletions backend/oasst_backend/prompt_repository.py
Expand Up @@ -445,6 +445,8 @@ def fetch_multiple_random_replies(self, max_size: int = 5, post_role: str = None

parent = parent.order_by(func.random()).limit(1).subquery()
replies = self.db.query(Post).filter(Post.parent_id.in_(parent)).order_by(func.random()).limit(max_size).all()
if not replies:
raise OasstError("No replies found", OasstErrorCode.NO_REPLIES_FOUND)

thread = self.fetch_thread(replies[0].thread_id)
thread = {p.id: p for p in thread}
Expand Down

0 comments on commit 4ead078

Please sign in to comment.