Add Perplexity citations at the end of the response, it is a Filter Function, which means this function run only on input or output chunks. In this case I'm checking finish_reason, if it is not None which means it the last chunk, then I'll add citations at the end of the last chunk. Note: you have access to citations on each chunk you receive, you can even edit [1] this kind of text to md format to link to the related citation, but I just want to make it simple. cheers 🍻