Commit
·
9a75ed0
1
Parent(s):
2123ed3
Add debug print statements to check payload sent and received
Browse files
app.py
CHANGED
@@ -26,6 +26,7 @@ def user(message, history):
|
|
26 |
history = history or []
|
27 |
history.append({"role": "user", "content": message})
|
28 |
return history
|
|
|
29 |
def call_nvidia_api(history, max_tokens, temperature, top_p):
|
30 |
payload = {
|
31 |
"messages": history,
|
@@ -35,9 +36,11 @@ def call_nvidia_api(history, max_tokens, temperature, top_p):
|
|
35 |
"stream": False
|
36 |
}
|
37 |
|
|
|
|
|
38 |
session = requests.Session()
|
39 |
response = session.post(INVOKE_URL, headers=headers, json=payload)
|
40 |
-
|
41 |
while response.status_code == 202:
|
42 |
request_id = response.headers.get("NVCF-REQID")
|
43 |
fetch_url = FETCH_URL_FORMAT + request_id
|
@@ -45,8 +48,9 @@ def call_nvidia_api(history, max_tokens, temperature, top_p):
|
|
45 |
|
46 |
response.raise_for_status()
|
47 |
response_body = response.json()
|
48 |
-
|
49 |
-
|
|
|
50 |
if response_body["choices"]:
|
51 |
assistant_message = response_body["choices"][0]["message"]["content"]
|
52 |
history.append({"role": "assistant", "content": assistant_message})
|
@@ -75,12 +79,10 @@ with gr.Blocks() as demo:
|
|
75 |
|
76 |
def update_chatbot(message, chat_history):
|
77 |
print("Updating chatbot...")
|
78 |
-
# Ensure the user's message is not added twice
|
79 |
if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
|
80 |
chat_history = user(message, chat_history)
|
81 |
chat_history, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
|
82 |
-
|
83 |
-
formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
|
84 |
return formatted_chat_history, chat_history, ""
|
85 |
|
86 |
|
|
|
26 |
history = history or []
|
27 |
history.append({"role": "user", "content": message})
|
28 |
return history
|
29 |
+
|
30 |
def call_nvidia_api(history, max_tokens, temperature, top_p):
|
31 |
payload = {
|
32 |
"messages": history,
|
|
|
36 |
"stream": False
|
37 |
}
|
38 |
|
39 |
+
print(f"Payload enviado: {payload}") # Imprime o payload enviado
|
40 |
+
|
41 |
session = requests.Session()
|
42 |
response = session.post(INVOKE_URL, headers=headers, json=payload)
|
43 |
+
|
44 |
while response.status_code == 202:
|
45 |
request_id = response.headers.get("NVCF-REQID")
|
46 |
fetch_url = FETCH_URL_FORMAT + request_id
|
|
|
48 |
|
49 |
response.raise_for_status()
|
50 |
response_body = response.json()
|
51 |
+
|
52 |
+
print(f"Payload recebido: {response_body}") # Imprime o payload recebido
|
53 |
+
|
54 |
if response_body["choices"]:
|
55 |
assistant_message = response_body["choices"][0]["message"]["content"]
|
56 |
history.append({"role": "assistant", "content": assistant_message})
|
|
|
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 |
+
formatted_chat_history = [msg["content"] for msg in chat_history] # Remove os roles do histórico do chat
|
|
|
86 |
return formatted_chat_history, chat_history, ""
|
87 |
|
88 |
|