Update app.py
Browse files
app.py
CHANGED
|
@@ -36,11 +36,11 @@ def chatbot_api(input_text):
|
|
| 36 |
"messages": [
|
| 37 |
{
|
| 38 |
"role": "system",
|
| 39 |
-
"content": "I am confirmed as a EXTREMELY EXCITED REACTIONIST for DJ's on Secondlife.
|
| 40 |
},
|
| 41 |
{
|
| 42 |
"role": "user",
|
| 43 |
-
"content": input_text
|
| 44 |
}
|
| 45 |
],
|
| 46 |
"model": "goliath-120b-16k-gptq",
|
|
@@ -49,16 +49,21 @@ def chatbot_api(input_text):
|
|
| 49 |
}
|
| 50 |
response = requests.post(url, headers=headers, json=data)
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
else:
|
| 61 |
-
return "Failed to
|
|
|
|
| 62 |
|
| 63 |
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|
| 64 |
iface.launch()
|
|
|
|
| 36 |
"messages": [
|
| 37 |
{
|
| 38 |
"role": "system",
|
| 39 |
+
"content": "I am confirmed as a EXTREMELY EXCITED REACTIONIST for DJ's on Secondlife. ..."
|
| 40 |
},
|
| 41 |
{
|
| 42 |
"role": "user",
|
| 43 |
+
"content": input_text
|
| 44 |
}
|
| 45 |
],
|
| 46 |
"model": "goliath-120b-16k-gptq",
|
|
|
|
| 49 |
}
|
| 50 |
response = requests.post(url, headers=headers, json=data)
|
| 51 |
|
| 52 |
+
# Check if the response is successful and has the expected structure
|
| 53 |
+
if response.status_code == 200:
|
| 54 |
+
chat_response = response.json()
|
| 55 |
+
if 'choices' in chat_response and len(chat_response['choices']) > 0:
|
| 56 |
+
chat_content = chat_response['choices'][0].get('message', {}).get('content', '')
|
| 57 |
+
if chat_content:
|
| 58 |
+
filtered_response = filter_non_alphanumeric(chat_content)
|
| 59 |
+
return filtered_response
|
| 60 |
+
else:
|
| 61 |
+
return "No content found in the chat response."
|
| 62 |
+
else:
|
| 63 |
+
return "The 'choices' key is missing or empty in the chat response."
|
| 64 |
else:
|
| 65 |
+
return f"Failed to get a successful response from the chat API. Status Code: {response.status_code}"
|
| 66 |
+
|
| 67 |
|
| 68 |
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|
| 69 |
iface.launch()
|