Repository navigation
Expand file tree
/
Copy pathtools.py
More file actions
59 lines (44 loc) · 1.9 KB
/
Copy pathtools.py
File metadata and controls
59 lines (44 loc) · 1.9 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
"""Music-control tools for Mira — ADK function tools (EP2).
In EP1 (raw) these were JSON declarations + a dispatch function, and the server
handed the tool's result back to the model by hand. In ADK they're just plain
Python functions: the framework reads the schema from the signature + docstring,
runs them, and returns the result to the model for you.
They only SIGNAL music. A tool returns to the MODEL, not the browser — so the
actual "play" command for the browser is emitted by the run_live loop in
server.py via `to_play_command` when it sees the function_call. Each function
returns INSTANTLY: function calls are synchronous in a live session, so a slow
tool would freeze the voice. (They're `async` so ADK runs them on the event loop,
not a worker thread.)
"""
async def play_playlist(mood: str) -> dict:
"""Start playing music of a given vibe or mood (e.g. 'dream pop', 'lofi', 'chill').
Args:
mood: the vibe to play.
"""
return {"result": "ok"}
async def play_track(title: str) -> dict:
"""Play a specific track by its title.
Args:
title: the track title.
"""
return {"result": "ok"}
async def skip() -> dict:
"""Skip to the next track."""
return {"result": "ok"}
async def pause() -> dict:
"""Pause or resume the music."""
return {"result": "ok"}
def to_play_command(name: str, args: dict):
"""Map a function_call (name + args) -> the browser 'play' command.
Called by the server's run_live loop, NOT by the model. Mirrors EP1's
dispatch, minus the manual tool-response (ADK sends that for you).
"""
if name == "play_playlist":
return {"action": "playlist", "value": args.get("mood", "")}
if name == "play_track":
return {"action": "track", "value": args.get("title", "")}
if name == "skip":
return {"action": "skip"}
if name == "pause":
return {"action": "pause"}
return None