mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-10 00:20:06 +08:00
made user structured
This commit is contained in:
@@ -39,8 +39,8 @@ def generate_task(request: protocol_schema.TaskRequest) -> protocol_schema.Task:
|
||||
detail="Invalid request type.",
|
||||
)
|
||||
logger.info(f"Generated {task=}.")
|
||||
if request.user_id is not None:
|
||||
task.addressed_users = [request.user_id]
|
||||
if request.user is not None:
|
||||
task.addressed_users = [request.user]
|
||||
|
||||
return task
|
||||
|
||||
@@ -112,21 +112,21 @@ def post_interaction(
|
||||
match (type(interaction)):
|
||||
case protocol_schema.TextReplyToPost:
|
||||
logger.info(
|
||||
f"Frontend reports text reply to {interaction.post_id=} with {interaction.text=} by {interaction.user_id=}."
|
||||
f"Frontend reports text reply to {interaction.post_id=} with {interaction.text=} by {interaction.user=}."
|
||||
)
|
||||
# here we would store the text reply in the database
|
||||
return protocol_schema.TaskDone(
|
||||
reply_to_post_id=interaction.user_post_id,
|
||||
addressed_users=[interaction.user_id],
|
||||
addressed_users=[interaction.user],
|
||||
)
|
||||
case protocol_schema.PostRating:
|
||||
logger.info(
|
||||
f"Frontend reports rating of {interaction.post_id=} with {interaction.rating=} by {interaction.user_id=}."
|
||||
f"Frontend reports rating of {interaction.post_id=} with {interaction.rating=} by {interaction.user=}."
|
||||
)
|
||||
# here we would store the rating in the database
|
||||
return protocol_schema.TaskDone(
|
||||
reply_to_post_id=interaction.post_id,
|
||||
addressed_users=[interaction.user_id],
|
||||
addressed_users=[interaction.user],
|
||||
)
|
||||
case _:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -13,11 +13,16 @@ class TaskRequestType(str, enum.Enum):
|
||||
rate_summary = "rate_summary"
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
|
||||
|
||||
class TaskRequest(BaseModel):
|
||||
"""The frontend asks the backend for a task."""
|
||||
|
||||
type: TaskRequestType = TaskRequestType.generic
|
||||
user_id: Optional[str] = None
|
||||
user: Optional[User] = None
|
||||
|
||||
|
||||
class Task(BaseModel):
|
||||
@@ -25,7 +30,7 @@ class Task(BaseModel):
|
||||
|
||||
id: UUID = pydantic.Field(default_factory=uuid4)
|
||||
type: str
|
||||
addressed_users: Optional[list[str]] = None
|
||||
addressed_users: Optional[list[User]] = None
|
||||
|
||||
|
||||
class TaskResponse(BaseModel):
|
||||
@@ -81,10 +86,10 @@ AnyTask = Union[
|
||||
|
||||
|
||||
class Interaction(BaseModel):
|
||||
"""An interaction is a message from the frontend to the backend."""
|
||||
"""An interaction is a user-generated action in the frontend."""
|
||||
|
||||
type: str
|
||||
user_id: str
|
||||
user: User
|
||||
|
||||
|
||||
class TextReplyToPost(Interaction):
|
||||
|
||||
@@ -38,7 +38,7 @@ def main(backend_url: str, api_key: str):
|
||||
"post_id": "1234",
|
||||
"user_post_id": "5678",
|
||||
"text": summary,
|
||||
"user_id": "1234",
|
||||
"user": {"id": "1234", "name": "John Doe"},
|
||||
},
|
||||
)
|
||||
tasks.append(new_task)
|
||||
@@ -60,7 +60,7 @@ def main(backend_url: str, api_key: str):
|
||||
"type": "post_rating",
|
||||
"post_id": "1234",
|
||||
"rating": rating,
|
||||
"user_id": "1234",
|
||||
"user": {"id": "1234", "name": "John Doe"},
|
||||
},
|
||||
)
|
||||
tasks.append(new_task)
|
||||
|
||||
Reference in New Issue
Block a user