Skip to content

Commit 1c9bee6

Browse files
Add text repeater for use with LLM/VLM/VLA setups (#69)
* Add text repeater for use with LLM/VLM/VLA setups * [UPDATE] updated text_repeater * [UPDATE] updated text_repeater --------- Co-authored-by: abhineetkumar <abhineetsoccer@gmail.com>
1 parent fd76793 commit 1c9bee6

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from ark.client.comm_infrastructure.base_node import BaseNode, main
2+
from arktypes import string_t
3+
from pathlib import Path
4+
import argparse
5+
6+
class TextRepeaterNode(BaseNode):
7+
def __init__(self, node_name: str, global_config):
8+
super().__init__(node_name, global_config)
9+
# Required keys in the global config
10+
text_path = self.config.get("text_path", "")
11+
text = self.config.get("text", "")
12+
channel = self.config.get("channel", "user_input")
13+
freq = self.config.get("freq", 1)
14+
15+
# Exactly one of 'text' or 'text_path' should be provided; both default to "".
16+
if text and text_path:
17+
raise ValueError("Pass only one of 'text' or 'text_path' (not both).")
18+
19+
if text_path:
20+
p = Path(text_path)
21+
if not p.is_file():
22+
raise FileNotFoundError(f"'text_path' does not exist or is not a file: {p}")
23+
self.text = p.read_text()
24+
else:
25+
self.text = text
26+
27+
self.text_msg = string_t()
28+
self.text_msg.data = self.text
29+
30+
# Publisher on requested channel
31+
self.pub = self.create_publisher(channel, string_t)
32+
33+
# Stepper that publishes at the requested frequency
34+
self.publish_text = lambda: self.pub.publish(self.text_msg)
35+
self.create_stepper(freq, self.publish_text)
36+
37+
38+
def get_args():
39+
parser = argparse.ArgumentParser(
40+
description="Publishes a text file as a string at a given frequency, using a global config.",
41+
)
42+
parser.add_argument(
43+
"--node-name",
44+
type=str,
45+
required=True,
46+
help="Name of this node.",
47+
)
48+
parser.add_argument(
49+
"--config",
50+
type=str,
51+
required=True,
52+
help="Path to global config file (.json or .yaml/.yml) containing: text_path, channel, freq.",
53+
)
54+
args = parser.parse_args()
55+
return args.node_name, args.config
56+
57+
58+
if __name__ == "__main__":
59+
node_name, global_config = get_args()
60+
# Pass exactly (node_name, global_config) to match TextRepeaterNode.__init__
61+
main(TextRepeaterNode, node_name, global_config)

0 commit comments

Comments
 (0)