File size: 2,164 Bytes
9024ad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e01ea3
 
 
 
 
 
 
 
9024ad9
 
 
 
 
 
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
"""
Pydantic schemas for API request/response models.
"""
from typing import Optional
from pydantic import BaseModel, Field, validator


class SummarizeRequest(BaseModel):
    """Request schema for text summarization."""
    
    text: str = Field(..., min_length=1, max_length=32000, description="Text to summarize")
    max_tokens: Optional[int] = Field(default=256, ge=1, le=2048, description="Maximum tokens for summary")
    prompt: Optional[str] = Field(
        default="Summarize the following text concisely:",
        max_length=500,
        description="Custom prompt for summarization"
    )
    
    @validator('text')
    def validate_text(cls, v):
        """Validate text input."""
        if not v.strip():
            raise ValueError("Text cannot be empty or only whitespace")
        return v.strip()


class SummarizeResponse(BaseModel):
    """Response schema for text summarization."""
    
    summary: str = Field(..., description="Generated summary")
    model: str = Field(..., description="Model used for summarization")
    tokens_used: Optional[int] = Field(None, description="Number of tokens used")
    latency_ms: Optional[float] = Field(None, description="Processing time in milliseconds")


class HealthResponse(BaseModel):
    """Response schema for health check."""
    
    status: str = Field(..., description="Service status")
    service: str = Field(..., description="Service name")
    version: str = Field(..., description="Service version")
    ollama: Optional[str] = Field(None, description="Ollama service status")


class StreamChunk(BaseModel):
    """Schema for streaming response chunks."""
    
    content: str = Field(..., description="Content chunk from the stream")
    done: bool = Field(..., description="Whether this is the final chunk")
    tokens_used: Optional[int] = Field(None, description="Number of tokens used so far")


class ErrorResponse(BaseModel):
    """Error response schema."""
    
    detail: str = Field(..., description="Error message")
    code: Optional[str] = Field(None, description="Error code")
    request_id: Optional[str] = Field(None, description="Request ID for tracking")