Encyclopedia / models.py
baconnier's picture
Create models.py
d31d865 verified
raw
history blame
2.2 kB
from typing import List, Optional, Literal
from pydantic import BaseModel, Field
from instructor import Field as InstructorField
class Location(BaseModel):
name: str
lat: float
lon: float
relevance: str
class ZoomRange(BaseModel):
range: List[int] = Field(..., description="Start and end years")
explanation: str
class StyleConfig(BaseModel):
level: str
options: List[str] = Field(..., description="Available style options")
explanation: str
class TemporalZoom(BaseModel):
level: Literal["century", "decade", "year"]
range: List[int] = Field(..., description="Start and end years")
explanation: str
class GeographicalZoom(BaseModel):
level: Literal["continent", "country", "city"]
locations: List[Location]
explanation: str = ""
class StyleZoom(BaseModel):
level: Literal["movement", "sub_movement", "specific"]
options: List[str]
explanation: str
class AxisImpact(BaseModel):
geographical: Optional[str] = None
temporal: Optional[str] = None
style: Optional[str] = None
class TemporalConfig(BaseModel):
component: Literal["st.slider"]
current_zoom: TemporalZoom
available_zooms: dict[Literal["in", "out"], ZoomRange]
impacted_by: AxisImpact
class GeographicalConfig(BaseModel):
component: Literal["st.map"]
current_zoom: GeographicalZoom
available_zooms: dict[Literal["in", "out"], dict[Literal["locations", "explanation"], str | List[Location]]]
impacted_by: AxisImpact
class StyleConfig(BaseModel):
component: Literal["st.multiselect", "st.selectbox"]
current_zoom: StyleZoom
class Analysis(BaseModel):
query_focus: str
historical_context: str
class ArtResponse(BaseModel):
"""Art history exploration response with contextual zoom configurations"""
analysis: Analysis
axis_configurations: dict[
Literal["temporal", "geographical", "style"],
TemporalConfig | GeographicalConfig | StyleConfig
]
@classmethod
def from_llm(cls, query: str, current_zoom_states: dict) -> "ArtResponse":
"""Factory method to create response from LLM output"""
# This would be implemented with instructor
pass