Julia Ostheimer commited on
Commit
038c68a
·
1 Parent(s): 7c247f1

Add function to clear source and chat history and invoke it via event listener when triggering chat bin icon

Browse files
Files changed (1) hide show
  1. app.py +27 -11
app.py CHANGED
@@ -89,7 +89,6 @@ graph_builder.add_edge("generate", END)
89
  graph = graph_builder.compile(checkpointer=memory)
90
  # -----
91
 
92
- def bot(message, history, source_history, request: gr.Request) -> list[Any]:
93
  def bot(message, history, source_history, chat_hash) -> list[Any]:
94
  """Generate bot response and history from message.
95
 
@@ -124,6 +123,16 @@ def bot(message, history, source_history, chat_hash) -> list[Any]:
124
  source_history = build_source_history_object(response, source_history, user_input_prompt)
125
 
126
  return [response["messages"][-1].content], source_history, chat_hash
 
 
 
 
 
 
 
 
 
 
127
  def create_chat_hash():
128
  chat_hash = str(uuid.uuid4())
129
  logger.info("This is the chat_hash when it is called", chat_hash=chat_hash)
@@ -136,17 +145,24 @@ with gr.Blocks() as demo:
136
 
137
  gr.Markdown("### Dies ist der aktuelle Prototyp der DEval AI4Kontextanalysen, mit dem Fokus auf dem Testen der Zitationsfunktion und der grundlegenden Konfiguration.")
138
  with gr.Tab("Chat"):
 
 
 
 
 
 
139
  gr.ChatInterface(
140
- bot,
141
- type="messages",
142
- flagging_mode="manual",
143
- editable=True,
144
- flagging_options=["Like", "Dislike", "Spam", "Inappropriate", "Other"],
145
- multimodal=True,
146
- textbox=gr.MultimodalTextbox(file_count="multiple"),
147
- title="DEval Prototype 1",
148
- additional_inputs=[source_history],
149
- additional_outputs=[source_history],
 
150
  )
151
  with gr.Tab("Quellen"):
152
  prettified_source_history_md = gr.Markdown()
 
89
  graph = graph_builder.compile(checkpointer=memory)
90
  # -----
91
 
 
92
  def bot(message, history, source_history, chat_hash) -> list[Any]:
93
  """Generate bot response and history from message.
94
 
 
123
  source_history = build_source_history_object(response, source_history, user_input_prompt)
124
 
125
  return [response["messages"][-1].content], source_history, chat_hash
126
+
127
+ def clear_chat_and_source_history(source_history, chat_hash):
128
+ # Clear the source history
129
+ source_history = []
130
+
131
+ # Return a new chat hash
132
+ chat_hash = create_chat_hash()
133
+
134
+ return source_history, chat_hash
135
+
136
  def create_chat_hash():
137
  chat_hash = str(uuid.uuid4())
138
  logger.info("This is the chat_hash when it is called", chat_hash=chat_hash)
 
145
 
146
  gr.Markdown("### Dies ist der aktuelle Prototyp der DEval AI4Kontextanalysen, mit dem Fokus auf dem Testen der Zitationsfunktion und der grundlegenden Konfiguration.")
147
  with gr.Tab("Chat"):
148
+ chatbot = gr.Chatbot(type="messages")
149
+ chatbot.clear(
150
+ clear_chat_and_source_history,
151
+ inputs=[source_history, chat_hash],
152
+ outputs=[source_history, chat_hash],
153
+ )
154
  gr.ChatInterface(
155
+ bot,
156
+ chatbot=chatbot,
157
+ type="messages",
158
+ flagging_mode="manual",
159
+ editable=True,
160
+ flagging_options=["Like", "Dislike", "Spam", "Inappropriate", "Other"],
161
+ multimodal=True,
162
+ textbox=gr.MultimodalTextbox(file_count="multiple"),
163
+ title="DEval Prototype 1",
164
+ additional_inputs=[source_history, chat_hash],
165
+ additional_outputs=[source_history, chat_hash],
166
  )
167
  with gr.Tab("Quellen"):
168
  prettified_source_history_md = gr.Markdown()