Emergent generative agents
Revision | cfbf97cd1d5d10fa0fd77ef16b2b582c5463d7c8 (tree) |
---|---|
Time | 2023-05-20 04:04:24 |
Author | Corbin <cds@corb...> |
Commiter | Corbin |
Well, it works. But it sucks.
Fuck it. Nobody gives a shit anyway.
@@ -132,13 +132,15 @@ class Clock(Agent): | ||
132 | 132 | class LeftBrainInterpreter(Agent): |
133 | 133 | tag = "lbi" |
134 | 134 | events = 0 |
135 | - def __init__(self, mind): self.mind = mind | |
135 | + def __init__(self, mind, idle): | |
136 | + self.mind = mind | |
137 | + self.idle = idle | |
136 | 138 | def overhear(self, tag, subtag, s): |
137 | - # XXX should skip thoughts, maybe? | |
138 | - self.events += 1 | |
139 | + if tag != "thoughts": self.events += 1 | |
139 | 140 | if self.events >= 20: |
140 | 141 | self.events = 0 |
141 | - return self.mind.infer(self.tag, self.subtag, "") | |
142 | + d = self.mind.infer(self.tag, self.subtag, "") | |
143 | + d.addCallback(lambda s: s.strip() or self.idle()) | |
142 | 144 | |
143 | 145 | choices = { |
144 | 146 | "irc": "Chat on IRC, channel {subtag}", |
@@ -146,6 +148,7 @@ choices = { | ||
146 | 148 | } |
147 | 149 | def choicify(options): |
148 | 150 | return " ".join(f"({c}) {o}" for c, o in zip(ascii_uppercase, options)) |
151 | +def indexify(c): return ord(c[0].upper()) - ord('A') | |
149 | 152 | |
150 | 153 | class ChoiceMaker(Agent): |
151 | 154 | tag = "choice" |
@@ -165,11 +168,9 @@ class ChoiceMaker(Agent): | ||
165 | 168 | |
166 | 169 | prompt = choicify([choices[tag].format(subtag=subtag) |
167 | 170 | for tag, subtag in possibilities]) |
168 | - self.broadcast(prompt) | |
169 | - d = self.mind.forceChoice(self.tag, self.subtag, "My choice: ", | |
171 | + d = self.mind.forceChoice(self.tag, self.subtag, prompt + " My choice: ", | |
170 | 172 | ascii_uppercase[:len(possibilities)]) |
171 | - d.addCallback(lambda s: self.dispatch(*possibilities[chr(ord(s[0]) - | |
172 | - ord('A'))])) | |
173 | + d.addCallback(lambda s: self.dispatch(*possibilities[indexify(s)])) | |
173 | 174 | return d |
174 | 175 | |
175 | 176 | class ChainOfThoughts(Agent): |
@@ -269,7 +270,7 @@ class IRCFactory(ClientFactory): | ||
269 | 270 | def go(): |
270 | 271 | print("~ Starting tasks…") |
271 | 272 | clock = Clock() |
272 | - LoopingCall(clock.go).start(60 * 10, now=False) | |
273 | + LoopingCall(clock.go).start(60 * 30, now=True) | |
273 | 274 | |
274 | 275 | for logpath in sys.argv[2:]: |
275 | 276 | character = load_character(logpath) |
@@ -282,14 +283,14 @@ def go(): | ||
282 | 283 | with Timer("initial warmup"): |
283 | 284 | mind.logits, mind.state = gen.feedForward(gen.tokenize(firstStatement), None, None) |
284 | 285 | |
285 | - lbi = LeftBrainInterpreter(mind) | |
286 | - clock.listeners += lbi, mind | |
287 | - | |
288 | 286 | cm = ChoiceMaker(mind) |
289 | 287 | |
288 | + lbi = LeftBrainInterpreter(mind, cm.idle) | |
289 | + clock.listeners += lbi, mind | |
290 | + | |
290 | 291 | thoughts = ChainOfThoughts(mind, thoughtIndex, firstStatement, cm.idle) |
291 | 292 | thoughts.listeners = lbi, mind |
292 | - LoopingCall(thoughts.go).start(60, now=False) | |
293 | + LoopingCall(thoughts.go).start(60 * 3, now=True) | |
293 | 294 | |
294 | 295 | print("~ Thought index:", thoughtIndex.size(), "thoughts") |
295 | 296 | factory = IRCFactory(mind, cm, (thoughts, lbi, cm, mind), |