Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -28,10 +28,20 @@ class Chatbot:
|
|
28 |
|
29 |
def create_bot(input):
|
30 |
bot = Chatbot(os.getenv("OPENAI_API_KEY"), index=index)
|
31 |
-
|
|
|
32 |
if input:
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
return output
|
37 |
|
|
|
28 |
|
29 |
def create_bot(input):
|
30 |
bot = Chatbot(os.getenv("OPENAI_API_KEY"), index=index)
|
31 |
+
|
32 |
+
# use moderations endpoint to check input
|
33 |
if input:
|
34 |
+
client = OpenAI()
|
35 |
+
response_mod = client.moderations.create(input=input)
|
36 |
+
response_dict = response_mod.model_dump()
|
37 |
+
flagged = response_dict['results'][0]['flagged']
|
38 |
+
print("Flagged:", flagged)
|
39 |
+
|
40 |
+
if not flagged:
|
41 |
+
response_bot = bot.generate_response(input)
|
42 |
+
output = response_bot['content']
|
43 |
+
else:
|
44 |
+
output = "Invalid request."
|
45 |
|
46 |
return output
|
47 |
|