Message tree state machine (#555)

* add query_incomplete_rankings()

* Add SQL queries for TreeManager task selection

* first working version of TreeManager.next_task()

* remove old generate_task(), add mandatory_labels to text_labels task

* Add ConversationMessage list to Ranking tasks

* add more sophisticated sql queries to find extendible trees

* add TreeManager.query_extendible_parents()

* fix task validation, seed data insertion (reviewed)

* provide user for task selection in text-frontend

* enter 'growing' state

* enter 'aborted_low_grade' state

* enter 'ranking' state

* check tree 'growing' state upon relpy insertion

* exclude user from labeling their own messages (added DEBUG_ALLOW_SELF_LABELING setting)

* add DEBUG_ALLOW_SELF_LABELING to docker-compose.yaml

* fix ranking submission

* add query_tree_ranking_results()

* add ranked_message_ids to RankingReactionPayload

* fix reply_messages instead of prompt_messages

* incorment 'ranking_count' of ranked replies

* added logic to check_condition_for_scoring_state

* changes to msg_tree_state_machine

* pre-commit changes

* enter 'ready_for_scoring' state

* re-add HF embedding call (lost during merge)

* use prepare_conversation() helper for seed-data creation

* Partially add user specified task selection

Co-authored-by: Daniel Hug <danielpatrickhug@gmail.com>
This commit is contained in:
Andreas Köpf
2023-01-11 10:54:03 +01:00
committed by GitHub
co-authored by Daniel Hug
parent 23ff01c603
commit 14fa08e2e7
19 changed files with 1212 additions and 323 deletions
@@ -17,9 +17,11 @@ class OasstErrorCode(IntEnum):
GENERIC_ERROR = 0
DATABASE_URI_NOT_SET = 1
API_CLIENT_NOT_AUTHORIZED = 2
SERVER_ERROR = 3
TOO_MANY_REQUESTS = 429
SERVER_ERROR0 = 500
SERVER_ERROR1 = 501
# 1000-2000: tasks endpoint
TASK_INVALID_REQUEST_TYPE = 1000
TASK_ACK_FAILED = 1001
@@ -27,6 +29,7 @@ class OasstErrorCode(IntEnum):
TASK_INVALID_RESPONSE_TYPE = 1003
TASK_INTERACTION_REQUEST_FAILED = 1004
TASK_GENERATION_FAILED = 1005
TASK_REQUESTED_TYPE_NOT_AVAILABLE = 1006
# 2000-3000: prompt_repository
INVALID_FRONTEND_MESSAGE_ID = 2000
@@ -38,6 +41,14 @@ class OasstErrorCode(IntEnum):
NO_MESSAGE_TREE_FOUND = 2006
NO_REPLIES_FOUND = 2007
INVALID_MESSAGE = 2008
BROKEN_CONVERSATION = 2009
TREE_NOT_IN_GROWING_STATE = 2010
CORRUPT_RANKING_RESULT = 2011
TEXT_LABELS_WRONG_MESSAGE_ID = 2050
TEXT_LABELS_INVALID_LABEL = 2051
TEXT_LABELS_MANDATORY_LABEL_MISSING = 2052
TASK_NOT_FOUND = 2100
TASK_EXPIRED = 2101
TASK_PAYLOAD_TYPE_MISMATCH = 2102
@@ -45,6 +56,7 @@ class OasstErrorCode(IntEnum):
TASK_NOT_ACK = 2104
TASK_ALREADY_DONE = 2105
TASK_NOT_COLLECTIVE = 2106
TASK_NOT_ASSIGNED_TO_USER = 2106
USER_NOT_FOUND = 2200
# 3000-4000: external resources
@@ -151,7 +151,8 @@ class RankInitialPromptsTask(Task):
"""A task to rank a set of initial prompts."""
type: Literal["rank_initial_prompts"] = "rank_initial_prompts"
prompts: list[str]
prompts: list[str] # deprecated, use prompt_messages
prompt_messages: list[ConversationMessage]
class RankConversationRepliesTask(Task):
@@ -159,7 +160,8 @@ class RankConversationRepliesTask(Task):
type: Literal["rank_conversation_replies"] = "rank_conversation_replies"
conversation: Conversation # the conversation so far
replies: list[str]
replies: list[str] # deprecated, use reply_messages
reply_messages: list[ConversationMessage]
class RankPrompterRepliesTask(RankConversationRepliesTask):
@@ -181,6 +183,7 @@ class LabelInitialPromptTask(Task):
message_id: UUID
prompt: str
valid_labels: list[str]
mandatory_labels: Optional[list[str]]
class LabelConversationReplyTask(Task):
@@ -191,6 +194,7 @@ class LabelConversationReplyTask(Task):
message_id: UUID
reply: str
valid_labels: list[str]
mandatory_labels: Optional[list[str]]
class LabelPrompterReplyTask(LabelConversationReplyTask):
@@ -304,6 +308,7 @@ class TextLabels(Interaction):
text: str
labels: dict[TextLabel, float]
message_id: UUID
task_id: Optional[UUID]
@property
def has_message_id(self) -> bool: