artificialguybr commited on
Commit
14126e6
1 Parent(s): 9faed3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -16,8 +16,17 @@ headers = {
16
  BASE_SYSTEM_MESSAGE = "I carefully provide accurate, factual, thoughtful, nuanced answers and am brilliant at reasoning."
17
 
18
  def call_nvidia_api(message, history_api, system_message, max_tokens, temperature, top_p):
19
- messages = [{"role": "system", "content": system_message}] if system_message else []
20
- messages.extend([{"role": "user", "content": msg[0]}, {"role": "assistant", "content": msg[1]} for msg in history_api])
 
 
 
 
 
 
 
 
 
21
 
22
  payload = {
23
  "messages": messages,
@@ -42,6 +51,7 @@ def call_nvidia_api(message, history_api, system_message, max_tokens, temperatur
42
  else:
43
  return "Desculpe, ocorreu um erro ao gerar a resposta."
44
 
 
45
  def chatbot_function(message, history_api, system_message, max_tokens, temperature, top_p):
46
  assistant_message = call_nvidia_api(message, history_api, system_message, max_tokens, temperature, top_p)
47
  history_api.append([message, assistant_message])
 
16
  BASE_SYSTEM_MESSAGE = "I carefully provide accurate, factual, thoughtful, nuanced answers and am brilliant at reasoning."
17
 
18
  def call_nvidia_api(message, history_api, system_message, max_tokens, temperature, top_p):
19
+ messages = []
20
+ if system_message: # Adiciona a mensagem do sistema, se houver
21
+ messages.append({"role": "system", "content": system_message})
22
+ # Adiciona as mensagens do histórico
23
+ for msg in history_api:
24
+ messages.append({"role": "user", "content": msg[0]})
25
+ if msg[1]: # Garante que não adicionamos respostas vazias
26
+ messages.append({"role": "assistant", "content": msg[1]})
27
+
28
+ # Adiciona a mensagem atual do usuário
29
+ messages.append({"role": "user", "content": message})
30
 
31
  payload = {
32
  "messages": messages,
 
51
  else:
52
  return "Desculpe, ocorreu um erro ao gerar a resposta."
53
 
54
+
55
  def chatbot_function(message, history_api, system_message, max_tokens, temperature, top_p):
56
  assistant_message = call_nvidia_api(message, history_api, system_message, max_tokens, temperature, top_p)
57
  history_api.append([message, assistant_message])