INNER CODE UNIT · Python
stream
hyperonym/basaran · basaran/__main__.py:184
def stream():
buffers = {}
times = {}
for choice in stream_model(**options):
index = choice["index"]
now = time.time_ns()
if index not in buffers:
buffers[index] = []
if index not in times:
times[index] = now
buffers[index].append(choice)
# Yield data when exceeded the maximum buffering interval.
elapsed = (now - times[index]) // 1_000_000
if elapsed > COMPLETION_MAX_INTERVAL:
data = template.copy()
data["choices"] = [reduce_choice(buffers[index])]
yield serialize(data)