-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsume.py
More file actions
68 lines (49 loc) · 2.02 KB
/
consume.py
File metadata and controls
68 lines (49 loc) · 2.02 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
"""Smoke test for the Python source-load plugin path (Phase 1C).
Same shape as `examples/python-plugin-consumer/consume.py` — the
manifest's `plugins` field handles loading. The only difference is the
plugin entry: `"."` (this directory) instead of a path to a `.so`.
The resolver sees `plugin.toml` here, parses `language = "python"`,
provisions a uv venv (no deps in this example), spawns the runner,
and registers `EchoPythonNode` into the executor's registry.
Prereqs:
pip install ... # standard remotemedia Python deps
Run:
cd examples/python-source-plugin
PYTHONPATH=<repo>/clients/python REMOTEMEDIA_PYTHON_SRC=<repo>/clients/python python consume.py
"""
from __future__ import annotations
import asyncio
import logging
import sys
from pathlib import Path
import remotemedia.runtime as rt
log = logging.getLogger("source_plugin_consumer")
async def main_async(manifest_path: Path):
log.info("loading manifest: %s", manifest_path)
manifest_json = manifest_path.read_text()
log.info("creating streaming session (provisions venv on first run)…")
session = await rt.create_streaming_session(manifest_json)
log.info("session_id = %s", session.session_id)
for utterance in ["hello from python source", "second message", "third and final"]:
log.info("sending: %r", utterance)
await session.send_input({"type": "text", "data": utterance})
out = await session.recv_data()
log.info("got back: %r", out)
await session.signal_input_complete()
await session.close()
log.info("clean shutdown")
def main():
here = Path(__file__).parent.resolve()
manifest_path = here / "manifest.json"
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)-5s %(name)s | %(message)s",
)
if not manifest_path.exists():
sys.exit(f"manifest not found: {manifest_path}")
try:
asyncio.run(main_async(manifest_path))
except KeyboardInterrupt:
print("\nbye.", file=sys.stderr)
if __name__ == "__main__":
main()