Spaces:
Sleeping
Sleeping
Create models.py
Browse files
models.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Optional, Literal
|
2 |
+
from pydantic import BaseModel, Field
|
3 |
+
from instructor import Field as InstructorField
|
4 |
+
|
5 |
+
class Location(BaseModel):
|
6 |
+
name: str
|
7 |
+
lat: float
|
8 |
+
lon: float
|
9 |
+
relevance: str
|
10 |
+
|
11 |
+
class ZoomRange(BaseModel):
|
12 |
+
range: List[int] = Field(..., description="Start and end years")
|
13 |
+
explanation: str
|
14 |
+
|
15 |
+
class StyleConfig(BaseModel):
|
16 |
+
level: str
|
17 |
+
options: List[str] = Field(..., description="Available style options")
|
18 |
+
explanation: str
|
19 |
+
|
20 |
+
class TemporalZoom(BaseModel):
|
21 |
+
level: Literal["century", "decade", "year"]
|
22 |
+
range: List[int] = Field(..., description="Start and end years")
|
23 |
+
explanation: str
|
24 |
+
|
25 |
+
class GeographicalZoom(BaseModel):
|
26 |
+
level: Literal["continent", "country", "city"]
|
27 |
+
locations: List[Location]
|
28 |
+
explanation: str = ""
|
29 |
+
|
30 |
+
class StyleZoom(BaseModel):
|
31 |
+
level: Literal["movement", "sub_movement", "specific"]
|
32 |
+
options: List[str]
|
33 |
+
explanation: str
|
34 |
+
|
35 |
+
class AxisImpact(BaseModel):
|
36 |
+
geographical: Optional[str] = None
|
37 |
+
temporal: Optional[str] = None
|
38 |
+
style: Optional[str] = None
|
39 |
+
|
40 |
+
class TemporalConfig(BaseModel):
|
41 |
+
component: Literal["st.slider"]
|
42 |
+
current_zoom: TemporalZoom
|
43 |
+
available_zooms: dict[Literal["in", "out"], ZoomRange]
|
44 |
+
impacted_by: AxisImpact
|
45 |
+
|
46 |
+
class GeographicalConfig(BaseModel):
|
47 |
+
component: Literal["st.map"]
|
48 |
+
current_zoom: GeographicalZoom
|
49 |
+
available_zooms: dict[Literal["in", "out"], dict[Literal["locations", "explanation"], str | List[Location]]]
|
50 |
+
impacted_by: AxisImpact
|
51 |
+
|
52 |
+
class StyleConfig(BaseModel):
|
53 |
+
component: Literal["st.multiselect", "st.selectbox"]
|
54 |
+
current_zoom: StyleZoom
|
55 |
+
|
56 |
+
class Analysis(BaseModel):
|
57 |
+
query_focus: str
|
58 |
+
historical_context: str
|
59 |
+
|
60 |
+
class ArtResponse(BaseModel):
|
61 |
+
"""Art history exploration response with contextual zoom configurations"""
|
62 |
+
analysis: Analysis
|
63 |
+
axis_configurations: dict[
|
64 |
+
Literal["temporal", "geographical", "style"],
|
65 |
+
TemporalConfig | GeographicalConfig | StyleConfig
|
66 |
+
]
|
67 |
+
|
68 |
+
@classmethod
|
69 |
+
def from_llm(cls, query: str, current_zoom_states: dict) -> "ArtResponse":
|
70 |
+
"""Factory method to create response from LLM output"""
|
71 |
+
# This would be implemented with instructor
|
72 |
+
pass
|