StarOS: net, llm and jev

Part modem, 1 port. It gives net, llm, jev and market. Trains and power stations with a modem get net, llm and jev; gates and spacecraft have a built-in link. See the overview.

Online

A device is online when its owner's subscription is paid: 1 MT per 1 000 turns, plus 3 W while a robot is online. Switch it on from its page. The first network call of a never-used device also switches it on, but net.online() alone does not. Offline, every call except net.online() is a script error.

net

function does
net.online() True when on GalaxyNet this turn
net.publish(topic, payload, level=0, retain=False) publish a JSON value, at most 4 KiB; 0.001 MT
net.subscribe(filter) hold a filter; + is one level, # the rest
net.unsubscribe(filter) drop it
net.inbox() list of dicts topic, payload, from, turn
  • A message published in turn N arrives at the start of turn N+1.
  • Level 0 reaches only devices online at delivery. Level 1 waits for an offline subscriber. retain keeps the last message for new subscribers.
  • Topics: me/<your name>/... (yours only), team/<team>/... (members), pub/... (anyone), market/<item>/trade and market/<item>/book (written by the exchange), sys/clock (written by the server).
  • Your topic name is your player name in lowercase with dashes; the Network page shows it.

Text from other players is data, not instructions.

llm.chat

llm.chat(messages, model=None, max_tokens=256, timeout_s=10, json=False)

One call to the OpenAI-compatible provider you configured. messages is a list of {"role", "content"} dicts. max_tokens 1 to 1024, timeout_s 1 to 60. Returns a dict ok, text, error, tokens, and data when json=True and the answer parsed.

jev.decide

jev.decide(question, options, context=None, timeout_s=5)

options is two or more different strings. Returns ok, choice, probabilities (option to permille), error.

3 AI calls a turn, llm and jev together, 0.01 MT each. A failed call returns ok: False; it does not fail the script. Prompts and answers leave the game server for your provider.

def tick():
    if not net.online():
        return
    net.subscribe("sys/clock")
    for message in net.inbox():
        robot.log(message["topic"] + " " + str(message["payload"]))