INNER CODE UNIT · Python
sample_record
IlyaGusev/rulm · self_instruct/src/bot/run.py:62
def sample_record(self, username, retries=50, max_overlap=3):
for _ in range(retries):
record = random.choice(self.records)
instruction = record["instruction"]
count = self.db.count(where("instruction") == instruction)
if count >= max_overlap:
continue
if not self.db.contains((where("instruction") == instruction) & (where("username") == username)):
break
return record
def show(self, update: Update, context: CallbackContext):
chat_id = update.effective_chat.id
if update.message:
username = update.message.chat.username
self.chat2username[chat_id] = username
else:
username = self.chat2username[chat_id]