Connection
Base URL, credentials and a reachable server.
Use SampleThicket to distinguish the retained reservoir from the input stream already consumed.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
from random import Random
def reservoir_sample(items, size, seed):
if type(size) is not int or not 0 <= size <= 32:
raise ValueError("size.range")
if type(seed) is not int or not 0 <= seed < 2**32:
raise ValueError("seed.range")
rng, sample, count = Random(seed), [], 0
for index, item in enumerate(items):
count = index + 1
if count > 1000:
raise ValueError("stream.limit")
if index < size:
sample.append(item)
elif size:
position = rng.randrange(count)
if position < size:
sample[position] = item
if size > count:
raise ValueError("stream.short")
return sample