EditData
gr.EditData 类是 gr.EventData 的子类,专门用于携带有关 .edit() 事件的信息。当 gr.EditData 作为事件监听器方法参数的类型提示添加时,一个 gr.EditData 对象将自动作为该参数的值传递。此对象的属性包含有关触发监听器的事件的信息。
import gradio as gr
def edit(edit_data: gr.EditData, history: list[gr.MessageDict]):
history_up_to_edit = history[:edit_data.index]
history_up_to_edit[-1] = edit_data.value
return history_up_to_edit
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
chatbot.undo(edit, chatbot, chatbot)
demo.launch()
🔗 index: int | tuple[int, int]
🔗 previous_value: Any
🔗 value: Any