Spaces:
Runtime error
Runtime error
Download server/schemas.py from TheAbyss99/abyss-api: direct link, hf CLI and curl.
- Browser
- Download file 3.06 kB
-
https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/server/schemas.py
- Command line
-
hf download hf://spaces/TheAbyss99/abyss-api/server/schemas.py
-
curl -L -o schemas.py https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/server/schemas.py
3.06 kB
| from pydantic import BaseModel, field_validator, model_validator | |
| from typing import List, Literal, Optional | |
| from server.limits import ( | |
| MAX_OUTPUT_TOKENS, | |
| MAX_MESSAGES, | |
| MAX_MESSAGE_CHARS, | |
| MAX_PROMPT_CHARS, | |
| ) | |
| class ChatMessage(BaseModel): | |
| role: Literal["system", "user", "assistant"] | |
| content: str | |
| class _GenRequest(BaseModel): | |
| """Sharded size/token caps for generation requests (Phase S).""" | |
| def _clamp_tokens(cls, v: int) -> int: | |
| if v < 1: | |
| raise ValueError("max_tokens must be >= 1") | |
| return min(v, MAX_OUTPUT_TOKENS) # Clamp, don't reject | |
| def _check_size(self): | |
| msgs = getattr(self, "messages", None) | |
| if not msgs: | |
| raise ValueError("messages must not be empty") | |
| if len(msgs) > MAX_MESSAGES: | |
| raise ValueError(f"too many messages (max {MAX_MESSAGES})") | |
| total = 0 | |
| for m in msgs: | |
| if len(m.content) > MAX_MESSAGE_CHARS: | |
| raise ValueError(f"a message exceeds {MAX_MESSAGE_CHARS} chars") | |
| total += len(m.content) | |
| if total > MAX_PROMPT_CHARS: | |
| raise ValueError(f"prompt too long (max {MAX_PROMPT_CHARS} chars)") | |
| return self | |
| class ChatRequest(_GenRequest): | |
| model: str = "abyss-1" | |
| messages: List[ChatMessage] | |
| max_tokens: int = 200 | |
| temperature: float = 0.7 | |
| top_k: int = 40 | |
| top_p: float = 0.95 | |
| stream: bool = True | |
| conversation_id: Optional[str] = None | |
| class ModelCard(BaseModel): | |
| id: str | |
| object: str = "model" | |
| owned_by: str = "the-abyss" | |
| class ModelList(BaseModel): | |
| object: str = "list" | |
| data: List[ModelCard] | |
| class RegisterRequest(BaseModel): | |
| username: str | |
| email: str | |
| password: str | |
| class LoginRequest(BaseModel): | |
| email: str | |
| password: str | |
| class TokenResponse(BaseModel): | |
| access_token: str | |
| token_type: str = "bearer" | |
| username: str | |
| class UserResponse(BaseModel): | |
| id: str | |
| username: str | |
| email: str | |
| class AgentRequest(_GenRequest): | |
| model: str = "Abyss-1.0" | |
| messages: List[ChatMessage] | |
| max_tokens: int = 300 | |
| temperature: float = 0.7 | |
| top_k: int = 40 | |
| top_p: float = 0.95 | |
| stream: bool = True | |
| conversation_id: Optional[str] = None | |
| # ----- MODERATION (PHASE W) ----- | |
| class ModerationRequest(BaseModel): | |
| input: str | |
| def _cap(cls, v: str) -> str: | |
| if not v: | |
| raise ValueError("input must not be empty") | |
| if len(v) > MAX_PROMPT_CHARS: | |
| raise ValueError(f"input too long (max {MAX_PROMPT_CHARS} chars)") | |
| return v | |
| class ModerationResponse(BaseModel): | |
| flagged: bool | |
| severity: str | |
| action: str | |
| top_category: Optional[str] = None | |
| score: float = 0.0 | |
| categories: dict = {} | |
| reason: str = "" |