-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathhvplot.py
More file actions
74 lines (62 loc) · 2.19 KB
/
Copy pathhvplot.py
File metadata and controls
74 lines (62 loc) · 2.19 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from typing import Any
import param
from pydantic import BaseModel
from pydantic.fields import FieldInfo
from ...views import hvPlotUIView
from ..config import PROMPTS_DIR
from ..context import TContext
from ..translate import param_to_pydantic
from ..utils import get_data
from .base_view import BaseViewAgent
class hvPlotAgent(BaseViewAgent):
conditions = param.List(
default=[
"Use for exploratory data analysis, interactive plots, and dynamic filtering",
"Use for quick, iterative data visualization during analysis",
]
)
purpose = param.String(default="Generates a plot of the data given a user prompt.")
prompts = param.Dict(
default={
"main": {"template": PROMPTS_DIR / "hvPlotAgent" / "main.jinja2"},
}
)
view_type = hvPlotUIView
def _get_model(self, prompt_name: str, schema: dict[str, Any]) -> type[BaseModel]:
# Find parameters
excluded = self.view_type._internal_params + [
"controls",
"type",
"source",
"pipeline",
"transforms",
"download",
"field",
"selection_group",
]
model = param_to_pydantic(
self.view_type,
base_model=BaseModel,
excluded=excluded,
schema=schema,
extra_fields={
"chain_of_thought": (str, FieldInfo(description="Your thought process behind the plot.")),
},
)
return model[self.view_type.__name__]
async def _extract_spec(self, context: TContext, spec: dict[str, Any]):
pipeline = context["pipeline"]
spec = {key: val for key, val in spec.items() if val is not None}
spec["type"] = "hvplot_ui"
self.view_type.validate(spec)
spec.pop("type", None)
# Add defaults
spec["responsive"] = True
if spec.get("kind") == "heatmap":
spec.pop("by", None)
spec.pop("groupby", None)
data = await get_data(pipeline)
if len(data) > 20000 and spec["kind"] in ("line", "scatter", "points"):
spec["rasterize"] = True
spec["cnorm"] = "log"
return spec