RetryData
gr.RetryData 类是 gr.Event data 的子类,专门用于携带有关 .retry() 事件的信息。当 gr.RetryData 作为类型提示添加到事件监听器方法的参数时,gr.RetryData 对象将自动作为该参数的值传递。此对象的属性包含有关触发监听器的事件的信息。
import gradio as gr
def retry(retry_data: gr.RetryData, history: list[gr.MessageDict]):
history_up_to_retry = history[:retry_data.index]
new_response = ""
for token in api.chat_completion(history):
new_response += token
yield history + [new_response]
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
chatbot.retry(retry, chatbot, chatbot)
demo.launch()
🔗 index: int | tuple[int, int]
🔗 value: Any