|
1 |
| -# import os |
2 |
| -# import time |
3 |
| -# from slack_bolt import App |
4 |
| -# from slack_bolt.adapter.socket_mode import SocketModeHandler |
5 |
| -# from threading import Thread, Event |
6 |
| - |
7 |
| -# # Import your SemanticSearchService |
8 |
| -# from generate_full_response import SemanticSearchService |
9 |
| - |
10 |
| -# app = App(token=os.environ["SLACK_BOT_TOKEN"]) |
11 |
| - |
12 |
| -# # Initialize the SemanticSearchService |
13 |
| -# weaviate_url = "http://localhost:8777" |
14 |
| -# service = SemanticSearchService(weaviate_url) |
15 |
| - |
16 |
| -# def update_message(client, channel, timestamp, text): |
17 |
| -# client.chat_update( |
18 |
| -# channel=channel, |
19 |
| -# ts=timestamp, |
20 |
| -# text=text |
21 |
| -# ) |
22 |
| - |
23 |
| -# def generate_response_with_animation(event, say, client): |
24 |
| -# # Extract the text after the bot mention |
25 |
| -# text = event['text'].split('>')[1].strip() |
26 |
| - |
27 |
| -# # Send an initial message |
28 |
| -# result = say("Thinking...") |
29 |
| -# message_ts = result['ts'] |
30 |
| - |
31 |
| -# # Start the loading animation |
32 |
| -# loading_chars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] |
33 |
| -# i = 0 |
34 |
| -# stop_event = Event() |
35 |
| - |
36 |
| -# def animate(): |
37 |
| -# nonlocal i |
38 |
| -# while not stop_event.is_set(): |
39 |
| -# update_message(client, event['channel'], message_ts, f"{loading_chars[i]} Thinking...") |
40 |
| -# i = (i + 1) % len(loading_chars) |
41 |
| -# time.sleep(0.1) |
42 |
| - |
43 |
| -# # Start the animation in a separate thread |
44 |
| -# animation_thread = Thread(target=animate) |
45 |
| -# animation_thread.start() |
46 |
| - |
47 |
| -# try: |
48 |
| -# # Generate a response using the SemanticSearchService |
49 |
| -# response = service.generate_response(text) |
50 |
| -# finally: |
51 |
| -# # Stop the animation thread |
52 |
| -# stop_event.set() |
53 |
| -# animation_thread.join() |
54 |
| - |
55 |
| -# # Update the message with the final response |
56 |
| -# update_message(client, event['channel'], message_ts, response) |
57 |
| - |
58 |
| -# @app.event("app_mention") |
59 |
| -# def handle_mention(event, say, client): |
60 |
| -# Thread(target=generate_response_with_animation, args=(event, say, client)).start() |
61 |
| - |
62 |
| -# if __name__ == "__main__": |
63 |
| -# handler = SocketModeHandler(app, str(os.environ["SLACK_APP_TOKEN"])) |
64 |
| -# handler.start() |
65 |
| - |
66 | 1 | import os
|
67 | 2 | import time
|
68 | 3 | import random
|
|
0 commit comments