nadaaaita commited on
Commit
c6e47c7
·
1 Parent(s): 16273f5

fixed bug in second tab

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -53,11 +53,10 @@ def process_input_passage_finder(message):
53
  return html_output
54
 
55
  # Chatbot functions
 
56
  def respond_chatbot(query, history):
57
  formatted_query = [HumanMessage(content=query)]
58
- # Invoke the graph with properly formatted input
59
  result = chatbot.graph.invoke({"messages": formatted_query}, chatbot.config)
60
- # Get the passages from the graph and append to history if documents exist
61
  state = chatbot.graph.get_state(config=chatbot.config).values
62
  documents = state.get("documents")
63
  passages = ''
@@ -65,12 +64,13 @@ def respond_chatbot(query, history):
65
  for d in documents:
66
  passages += f'<b>{d.metadata["publication_name"]} - {d.metadata["chapter_name"]}</b>\n{d.page_content}\n\n'
67
  history.append((f'Passages: {query}', passages))
68
- # Extract the assistant's response and append to history
69
  response = result["messages"][-1].content
70
  system_message_dropdown = state.get("system_message_dropdown")
71
  history.append((query, f"<i>[{system_message_dropdown}]</i>\n" + response))
72
  return history
73
 
 
 
74
  # Generic Chatbot function
75
  def respond_genericchatbot(query, history):
76
  formatted_query = [HumanMessage(content=query)]
@@ -166,7 +166,6 @@ with gr.Blocks(css=css) as demo:
166
  value=list(sp.system_prompt_templates.keys())[0],
167
  )
168
 
169
- # Chatbot description Textbox
170
  chatbot_description = gr.Textbox(
171
  value=sp.chatbot_descriptions[list(sp.system_prompt_templates.keys())[0]],
172
  label="Chatbot Description",
@@ -192,12 +191,23 @@ with gr.Blocks(css=css) as demo:
192
  </div>
193
  """)
194
 
 
 
 
 
 
 
 
 
 
 
195
  system_prompt_dropdown.change(
196
- fn=lambda x: (sp.chatbot_descriptions[x], sp.system_prompt_templates[x]),
197
  inputs=[system_prompt_dropdown],
198
  outputs=[chatbot_description, system_prompt_display]
199
  )
200
-
 
201
  submit_button_cb.click(
202
  fn=respond_chatbot,
203
  inputs=[user_input_cb, chatbot_output],
 
53
  return html_output
54
 
55
  # Chatbot functions
56
+
57
  def respond_chatbot(query, history):
58
  formatted_query = [HumanMessage(content=query)]
 
59
  result = chatbot.graph.invoke({"messages": formatted_query}, chatbot.config)
 
60
  state = chatbot.graph.get_state(config=chatbot.config).values
61
  documents = state.get("documents")
62
  passages = ''
 
64
  for d in documents:
65
  passages += f'<b>{d.metadata["publication_name"]} - {d.metadata["chapter_name"]}</b>\n{d.page_content}\n\n'
66
  history.append((f'Passages: {query}', passages))
 
67
  response = result["messages"][-1].content
68
  system_message_dropdown = state.get("system_message_dropdown")
69
  history.append((query, f"<i>[{system_message_dropdown}]</i>\n" + response))
70
  return history
71
 
72
+
73
+
74
  # Generic Chatbot function
75
  def respond_genericchatbot(query, history):
76
  formatted_query = [HumanMessage(content=query)]
 
166
  value=list(sp.system_prompt_templates.keys())[0],
167
  )
168
 
 
169
  chatbot_description = gr.Textbox(
170
  value=sp.chatbot_descriptions[list(sp.system_prompt_templates.keys())[0]],
171
  label="Chatbot Description",
 
191
  </div>
192
  """)
193
 
194
+ # system_prompt_dropdown.change(
195
+ # fn=lambda x: (sp.chatbot_descriptions[x], sp.system_prompt_templates[x]),
196
+ # inputs=[system_prompt_dropdown],
197
+ # outputs=[chatbot_description, system_prompt_display]
198
+ # )
199
+
200
+ def update_chatbot_info(selected_prompt):
201
+ chatbot.reset_system_prompt(selected_prompt)
202
+ return sp.chatbot_descriptions[selected_prompt], sp.system_prompt_templates[selected_prompt]
203
+
204
  system_prompt_dropdown.change(
205
+ fn=update_chatbot_info,
206
  inputs=[system_prompt_dropdown],
207
  outputs=[chatbot_description, system_prompt_display]
208
  )
209
+
210
+
211
  submit_button_cb.click(
212
  fn=respond_chatbot,
213
  inputs=[user_input_cb, chatbot_output],