Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,13 @@ def api_call(prompt, thread_id, model_name, chat_history):
|
|
| 12 |
"key": api_key,
|
| 13 |
"Content-Type": "application/json"
|
| 14 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
data = {
|
| 16 |
"prompt": prompt,
|
| 17 |
-
"thread_id": thread_id,
|
| 18 |
"nameM": model_name,
|
| 19 |
"max_new_tokens": 4096,
|
| 20 |
"top_p": 0.95,
|
|
@@ -27,18 +31,24 @@ def api_call(prompt, thread_id, model_name, chat_history):
|
|
| 27 |
"persist_data": True,
|
| 28 |
"max_chat_history_tokens": 2000,
|
| 29 |
"max_chat_history_days": 10,
|
| 30 |
-
"chat_history":
|
| 31 |
}
|
|
|
|
| 32 |
response = requests.post(url, headers=headers, json=data)
|
| 33 |
|
| 34 |
-
# Log the
|
| 35 |
-
print("
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Gradio interface
|
| 44 |
with gr.Blocks() as demo:
|
|
|
|
| 12 |
"key": api_key,
|
| 13 |
"Content-Type": "application/json"
|
| 14 |
}
|
| 15 |
+
|
| 16 |
+
# Ensure chat_history is formatted as a list of strings
|
| 17 |
+
formatted_chat_history = [[str(item[0]), str(item[1])] if item[1] is not None else [str(item[0]), ""] for item in chat_history]
|
| 18 |
+
|
| 19 |
data = {
|
| 20 |
"prompt": prompt,
|
| 21 |
+
"thread_id": thread_id,
|
| 22 |
"nameM": model_name,
|
| 23 |
"max_new_tokens": 4096,
|
| 24 |
"top_p": 0.95,
|
|
|
|
| 31 |
"persist_data": True,
|
| 32 |
"max_chat_history_tokens": 2000,
|
| 33 |
"max_chat_history_days": 10,
|
| 34 |
+
"chat_history": formatted_chat_history # Ensure chat_history is properly formatted
|
| 35 |
}
|
| 36 |
+
|
| 37 |
response = requests.post(url, headers=headers, json=data)
|
| 38 |
|
| 39 |
+
# Log the status code and content for debugging
|
| 40 |
+
print(f"Status Code: {response.status_code}")
|
| 41 |
+
print(f"Response Content: {response.content}")
|
| 42 |
|
| 43 |
+
# Check if the response contains JSON data
|
| 44 |
+
if response.status_code == 200:
|
| 45 |
+
try:
|
| 46 |
+
return response.json().get("message", "Error: 'message' key not found in the response")
|
| 47 |
+
except ValueError:
|
| 48 |
+
print("Error parsing JSON response")
|
| 49 |
+
return "Error: Unable to parse the response"
|
| 50 |
+
else:
|
| 51 |
+
return f"Error: Received status code {response.status_code}"
|
| 52 |
|
| 53 |
# Gradio interface
|
| 54 |
with gr.Blocks() as demo:
|