Custom alert when annotations condition is met

Hi! You can provide custom JavaScript via the "javascript" setting returned by your custom recipe so if you want to handle it all in JavaScript, you could do something like this and check whether the target was reached every time an answer is submitted. To make sure you're only counting unique examples (and not cases wher the user undos and reannotates), you can count the _input_hash values in the answers:

const answered = Set()
const target = 1234

document.addEventListener('prodigyanswer', event => {
  const { task } = event.detail
  answered.add(task._input_hash)
  if (answered.length == target) {
      alert(`You have reached ${target} examples, please save and exit`)
  } 
})

Alternatively, if you don't want the user to keep submitting answers if the target was reached, you could also use the validate_answer callback: https://prodi.gy/docs/custom-recipes#validate_answer This would let you implement the logic in Python and the function will be called on every example that's submitted in the UI. An error raised here will be shown as an alert in the UI and the user won't be able to keep annotating:

answered = set()
target = 1234

def validate_answer(answer):
    answered.add(answer["_input_hash"])
    if len(answered) == target:
        raise ValueError(f"You have reached {target} examples, please save and exit")
1 Like