Write a function to simulate top-k or top-p (nucleus) sampling during text generation at Mistral AI.
Implement sample_token(logits, top_k=None, top_p=None, seed=0), returning one sampled token index. logits is a non-empty list of floats, exactly one of top_k or top_p is provided, and seed must make sampling reproducible. Apply softmax only after filtering, then sample proportionally to the remaining probabilities. For top-p, sort tokens by descending logit and retain tokens through the first cumulative probability reaching top_p.
def sample_token(logits, top_k=None, top_p=None, seed=0):