proscenium 0.0.7__py3-none-any.whl → 0.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ from typing import Callable, Optional
2
+
3
+ import logging
4
+ import importlib
5
+ import yaml
6
+ from pathlib import Path
7
+ from rich.console import Console
8
+ from proscenium.core import Production
9
+
10
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
11
+
12
+
13
+ def load_config(config_file_name: Path) -> dict:
14
+
15
+ if not config_file_name.exists():
16
+ raise FileNotFoundError(
17
+ f"Configuration file {config_file_name} not found. "
18
+ "Please provide a valid configuration file."
19
+ )
20
+
21
+ with open(config_file_name, "r", encoding="utf-8") as f:
22
+ config = yaml.safe_load(f)
23
+ return config
24
+
25
+
26
+ def production_from_config(
27
+ config_file_name: Path,
28
+ get_secret: Callable[[str, str], str],
29
+ sub_console: Optional[Console] = None,
30
+ ) -> tuple[Production, dict]:
31
+
32
+ config = load_config(config_file_name)
33
+
34
+ production_config = config.get("production", {})
35
+
36
+ production_module_name = production_config.get("module", None)
37
+
38
+ production_module = importlib.import_module(production_module_name, package=None)
39
+
40
+ production = production_module.make_production(config, get_secret, sub_console)
41
+
42
+ return production, config
proscenium/bin/bot.py CHANGED
@@ -4,32 +4,12 @@ import os
4
4
  import sys
5
5
  import logging
6
6
  import typer
7
- import importlib
7
+ from pathlib import Path
8
8
  from rich.console import Console
9
9
 
10
- from proscenium.admin import Admin
11
-
12
- from proscenium.interfaces.slack import (
13
- get_slack_auth,
14
- channel_table,
15
- bot_user_id,
16
- places_table,
17
- channel_maps,
18
- make_slack_listener,
19
- connect,
20
- send_curtain_up,
21
- listen,
22
- send_curtain_down,
23
- shutdown,
24
- )
25
-
26
10
  from proscenium.verbs.display import header
27
-
28
- logging.basicConfig(
29
- stream=sys.stdout,
30
- format="%(asctime)s %(levelname)-8s %(name)s: %(message)s",
31
- level=logging.WARNING,
32
- )
11
+ from proscenium.bin import production_from_config
12
+ from proscenium.interfaces.slack import slack_main
33
13
 
