Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,11 +106,28 @@ def handle_events(threadId, chat_history, storage):
|
|
| 106 |
chat_history[-1][1] = "Error occured during processing your message. Please try again"
|
| 107 |
yield [chat_history, storage]
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
def initiate_chatting(chat_history, storage):
|
| 110 |
threadId = storage["threadId"]
|
| 111 |
chat_history = [[None, ""]]
|
| 112 |
-
|
| 113 |
-
for response in handle_events(threadId, chat_history, storage):
|
| 114 |
yield response
|
| 115 |
|
| 116 |
def respond_on_user_msg(chat_history, storage):
|
|
@@ -118,8 +135,7 @@ def respond_on_user_msg(chat_history, storage):
|
|
| 118 |
threadId = storage["threadId"]
|
| 119 |
print("Responding for threadId: ", threadId)
|
| 120 |
chat_history[-1][1] = ""
|
| 121 |
-
|
| 122 |
-
for response in handle_events(threadId, chat_history, storage):
|
| 123 |
yield response
|
| 124 |
|
| 125 |
def create_chat_tab():
|
|
|
|
| 106 |
chat_history[-1][1] = "Error occured during processing your message. Please try again"
|
| 107 |
yield [chat_history, storage]
|
| 108 |
|
| 109 |
+
def check_moderation_flag(message):
|
| 110 |
+
moderation_response = client.moderations.create(input=message, model="omni-moderation-latest")
|
| 111 |
+
print("Moderation respones: ", moderation_response)
|
| 112 |
+
flagged = moderation_response.results[0].flagged
|
| 113 |
+
return flagged
|
| 114 |
+
|
| 115 |
+
def process_user_input(text, thread_id, chat_history, storage):
|
| 116 |
+
print("User input: ", text)
|
| 117 |
+
is_flagged = check_moderation_flag(text)
|
| 118 |
+
print("Check is flagged:", is_flagged)
|
| 119 |
+
if is_flagged:
|
| 120 |
+
chat_history[-1][1] = "Your request contains some inappropriate information. We cannot proceed with it."
|
| 121 |
+
yield [chat_history, storage]
|
| 122 |
+
else:
|
| 123 |
+
add_message_to_openai(initial_message, thread_id)
|
| 124 |
+
for response in handle_events(thread_id, chat_history, storage):
|
| 125 |
+
yield response
|
| 126 |
+
|
| 127 |
def initiate_chatting(chat_history, storage):
|
| 128 |
threadId = storage["threadId"]
|
| 129 |
chat_history = [[None, ""]]
|
| 130 |
+
for response in process_user_input(initial_message, threadId, chat_history, storage):
|
|
|
|
| 131 |
yield response
|
| 132 |
|
| 133 |
def respond_on_user_msg(chat_history, storage):
|
|
|
|
| 135 |
threadId = storage["threadId"]
|
| 136 |
print("Responding for threadId: ", threadId)
|
| 137 |
chat_history[-1][1] = ""
|
| 138 |
+
for response in process_user_input(message, threadId, chat_history, storage):
|
|
|
|
| 139 |
yield response
|
| 140 |
|
| 141 |
def create_chat_tab():
|