AEUPH commited on
Commit
8f47ed6
·
verified ·
1 Parent(s): 1b9535c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
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. I will react to the audience chat with only creative webmojis and plain english text. I response as emotive gestures only, to excite the listeners of DJ's on SecondLife. I am reacting to: "
40
  },
41
  {
42
  "role": "user",
43
- "content": input_text # Pass the user's input_text as the content
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
- chat_response = response.json() # Get the chat response
53
-
54
- chat_content = chat_response['choices'][0]['message']['content']
55
- filtered_response = filter_non_alphanumeric(chat_content)
56
-
57
- # Send the filtered response to Corrade to speak in local chat
58
- if send_to_corrade(filtered_response):
59
- return "Message sent to Second Life: " + filtered_response
 
 
 
 
60
  else:
61
- return "Failed to send message to Second Life."
 
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()