Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ def text_generate(prompt):
|
|
19 |
data ={"inputs":prompt,
|
20 |
"top_p": 0.9,
|
21 |
"temp": 0.75}
|
22 |
-
|
23 |
response = requests.post(API_URL, headers=headers, json=data)
|
24 |
if response.status_code == 200:
|
25 |
data_str=response.json()
|
@@ -33,10 +33,10 @@ def text_generate(prompt):
|
|
33 |
slack_msg=slack_msg+data_str
|
34 |
else:
|
35 |
slack_msg="Failed to send JSON message to URL"
|
36 |
-
|
37 |
slack_msg="Failed to send JSON message to URL due to timeout error"
|
38 |
pass
|
39 |
-
|
40 |
@app.route("/")
|
41 |
def index():
|
42 |
return 'Hello'
|
@@ -53,25 +53,6 @@ def handle_event():
|
|
53 |
return (
|
54 |
challenge
|
55 |
)
|
56 |
-
if event=='app_mention':
|
57 |
-
API_KEY=os.environ.get('SLACK_APP_TOKEN')
|
58 |
-
SLACK_CHANNEL=os.environ.get('SLACK_APP_CHANNEL')
|
59 |
-
# Set up the Slack client
|
60 |
-
YOUR_BOT_TOKEN=API_KEY
|
61 |
-
client = WebClient(token=YOUR_BOT_TOKEN)
|
62 |
-
channel= SLACK_CHANNEL
|
63 |
-
conversation = request.json['text']
|
64 |
-
print(conversation)
|
65 |
-
response=text_generate(conversation)
|
66 |
-
# Post the response back to the Slack channel
|
67 |
-
try:
|
68 |
-
client.chat_postMessage(
|
69 |
-
channel='#chat-gpt-bot',
|
70 |
-
text=response
|
71 |
-
)
|
72 |
-
except SlackApiError as e:
|
73 |
-
response="Error"
|
74 |
-
return response
|
75 |
if event=='event_callback':
|
76 |
API_KEY=os.environ.get('SLACK_APP_TOKEN')
|
77 |
SLACK_CHANNEL=os.environ.get('SLACK_APP_CHANNEL')
|
|
|
19 |
data ={"inputs":prompt,
|
20 |
"top_p": 0.9,
|
21 |
"temp": 0.75}
|
22 |
+
try:
|
23 |
response = requests.post(API_URL, headers=headers, json=data)
|
24 |
if response.status_code == 200:
|
25 |
data_str=response.json()
|
|
|
33 |
slack_msg=slack_msg+data_str
|
34 |
else:
|
35 |
slack_msg="Failed to send JSON message to URL"
|
36 |
+
except requests.exceptions.Timeout:
|
37 |
slack_msg="Failed to send JSON message to URL due to timeout error"
|
38 |
pass
|
39 |
+
return slack_msg
|
40 |
@app.route("/")
|
41 |
def index():
|
42 |
return 'Hello'
|
|
|
53 |
return (
|
54 |
challenge
|
55 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
if event=='event_callback':
|
57 |
API_KEY=os.environ.get('SLACK_APP_TOKEN')
|
58 |
SLACK_CHANNEL=os.environ.get('SLACK_APP_CHANNEL')
|