Spaces:
Sleeping
Sleeping
Upload models.py with huggingface_hub
Browse files
models.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pydantic models for Nemo Seed Generator API."""
|
| 2 |
+
|
| 3 |
+
from enum import Enum
|
| 4 |
+
from typing import List, Optional, Any
|
| 5 |
+
|
| 6 |
+
from pydantic import BaseModel, Field
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class HFInferenceModel(str, Enum):
|
| 10 |
+
"""Available HuggingFace Inference models."""
|
| 11 |
+
|
| 12 |
+
QWEN_2_5_7B = "Qwen/Qwen2.5-7B-Instruct"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class HFInferenceProvider(str, Enum):
|
| 16 |
+
"""Available HuggingFace Inference providers."""
|
| 17 |
+
|
| 18 |
+
TOGETHER = "together"
|
| 19 |
+
INFERENCE_SERVER = "inference-server"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class SeedGenerateRequest(BaseModel):
|
| 23 |
+
"""Request model for generating seed Q&A pairs."""
|
| 24 |
+
|
| 25 |
+
num_records: int = Field(
|
| 26 |
+
default=1,
|
| 27 |
+
ge=1,
|
| 28 |
+
le=50,
|
| 29 |
+
description="Number of Q&A pairs to generate (max 50)"
|
| 30 |
+
)
|
| 31 |
+
topic: str = Field(
|
| 32 |
+
...,
|
| 33 |
+
min_length=1,
|
| 34 |
+
max_length=200,
|
| 35 |
+
description="Topic for the Q&A pairs (e.g., 'machine learning')"
|
| 36 |
+
)
|
| 37 |
+
difficulty: str = Field(
|
| 38 |
+
...,
|
| 39 |
+
pattern=r"^(beginner|intermediate|advanced)$",
|
| 40 |
+
description="Difficulty level: beginner, intermediate, or advanced"
|
| 41 |
+
)
|
| 42 |
+
model: HFInferenceModel = Field(
|
| 43 |
+
default=HFInferenceModel.QWEN_2_5_7B,
|
| 44 |
+
description="HuggingFace model to use"
|
| 45 |
+
)
|
| 46 |
+
provider: HFInferenceProvider = Field(
|
| 47 |
+
default=HFInferenceProvider.TOGETHER,
|
| 48 |
+
description="HF Inference API provider"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class SeedRecord(BaseModel):
|
| 53 |
+
"""A single Q&A seed record."""
|
| 54 |
+
|
| 55 |
+
topic: str = Field(..., description="The topic of the Q&A")
|
| 56 |
+
difficulty: str = Field(..., description="Difficulty level")
|
| 57 |
+
question: str = Field(..., description="The question")
|
| 58 |
+
answer: str = Field(..., description="The answer")
|
| 59 |
+
model: str = Field(..., description="Model used to generate")
|
| 60 |
+
provider: str = Field(..., description="Provider used")
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class SeedGenerateResponse(BaseModel):
|
| 64 |
+
"""Response model for seed generation."""
|
| 65 |
+
|
| 66 |
+
success: bool = Field(..., description="Whether generation succeeded")
|
| 67 |
+
data: Optional[List[SeedRecord]] = Field(
|
| 68 |
+
default=None,
|
| 69 |
+
description="Generated Q&A pairs if successful"
|
| 70 |
+
)
|
| 71 |
+
record_count: int = Field(default=0, description="Number of records generated")
|
| 72 |
+
error: Optional[str] = Field(default=None, description="Error message if failed")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class HealthResponse(BaseModel):
|
| 76 |
+
"""Health check response."""
|
| 77 |
+
|
| 78 |
+
status: str = Field(..., description="Health status")
|
| 79 |
+
model: str = Field(..., description="Current model")
|
| 80 |
+
provider: str = Field(..., description="Current provider")
|