diff --git a/backend/oasst_backend/api/v1/text_labels.py b/backend/oasst_backend/api/v1/text_labels.py index 97422119..5b18e4ea 100644 --- a/backend/oasst_backend/api/v1/text_labels.py +++ b/backend/oasst_backend/api/v1/text_labels.py @@ -3,6 +3,7 @@ from fastapi.security.api_key import APIKey from loguru import logger from oasst_backend.api import deps from oasst_backend.prompt_repository import PromptRepository +from oasst_backend.schemas.text_labels import LabelOption, ValidLabelsResponse from oasst_shared.schemas import protocol as protocol_schema from sqlmodel import Session from starlette.status import HTTP_204_NO_CONTENT, HTTP_400_BAD_REQUEST @@ -32,3 +33,10 @@ def label_text( raise HTTPException( status_code=HTTP_400_BAD_REQUEST, ) + + +@router.get("/valid_labels") +def get_valid_lables() -> ValidLabelsResponse: + return ValidLabelsResponse( + valid_labels=[LabelOption(name=l.value, description=l.description) for l in protocol_schema.TextLabel] + ) diff --git a/backend/oasst_backend/schemas/text_labels.py b/backend/oasst_backend/schemas/text_labels.py new file mode 100644 index 00000000..e7160236 --- /dev/null +++ b/backend/oasst_backend/schemas/text_labels.py @@ -0,0 +1,10 @@ +from pydantic import BaseModel + + +class LabelOption(BaseModel): + name: str + description: str + + +class ValidLabelsResponse(BaseModel): + valid_labels: list[LabelOption] diff --git a/oasst-shared/oasst_shared/schemas/protocol.py b/oasst-shared/oasst_shared/schemas/protocol.py index f8af590e..b87575a9 100644 --- a/oasst-shared/oasst_shared/schemas/protocol.py +++ b/oasst-shared/oasst_shared/schemas/protocol.py @@ -265,10 +265,23 @@ class MessageRanking(Interaction): class TextLabel(str, enum.Enum): """A label for a piece of text.""" + def __new__(cls, label, description=""): + obj = str.__new__(cls, label) + obj._value_ = label + obj.description = description + return obj + spam = "spam" - violence = "violence" - sexual_content = "sexual_content" + fails_task = "fails_task", "Fails to follow the correct instruction / task" + not_appropriate = "not_appropriate", "Inappropriate for customer assistant" + violence = "violence", "Encourages or fails to discourage violence/abuse/terrorism/self-harm" + harmful = ( + "harmful", + "The advice given in the output is harmful or counter-productive. This may be in addition to, but is distinct from the question about encouraging violence/abuse/terrorism/self-harm.", + ) + sexual_content = "sexual_content", "Contains sexual content" toxicity = "toxicity" + moral_judgement = "moral_judgement", "Expresses moral judgement" political_content = "political_content" humor = "humor" sarcasm = "sarcasm"