Spaces:
Sleeping
Sleeping
File size: 5,552 Bytes
3b86501 8ebe686 3b86501 8ebe686 3b86501 8ebe686 3b86501 8ebe686 3b86501 8ebe686 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
from pydantic import BaseModel, Field
from typing import List, Optional
from uuid import UUID
from datetime import datetime
from typing import Literal, Optional, Union
from pydantic import BaseModel, Field, HttpUrl
from pydantic.types import NonNegativeInt
from enum import Enum
class Engagement(BaseModel):
upvote: int
downvote: int
comment: int
award: int
class Item(BaseModel):
id: UUID = Field(..., example=UUID("3fa85f64-5717-4562-b3fc-2c963f66afa6"))
#post_id: Optional[UUID] = None
#parent_id: Optional[UUID] = None
#title: Optional[str] = None
text: str = Field(..., example="I never liked politicians anyway, they don't care much about citizens")
#author_name_hash: str
#type: str
#created_at: str
#engagements: Engagement
class Platform(Enum):
TWITTER = "twitter"
FACEBOOK = "facebook"
REDDIT = "reddit"
class Session(BaseModel):
user_id: UUID = Field(..., example=UUID("4fa85f64-5717-4562-b3fc-2c963f66afd6"))
user_name_hash: str
platform: Platform = Field(..., example=Platform.TWITTER)
current_time: datetime = Field(..., example="2024-04-09T19:29:38.072017Z")
class Input(BaseModel):
session: Session
items: List[Item]
class NewItem(BaseModel):
id: UUID
url: str
class Output(BaseModel):
ranked_ids: List[UUID]
new_items: List[Optional[NewItem]]
class TwitterEngagements(BaseModel):
"""Engagement counts from Twitter"""
retweet: NonNegativeInt
like: NonNegativeInt
comment: NonNegativeInt
share: NonNegativeInt
class RedditEngagements(BaseModel):
"""Engagement counts from Reddit"""
upvote: NonNegativeInt
downvote: NonNegativeInt
comment: NonNegativeInt
award: NonNegativeInt
class FacebookEngagements(BaseModel):
"""Engagement counts from Facebook"""
like: NonNegativeInt
love: NonNegativeInt
care: NonNegativeInt
haha: NonNegativeInt
wow: NonNegativeInt
sad: NonNegativeInt
angry: NonNegativeInt
comment: NonNegativeInt
share: NonNegativeInt
class ContentItem(BaseModel):
"""A content item to be ranked"""
id: str = Field(
description="A unique ID describing a specific piece of content. We will do our best to make an ID for a given item persist between requests, but that property is not guaranteed."
)
post_id: Optional[str] = Field(
description="The ID of the post to which this comment belongs. Useful for linking comments to their post when comments are shown in a feed. Currently this UX only exists on Facebook.",
default=None,
)
parent_id: Optional[str] = Field(
description="For threaded comments, this identifies the comment to which this one is a reply. Blank for top-level comments.",
default=None,
)
title: Optional[str] = Field(
description="The post title, only available on reddit posts.", default=None
)
text: str = Field(
description="The text of the content item. Assume UTF-8, and that leading and trailing whitespace have been trimmed."
)
author_name_hash: str = Field(
description="A hash of the author's name (salted). Use this to determine which posts are by the same author. When the post is by the current user, this should match `session.user_name_hash`."
)
type: Literal["post", "comment"] = Field(
description="Whether the content item is a `post` or `comment`. On Twitter, tweets will be identified as `comment` when they are replies displayed on the page for a single tweet."
)
embedded_urls: Optional[list[HttpUrl]] = Field(
description="A list of URLs that are embedded in the content item. This could be links to images, videos, or other content. They may or may not also appear in the text of the item."
)
created_at: datetime = Field(
description="The time that the item was created in UTC, in `YYYY-MM-DD hh:mm:ss` format, at the highest resolution available (which may be as low as the hour)."
)
engagements: Union[TwitterEngagements, RedditEngagements, FacebookEngagements] = (
Field(description="Engagement counts for the content item.")
)
class Session(BaseModel):
"""Data that is scoped to the user's browsing session (generally a single page view)"""
user_id: str = Field(
description="A unique id for this study participant. Will remain fixed for the duration of the experiment."
)
user_name_hash: str = Field(
description="A (salted) hash of the user's username. We'll do our best to make it match the `item.author_name_hash` on posts authored by the current user."
)
cohort: str = Field(
description="The cohort to which the user has been assigned. You can safely ignore this. It is used by the PRC request router."
)
platform: Literal["twitter", "reddit", "facebook"] = Field(
description="The platform on which the user is viewing content."
)
current_time: datetime = Field(
description="The current time according to the user's browser, in UTC, in `YYYY-MM-DD hh:mm:ss` format."
)
class RankingRequest(BaseModel):
"""A complete ranking request"""
session: Session = Field(
description="Data that is scoped to the user's browsing session"
)
#survey: Optional[SurveyResponse] = Field(
# description="Responses to PRC survey. Added by the request router.",
# default=None,
#)
items: list[ContentItem] = Field(description="The content items to be ranked.") |