Skip to content

Commit d10674a

Browse files
authored
Merge pull request #6 from ArjunBakhale/main
Slack App Suggested Featues
2 parents 72566d9 + 5ff48c5 commit d10674a

File tree

3 files changed

+34
-66
lines changed

3 files changed

+34
-66
lines changed

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
SLACK_TOKEN:
3131

3232
slack-bot:
33-
image: ghcr.io/janeliascicomp/gpt-semantic-search-slack-bot:0.1.4
33+
image: ghcr.io/janeliascicomp/gpt-semantic-search-slack-bot:0.1.5
3434
restart: unless-stopped
3535
environment:
3636
WEAVIATE_URL: 'http://weaviate:8080'

generate_full_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_slack_client(self):
6767

6868
def get_query_engine(self):
6969
# Assuming settings like model, class_prefix, etc., are set elsewhere or passed as parameters
70-
llm = OpenAI(model="gpt-3.5-turbo", temperature=0)
70+
llm = OpenAI(model="gpt-4o", temperature=0)
7171
embed_model = OpenAIEmbedding(model="text-embedding-3-large")
7272
prompt_helper = PromptHelper(4096, 256, 0.1)
7373

@@ -82,7 +82,7 @@ def get_query_engine(self):
8282

8383
retriever = VectorIndexRetriever(
8484
index,
85-
similarity_top_k=5,
85+
similarity_top_k=3,
8686
vector_store_query_mode=VectorStoreQueryMode.HYBRID,
8787
alpha=0.5,
8888
)

slack_app.py

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
from threading import Thread, Event
77
from concurrent.futures import ThreadPoolExecutor, TimeoutError
88

9-
# Import your SemanticSearchService
109
from generate_full_response import SemanticSearchService
1110
import logging
11+
import re
12+
1213
logging.basicConfig(level=logging.INFO)
1314
logging.basicConfig(level=logging.DEBUG)
1415
logger = logging.getLogger(__name__)
1516
app = App(token=os.environ["SLACK_BOT_TOKEN"])
1617

17-
# # Initialize the SemanticSearchService
1818
weaviate_url = os.environ["WEAVIATE_URL"]
19-
service = SemanticSearchService(weaviate_url)
2019

21-
# # Conversation history (we'll keep this for future use)
22-
# conversation_history = {}
20+
service = SemanticSearchService(weaviate_url)
2321

2422
def update_message(client, channel, timestamp, text, blocks=None):
2523
client.chat_update(
@@ -29,24 +27,19 @@ def update_message(client, channel, timestamp, text, blocks=None):
2927
blocks=blocks
3028
)
3129

32-
def generate_response_with_animation(event, say, client):
33-
user_id = event['user']
34-
channel = event['channel']
35-
text = event['text'].split('>')[1].strip()
36-
37-
# Initialize or update conversation history
38-
# if user_id not in conversation_history:
39-
# conversation_history[user_id] = []
40-
# conversation_history[user_id].append(f"Human: {text}")
41-
30+
def generate_response_with_animation(text, channel, thread_ts, client):
4231
# Send an initial message with a random thinking phrase
4332
thinking_phrases = [
4433
"Thinking...",
4534
"Processing your request...",
4635
"Hmmmmm..."
4736
]
4837
initial_message = random.choice(thinking_phrases)
49-
result = say(initial_message)
38+
result = client.chat_postMessage(
39+
channel=channel,
40+
text=initial_message,
41+
thread_ts=thread_ts # This ensures the message is posted in the thread if there is one
42+
)
5043
message_ts = result['ts']
5144

5245
# Start the loading animation
@@ -82,60 +75,35 @@ def animate():
8275
stop_event.set()
8376
animation_thread.join()
8477

85-
# Update conversation history
86-
# conversation_history[user_id].append(f"Assistant: {response}")
87-
88-
# # Truncate conversation history if it gets too long
89-
# if len(conversation_history[user_id]) > 10:
90-
# conversation_history[user_id] = conversation_history[user_id][-10:]
91-
92-
# Create a formatted response with markdown
9378
formatted_response = f"*Here's what I found:*\n\n{response}"
9479

95-
# Update the message with the final response
96-
# blocks = [
97-
# {
98-
# "type": "section",
99-
# "text": {"type": "mrkdwn", "text": formatted_response}
100-
# },
101-
# {
102-
# "type": "context",
103-
# "elements": [
104-
# {
105-
# "type": "mrkdwn",
106-
# "text": "If you found this helpful, react with :thumbsup:. If not, react with :thumbsdown:."
107-
# }
108-
# ]
109-
# }
110-
# ]
11180
update_message(client, channel, message_ts, formatted_response)
11281

113-
@app.event("app_mention")
114-
def handle_mention(event, say, client):
115-
Thread(target=generate_response_with_animation, args=(event, say, client)).start()
116-
117-
# @app.event("reaction_added")
118-
# def handle_reaction(event, say):
119-
# logger.debug(f"Reaction event received: {event}")
82+
def process_message(event, client):
83+
text = event['text']
84+
channel = event['channel']
85+
thread_ts = event.get('thread_ts', event['ts'])
12086

121-
# reaction = event.get("reaction")
122-
# user = event.get("user")
123-
# item = event.get("item", {})
124-
# ts = item.get("ts")
125-
# channel = item.get("channel")
126-
127-
# logger.info(f"Reaction: {reaction}, User: {user}, Timestamp: {ts}, Channel: {channel}")
87+
# Remove the bot mention if it exists
88+
bot_id = client.auth_test()["user_id"]
89+
text = re.sub(f'<@{bot_id}>', '', text).strip()
90+
91+
Thread(target=generate_response_with_animation, args=(text, channel, thread_ts, client)).start()
12892

129-
# if reaction == "thumbsup":
130-
# say(text="Thank you for the positive feedback! I'm glad I could help.", channel=channel, thread_ts=ts)
131-
# logger.info("Positive feedback received")
132-
# elif reaction == "thumbsdown":
133-
# say(text="I'm sorry my response wasn't helpful. Could you provide more details about what you're looking for?", channel=channel, thread_ts=ts)
134-
# logger.info("Negative feedback received")
135-
# else:
136-
# logger.info(f"Reaction {reaction} received but not handled")
93+
@app.event("app_mention")
94+
def handle_mention(event, client):
95+
process_message(event, client)
13796

97+
@app.event("message")
98+
def handle_message(event, client):
99+
# Ignore messages from bots
100+
if "bot_id" in event:
101+
return
102+
# Process messages in DMs
103+
logger.info(event)
104+
if event['channel_type'] == 'im':
105+
process_message(event, client)
138106

139107
if __name__ == "__main__":
140108
handler = SocketModeHandler(app, str(os.environ["SLACK_APP_TOKEN"]))
141-
handler.start()
109+
handler.start()

0 commit comments

Comments
 (0)