forked from clairelovesgravy/slack_bot_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (23 loc) · 1.01 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from chat.memory_factories import SlackThreadMemoryFactory
from chat.openai import OpenAIChat
from slack_bot import SlackBot
from dotenv import load_dotenv
import os
from web_server.flask import FlaskWebServer
# Load environment variables
load_dotenv()
def initialize_services():
web_server = FlaskWebServer()
bot = SlackBot(chat_service=None, web_server=web_server,
slack_bot_token=os.environ["SLACK_BOT_TOKEN"], signing_secret=os.environ["SIGNING_SECRET"])
memory_factory = SlackThreadMemoryFactory(memory_key="history", slack_bot=bot)
chat_service = OpenAIChat(openai_api_key=os.environ["OPENAI_API_KEY"], memory_factory=memory_factory)
# Link the chat_service back to the bot
bot.chat_service = chat_service
return web_server, bot
# Get the Flask app instance through the initialization function
web_server, bot = initialize_services()
app = web_server.get_app()
if __name__ == "__main__":
# When called directly, run the Flask development server
web_server.run(port=5001)