-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_builder.py
More file actions
73 lines (63 loc) · 2.61 KB
/
Copy pathquery_builder.py
File metadata and controls
73 lines (63 loc) · 2.61 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
from __future__ import annotations
from typing import Any
EXPANSION_MAP = {
"graph": ["Axes", "NumberPlane", "FunctionGraph", "ParametricFunction"],
"label": ["Text", "MarkupText", "DecimalNumber"],
"move point on curve": ["MoveAlongPath", "always_redraw", "ValueTracker"],
"highlight relation": ["Indicate", "Circumscribe", "Flash", "FadeToColor"],
"compare two states": ["Transform", "ReplacementTransform", "FadeTransform"],
"trajectory": ["Axes", "Line", "Arc", "Dot", "TracedPath"],
"timeline": ["Line", "Dot", "Text", "VGroup", "LaggedStart"],
}
def _expand_terms(values: list[str]) -> list[str]:
expanded: list[str] = []
for value in values:
lowered = value.lower()
expanded.append(value)
for trigger, additions in EXPANSION_MAP.items():
if trigger in lowered:
expanded.extend(additions)
deduped: list[str] = []
seen: set[str] = set()
for item in expanded:
normalized = item.strip()
if not normalized or normalized in seen:
continue
seen.add(normalized)
deduped.append(normalized)
return deduped
def build_shot_queries(
shot: dict[str, Any],
scene_spec: dict[str, Any],
topic_brief: dict[str, Any],
prompt: str,
) -> tuple[str, str]:
visible_objects = shot.get("visible_objects", [])
candidate_symbols = _expand_terms(shot.get("candidate_symbols", []))
animation_patterns = _expand_terms(shot.get("animation_patterns", []))
factual_hints = topic_brief.get("key_facts", [])[:4]
process_hints = topic_brief.get("process_steps", [])[:3]
dense_query = "\n".join(
[
f"Prompt: {prompt}",
f"Goal: {shot.get('purpose', '')}",
f"Continuity: {shot.get('continuity_from_previous', '')}",
f"Visible objects: {', '.join(visible_objects)}",
f"Need Manim APIs for: {', '.join(candidate_symbols)}",
f"Animation patterns: {', '.join(animation_patterns)}",
f"Expected output: {shot.get('expected_output', '')}",
f"Relevant facts: {' | '.join(factual_hints)}",
f"Relevant process: {' | '.join(process_hints)}",
f"Visual style: {scene_spec.get('visual_style', '')}",
]
).strip()
lexical_tokens = [
*candidate_symbols,
*animation_patterns,
*visible_objects,
scene_spec.get("visual_style", ""),
scene_spec.get("narrative_style", ""),
*shot.get("grounded_claims", []),
]
lexical_query = " ".join(token for token in lexical_tokens if token).strip()
return dense_query, lexical_query