artificialguybr commited on
Commit
d1ff68f
1 Parent(s): f2bf349

Add system prompt to chat history

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -79,15 +79,16 @@ with gr.Blocks() as demo:
79
 
80
  def update_chatbot(message, chat_history):
81
  print("Updating chatbot...")
 
 
 
82
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
83
  chat_history = user(message, chat_history)
84
- chat_history, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
85
  # Formata o hist贸rico do chat para o formato esperado pelo gr.Chatbot
86
- formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
87
  return formatted_chat_history, chat_history, ""
88
 
89
-
90
-
91
  submit.click(
92
  fn=update_chatbot,
93
  inputs=[message, chat_history_state],
 
79
 
80
  def update_chatbot(message, chat_history):
81
  print("Updating chatbot...")
82
+ # Inclui o prompt do sistema como a primeira mensagem, se necess谩rio
83
+ if not chat_history or (chat_history and chat_history[0]["content"] != BASE_SYSTEM_MESSAGE):
84
+ chat_history.insert(0, {"role": "system", "content": BASE_SYSTEM_MESSAGE})
85
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
86
  chat_history = user(message, chat_history)
87
+ chat_history, _ = chat(chat_history, BASE_SYSTEM_MESSAGE, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
88
  # Formata o hist贸rico do chat para o formato esperado pelo gr.Chatbot
89
+ formatted_chat_history = [f"{msg['role']}: {msg['content']}" for msg in chat_history]
90
  return formatted_chat_history, chat_history, ""
91
 
 
 
92
  submit.click(
93
  fn=update_chatbot,
94
  inputs=[message, chat_history_state],