Update app.py
Browse files
app.py
CHANGED
|
@@ -22,10 +22,13 @@ def clear_chat():
|
|
| 22 |
chat_history_state.value = []
|
| 23 |
chatbot.textbox.value = ""
|
| 24 |
|
| 25 |
-
def call_nvidia_api(
|
| 26 |
"""Calls the NVIDIA API to generate a response."""
|
|
|
|
|
|
|
|
|
|
| 27 |
payload = {
|
| 28 |
-
"messages":
|
| 29 |
"temperature": temperature,
|
| 30 |
"top_p": top_p,
|
| 31 |
"max_tokens": max_tokens,
|
|
@@ -47,24 +50,20 @@ def call_nvidia_api(api_history, max_tokens, temperature, top_p):
|
|
| 47 |
else:
|
| 48 |
return "Desculpe, ocorreu um erro ao gerar a resposta."
|
| 49 |
|
| 50 |
-
def chatbot_submit(message, chat_history,
|
| 51 |
-
"""Submits the user message and updates
|
| 52 |
-
|
| 53 |
-
chat_history.append([message, ""])
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
assistant_message = call_nvidia_api(
|
| 60 |
|
| 61 |
-
#
|
| 62 |
chat_history[-1][1] = assistant_message
|
| 63 |
|
| 64 |
-
|
| 65 |
-
api_history.append({"role": "assistant", "content": assistant_message})
|
| 66 |
-
|
| 67 |
-
return assistant_message, chat_history, api_history
|
| 68 |
|
| 69 |
chat_history_state = gr.State([])
|
| 70 |
system_msg = gr.Textbox(BASE_SYSTEM_MESSAGE, label="System Message", placeholder="System prompt.", lines=5)
|
|
|
|
| 22 |
chat_history_state.value = []
|
| 23 |
chatbot.textbox.value = ""
|
| 24 |
|
| 25 |
+
def call_nvidia_api(history, system_message, max_tokens, temperature, top_p):
|
| 26 |
"""Calls the NVIDIA API to generate a response."""
|
| 27 |
+
messages = [{"role": "system", "content": system_message}]
|
| 28 |
+
messages.extend([{"role": "user", "content": h[0]} for h in history])
|
| 29 |
+
|
| 30 |
payload = {
|
| 31 |
+
"messages": messages,
|
| 32 |
"temperature": temperature,
|
| 33 |
"top_p": top_p,
|
| 34 |
"max_tokens": max_tokens,
|
|
|
|
| 50 |
else:
|
| 51 |
return "Desculpe, ocorreu um erro ao gerar a resposta."
|
| 52 |
|
| 53 |
+
def chatbot_submit(message, chat_history, system_message, max_tokens_val, temperature_val, top_p_val):
|
| 54 |
+
"""Submits the user message to the chatbot and updates the chat history."""
|
| 55 |
+
print("Updating chatbot...")
|
|
|
|
| 56 |
|
| 57 |
+
# Adiciona a mensagem do usu谩rio ao hist贸rico para exibi莽茫o
|
| 58 |
+
chat_history.append([message, ""])
|
| 59 |
|
| 60 |
+
# Chama a API da NVIDIA para gerar uma resposta
|
| 61 |
+
assistant_message = call_nvidia_api(chat_history, system_message, max_tokens_val, temperature_val, top_p_val)
|
| 62 |
|
| 63 |
+
# Atualiza o hist贸rico com a resposta do assistente
|
| 64 |
chat_history[-1][1] = assistant_message
|
| 65 |
|
| 66 |
+
return assistant_message, chat_history
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
chat_history_state = gr.State([])
|
| 69 |
system_msg = gr.Textbox(BASE_SYSTEM_MESSAGE, label="System Message", placeholder="System prompt.", lines=5)
|