artificialguybr commited on
Commit
8cf9380
·
verified ·
1 Parent(s): 75d0729

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -99,25 +99,27 @@ with gr.Blocks() as demo:
99
  top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.95, interactive=True)
100
  chat_history_state = gr.State([])
101
 
102
- def update_chatbot(message, chat_history, system_message=BASE_SYSTEM_MESSAGE):
 
103
  print("Updating chatbot...")
104
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
105
  chat_history = user(message, chat_history, system_message if not chat_history else None)
106
  else:
107
  chat_history = user(message, chat_history)
108
  chat_history, _ = chat(chat_history, system_message, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
109
-
110
  formatted_chat_history = []
111
  for user_msg, assistant_msg in zip([msg["content"].strip() for msg in chat_history if msg["role"] == "user"],
112
  [msg["content"].strip() for msg in chat_history if msg["role"] == "assistant"]):
113
  if user_msg or assistant_msg: # Verify if either message is not empty
114
  formatted_chat_history.append([user_msg, assistant_msg])
115
-
116
  return formatted_chat_history, chat_history, ""
117
-
 
118
  submit.click(
119
  fn=update_chatbot,
120
- inputs=[message, chat_history_state],
121
  outputs=[chatbot, chat_history_state, message]
122
  )
123
 
 
99
  top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.95, interactive=True)
100
  chat_history_state = gr.State([])
101
 
102
+ # Ajuste na definição da função update_chatbot para aceitar o valor atualizado do system_msg
103
+ def update_chatbot(message, chat_history, system_message): # Remova o valor padrão aqui
104
  print("Updating chatbot...")
105
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
106
  chat_history = user(message, chat_history, system_message if not chat_history else None)
107
  else:
108
  chat_history = user(message, chat_history)
109
  chat_history, _ = chat(chat_history, system_message, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
110
+
111
  formatted_chat_history = []
112
  for user_msg, assistant_msg in zip([msg["content"].strip() for msg in chat_history if msg["role"] == "user"],
113
  [msg["content"].strip() for msg in chat_history if msg["role"] == "assistant"]):
114
  if user_msg or assistant_msg: # Verify if either message is not empty
115
  formatted_chat_history.append([user_msg, assistant_msg])
116
+
117
  return formatted_chat_history, chat_history, ""
118
+
119
+ # Ajuste na chamada do botão submit para incluir system_msg como um input
120
  submit.click(
121
  fn=update_chatbot,
122
+ inputs=[message, chat_history_state, system_msg], # Inclua system_msg aqui
123
  outputs=[chatbot, chat_history_state, message]
124
  )
125