34
14
  logging.basicConfig(
35
15
  stream=sys.stdout,
@@ -41,17 +21,16 @@ app = typer.Typer(help="Proscenium Bot")
41
21
 
42
22
  log = logging.getLogger(__name__)
43
23
 
24
+ default_config_path = Path("demo/demo.yml")
25
+
44
26
 
45
27
  @app.command(help="""Start the Proscenium Bot.""")
46
28
  def start(
47
- verbose: bool = False,
48
- production_module_name: str = typer.Option(
49
- "demo.production",
50
- "-p",
51
- "--production",
52
- help="The name of the python module in PYTHONPATH in which the variable production of type proscenium.core.Production is defined.",
29
+ config_file: Path = typer.Option(
30
+ default_config_path,
31
+ help="The name of the Proscenium YAML configuration file.",
53
32
  ),
54
- force_rebuild: bool = False,
33
+ verbose: bool = False,
55
34
  ):
56
35
 
57
36
  console = Console()
@@ -65,76 +44,15 @@ def start(
65
44
 
66
45
  console.print(header())
67
46
 
68
- production_module = importlib.import_module(production_module_name, package=None)
69
-
70
- slack_admin_channel_id = os.environ.get("SLACK_ADMIN_CHANNEL_ID")
71
- # Note that the checking of the existence of the admin channel id is delayed
72
- # until after the subscribed channels are shown.
73
-
74
- production = production_module.make_production(slack_admin_channel_id, sub_console)
47
+ production, config = production_from_config(
48
+ config_file, os.environ.get, sub_console
49
+ )
75
50
 
76
51
  console.print("Preparing props...")
77
52
  production.prepare_props()
78
53
  console.print("Props are up-to-date.")
79
54
 
80
- slack_app_token, slack_bot_token = get_slack_auth()
81
-
82
- socket_mode_client = connect(slack_app_token, slack_bot_token)
83
-
84
- user_id = bot_user_id(socket_mode_client, console)
85
- console.print()
86
-
87
- channels_by_id, channel_name_to_id = channel_maps(socket_mode_client)
88
- console.print(channel_table(channels_by_id))
89
- console.print()
90
-
91
- if slack_admin_channel_id is None:
92
- raise ValueError(
93
- "SLACK_ADMIN_CHANNEL_ID environment variable not set. "
94
- "Please set it to the channel ID of the Proscenium admin channel."
95
- )
96
- if slack_admin_channel_id not in channels_by_id:
97
- raise ValueError(
98
- f"Admin channel {slack_admin_channel_id} not found in subscribed channels."
99
- )
100
-
101
- admin = Admin(slack_admin_channel_id)
102
- log.info("Admin handler started.")
103
-
104
- log.info("Places, please!")
105
- channel_id_to_character = production.places(channel_name_to_id)
106
- channel_id_to_character[slack_admin_channel_id] = admin
107
-
108
- console.print(places_table(channel_id_to_character, channels_by_id))
109
- console.print()
110
-
111
- slack_listener = make_slack_listener(
112
- user_id,
113
- slack_admin_channel_id,
114
- channels_by_id,
115
- channel_id_to_character,
116
- console,
117
- )
118
-
119
- send_curtain_up(socket_mode_client, production, slack_admin_channel_id)
120
-
121
- console.print("Starting the show. Listening for events...")
122
- listen(
123
- socket_mode_client,
124
- slack_listener,
125
- user_id,
126
- console,
127
- )
128
-
129
- send_curtain_down(socket_mode_client, slack_admin_channel_id)
130
-
131
- shutdown(
132
- socket_mode_client,
133
- slack_listener,
134
- user_id,
135
- production,
136
- console,
137
- )
55
+ slack_main(production, config, console)
138
56
 
139
57
 
140
58
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  from typing import Callable
2
-
3
2
  from typing import Generator
3
+
4
4
  import time
5
5
  import logging
6
6
  import os
@@ -15,6 +15,7 @@ from slack_sdk.socket_mode.listeners import SocketModeRequestListener
15
15
 
16
16
  from proscenium.core import Production
17
17
  from proscenium.core import Character
18
+ from proscenium.admin import Admin
18
19
 
19
20
  log = logging.getLogger(__name__)
20
21
 
@@ -277,3 +278,74 @@ def shutdown(
277
278
  production.curtain()
278
279
 
279
280
  console.print("Handlers stopped.")
281
+
282
+
283
+ def slack_main(
284
+ production: Production,
285
+ config: dict,
286
+ console: Console,
287
+ ) -> None:
288
+
289
+ slack_app_token, slack_bot_token = get_slack_auth()
290
+
291
+ socket_mode_client = connect(slack_app_token, slack_bot_token)
292
+
293
+ user_id = bot_user_id(socket_mode_client, console)
294
+ console.print()
295
+
296
+ channels_by_id, channel_name_to_id = channel_maps(socket_mode_client)
297
+ console.print(channel_table(channels_by_id))
298
+ console.print()
299
+
300
+ slack_admin_channel = config.get("slack", {}).get("admin_channel", None)
301
+
302
+ if slack_admin_channel is None:
303
+ raise ValueError(
304
+ "slack.admin_channel is not set. "
305
+ "Please set it to the channel name of the Proscenium admin channel."
306
+ )
307
+ slack_admin_channel_id = channel_name_to_id.get(slack_admin_channel, None)
308
+ if slack_admin_channel_id is None:
309
+ raise ValueError(
310
+ f"Admin channel {slack_admin_channel} not found in subscribed channels."
311
+ )
312
+
313
+ admin = Admin(slack_admin_channel_id)
314
+ log.info(
315
+ "Admin handler started %s %s.", slack_admin_channel, slack_admin_channel_id
316
+ )
317
+
318
+ log.info("Places, please!")
319
+ channel_id_to_character = production.places(channel_name_to_id)
320
+ channel_id_to_character[slack_admin_channel_id] = admin
321
+
322
+ console.print(places_table(channel_id_to_character, channels_by_id))
323
+ console.print()
324
+
325
+ slack_listener = make_slack_listener(
326
+ user_id,
327
+ slack_admin_channel_id,
328
+ channels_by_id,
329
+ channel_id_to_character,
330
+ console,
331
+ )
332
+
333
+ send_curtain_up(socket_mode_client, production, slack_admin_channel_id)
334
+
335
+ console.print("Starting the show. Listening for events...")
336
+ listen(
337
+ socket_mode_client,
338
+ slack_listener,
339
+ user_id,
340
+ console,
341
+ )
342
+
343
+ send_curtain_down(socket_mode_client, slack_admin_channel_id)
344
+
345
+ shutdown(
346
+ socket_mode_client,
347
+ slack_listener,
348
+ user_id,
349
+ production,
350
+ console,
351
+ )
@@ -12,18 +12,15 @@ def get_secret(key: str, default: str = None) -> str:
12
12
 
13
13
  try:
14
14
  value = userdata.get(key)
15
- print(
16
- f"Using {key} from colab userdata and setting corresponding os.environ value"
17
- )
18
15
  os.environ[key] = value
16
+ log.info(
17
+ f"In colab. Read {key} from colab userdata and set os.environ value"
18
+ )
19
19
  return value
20
20
  except userdata.SecretNotFoundError:
21
- print(f"Using default value for {key}")
22
21
  return default
23
22
  except ImportError:
24
23
  if key in os.environ:
25
- print(f"Not in colab. Using {key} from environment")
26
24
  return os.environ.get(key, default)
27
25
  else:
28
- print(f"Using default value for {key}")
29
26
  return default
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: proscenium
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: Frame AI Agents
5
5
  License: ASFv2
6
6
  Author: Adam Pingel
@@ -1,9 +1,10 @@
1
1
  proscenium/__init__.py,sha256=nDWNd6_TSf4vDQuHVBoAf4QfZCB3ZUFQ0M7XvifNJ-g,78
2
2
  proscenium/admin/__init__.py,sha256=GqGrkf7NOm3inuo67xszkARXZYKDsDs2jHuZh1tF4n0,924
3
- proscenium/bin/bot.py,sha256=nK4WN8ggpCr_KDpDI16Ib8RljmMpJyZ8qZTW8j7lwP4,3700
3
+ proscenium/bin/__init__.py,sha256=ThVsDG6BmnZ86gYaZLGMDcNmR6fVwBLJG3k_JawfzOY,1160
4
+ proscenium/bin/bot.py,sha256=kdZBe1SGM-S3-QSN-DM-_UnGwe6W5D32s-dTuczIPCU,1358
4
5
  proscenium/core/__init__.py,sha256=aSUqPMn2LjZ0C_l9Tx6yqqlfCzM7oSljZxHosJyjlLU,4335
5
6
  proscenium/interfaces/__init__.py,sha256=nDWNd6_TSf4vDQuHVBoAf4QfZCB3ZUFQ0M7XvifNJ-g,78
6
- proscenium/interfaces/slack.py,sha256=Arv3JT91gTZ_ZzizsOa9u1Wbbs8CnORr-KUzJzluy3g,8591
7
+ proscenium/interfaces/slack.py,sha256=wjkdhqAHgISxdNG5Pwo-8_QIyQf76X7b-0WwZfNabI8,10600
7
8
  proscenium/patterns/__init__.py,sha256=nDWNd6_TSf4vDQuHVBoAf4QfZCB3ZUFQ0M7XvifNJ-g,78
8
9
  proscenium/patterns/chunk_space.py,sha256=kQzGUtkQKGQGzGjBqS7jz_zr3uvJeiCBD2leflOenM8,1635
9
10
  proscenium/patterns/document_enricher.py,sha256=u-Q4FwvNAFj9nday235jUwxIwizht_VAW8DsmNQmoJs,2374
@@ -12,7 +13,7 @@ proscenium/patterns/graph_rag.py,sha256=1HH1xdlAA6ypvYdP4dWFm-KXrGPUmm0T4qIdAU8m
12
13
  proscenium/patterns/knowledge_graph.py,sha256=VLjG8Rp7YfJLZKe9bZt2d4NsGloBV1AYI6SuaQtRLhs,1137
13
14
  proscenium/patterns/rag.py,sha256=zvl_P48F3PDfVMgRXeiClLlevMsPKCMA1teVq9X20OE,1494
14
15
  proscenium/patterns/tools.py,sha256=f2CD6f7CYiSs0Tm1Ff1sOL5Ti6DqJ5HQvMI7NmIgqNs,1740
15
- proscenium/util/__init__.py,sha256=M1Fs2KD4JJJsJAStp8gdWD1DZn2N9IqFjhKYgHATKlM,854
16
+ proscenium/util/__init__.py,sha256=FC1hjA37VvmVpF9-OlYNp9TjArH6etr6KiAvF9t_6lI,679
16
17
  proscenium/verbs/__init__.py,sha256=nDWNd6_TSf4vDQuHVBoAf4QfZCB3ZUFQ0M7XvifNJ-g,78
17
18
  proscenium/verbs/chunk.py,sha256=hlVHfuR7sEAR8euh3FRd8hb2eJozE7bHe-E0RmAoFP8,1106
18
19
  proscenium/verbs/complete.py,sha256=Y1T49OfAV7K8p0DMzE4aVqtkgVfjUqb6IeOazzdYGow,5071
@@ -28,8 +29,8 @@ proscenium/verbs/read.py,sha256=twFtcuyP-y-UwksLmGMCOjMqI7mp--VgvkGDfga6IxA,1262
28
29
  proscenium/verbs/remember.py,sha256=Hh9BDRAYf7MGeMD4MzU73p6Q28KrSiLWPx4GjTW1amQ,296
29
30
  proscenium/verbs/vector_database.py,sha256=U09P7jnpzUDeP7pEgJubf8xQsxC-O8Qb0MS0KY8eoe8,3527
30
31
  proscenium/verbs/write.py,sha256=0GUJuixLnuu_EbFFzAIgrhLEQnOrL0TdUlMiqOl9KtA,367
31
- proscenium-0.0.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
32
- proscenium-0.0.7.dist-info/METADATA,sha256=w5WsPpSRx9yYSYyQPdVs0ZhPr01zZjUXUUv83vaEBig,2487
33
- proscenium-0.0.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
34
- proscenium-0.0.7.dist-info/entry_points.txt,sha256=Q05DVkPq_SjgD8mFN6bG5ae2r_UbsqKCdy2kDAtHYGU,57
35
- proscenium-0.0.7.dist-info/RECORD,,
32
+ proscenium-0.0.8.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
33
+ proscenium-0.0.8.dist-info/METADATA,sha256=A4wvRR5YW3DZlBrFXcm8d5P9OPkUB6jlSSRUS67XWi0,2487
34
+ proscenium-0.0.8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
35
+ proscenium-0.0.8.dist-info/entry_points.txt,sha256=Q05DVkPq_SjgD8mFN6bG5ae2r_UbsqKCdy2kDAtHYGU,57
36
+ proscenium-0.0.8.dist-info/RECORD,,