Spaces:
Running
Running
File size: 2,249 Bytes
1f5b714 |
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 |
"""Pydantic models for RAG chat feature."""
from typing import List, Optional, Literal
from datetime import datetime
from pydantic import BaseModel, Field
Role = Literal["user", "assistant"]
class SourceReference(BaseModel):
"""Metadata about a note used to generate a response."""
path: str = Field(..., description="Relative path in vault")
title: str = Field(..., description="Note title")
snippet: str = Field(..., description="Relevant text excerpt (max 500 chars)")
score: Optional[float] = Field(None, description="Relevance score (0.0-1.0)")
class NoteWritten(BaseModel):
"""Metadata about a note created or updated by the agent."""
path: str = Field(..., description="Path to created/updated note")
title: str = Field(..., description="Note title")
action: Literal["created", "updated"] = Field(..., description="Action performed")
class ChatMessage(BaseModel):
"""Represents a single message in the conversation."""
role: Role = Field(..., description="Message author")
content: str = Field(..., max_length=10000, description="Message text")
timestamp: Optional[datetime] = Field(default_factory=datetime.utcnow, description="Creation time")
sources: Optional[List[SourceReference]] = Field(None, description="Referenced notes (assistant only)")
notes_written: Optional[List[NoteWritten]] = Field(None, description="Notes created (Phase 2)")
class ChatRequest(BaseModel):
"""Request payload for the RAG chat endpoint."""
messages: List[ChatMessage] = Field(..., min_length=1, description="Conversation history")
class ChatResponse(BaseModel):
"""Response payload from the RAG chat endpoint."""
answer: str = Field(..., description="AI-generated response")
sources: List[SourceReference] = Field(default_factory=list, description="Notes used in response")
notes_written: List[NoteWritten] = Field(default_factory=list, description="Notes created (Phase 2)")
class StatusResponse(BaseModel):
"""RAG index status."""
status: Literal["ready", "building", "error"]
doc_count: int
last_updated: Optional[datetime] = None
class ErrorResponse(BaseModel):
"""Standard error response."""
error: str
detail: Optional[str] = None
|