Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added threading to eliminate slack timeout response #10

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions slackgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from flask import Flask, request, Response
import openai
from knowledge_base import doc_chat, load_embeddings
import threading
import requests

# Load environment variables from .env file
load_dotenv(find_dotenv())
Expand All @@ -31,22 +33,28 @@
# Initialize SlackEventAdapter
slack_event_adapter = SlackEventAdapter(os.getenv("SIGNING_SECRET"), '/slack/events', app)

def some_processing(question, channel_id):
"""function for doing the actual work in a thread"""
response = doc_chat(vectordb, model_name="gpt-3.5-turbo", question=str(question))
client.chat_postMessage(channel=channel_id, text=response)
#return Response(), 200


@app.route('/ai-helper', methods=['POST'])
def ai_helper():
"""
Respond to AI-related queries in Slack.
"""
data = request.form
user_id = data.get('user_id')
#user_id = data.get('user_id')
channel_id = data.get('channel_id')
question = data.get('text')

# Get a response from the AI knowledge base
response = doc_chat(vectordb, model_name="gpt-3.5-turbo", question=str(question))

# Post the response in the Slack channel
client.chat_postMessage(channel=channel_id, text=response)
return Response(), 200

# starting a new thread for doing the actual processing
x = threading.Thread(
target=some_processing,
args=(question,channel_id,)
)
x.start()
return "Processing information.... please wait"
if __name__ == '__main__':
app.run(host="127.0.0.1", port=80, debug=True)