|
24 | 24 | logger = logger("demo_mate_bot") |
25 | 25 |
|
26 | 26 | try: |
27 | | - session = Session.builder.config( |
28 | | - "connection_name", os.getenv("SNOWFLAKE_CONNECTION_NAME", "trial-key") |
| 27 | + session = Session.builder.configs( |
| 28 | + { |
| 29 | + "account": os.getenv("SNOWFLAKE_ACCOUNT"), |
| 30 | + "user": os.getenv("SNOWFLAKE_USER"), |
| 31 | + "authenticator": "SNOWFLAKE_JWT", |
| 32 | + "private_key_file": os.getenv("PRIVATE_KEY_FILE_PATH"), |
| 33 | + "private_key_file_pwd": os.getenv("PRIVATE_KEY_PASSPHRASE"), |
| 34 | + } |
29 | 35 | ).create() |
30 | 36 | logger.debug( |
31 | 37 | f"Account:{session.conf.get('account')},User:{session.conf.get('user')}" |
@@ -80,7 +86,7 @@ def do_setup( |
80 | 86 | try: |
81 | 87 | client.chat_postMessage( |
82 | 88 | channel=channel_id, |
83 | | - text=f"Wait for few seconds for the setup to be done :hourglass_flowing_sand:", |
| 89 | + text="Wait for few seconds for the setup to be done :hourglass_flowing_sand:", |
84 | 90 | ) |
85 | 91 |
|
86 | 92 | global db_setup |
@@ -255,7 +261,7 @@ def cleanup_handler(ack, client, command, respond): |
255 | 261 | # Send the response with wait message |
256 | 262 | client.chat_postMessage( |
257 | 263 | channel=channel_id, |
258 | | - text=f"Wait for few seconds for the cleanup to be done :hourglass_flowing_sand:", |
| 264 | + text="Wait for few seconds for the cleanup to be done :hourglass_flowing_sand:", |
259 | 265 | ) |
260 | 266 | db_name = command.get("text", "").strip() |
261 | 267 | logger.debug(f"command_text:{db_name}") |
@@ -308,7 +314,7 @@ def handle_cortalyst(ack, client: WebClient, say, command, respond, logger): |
308 | 314 | command_text = command.get("text", "").strip() |
309 | 315 | if not command_text: |
310 | 316 | try: |
311 | | - logger.debug(f"No question asking user") |
| 317 | + logger.debug("No question asking user") |
312 | 318 | # Send the response with input block |
313 | 319 | respond( |
314 | 320 | blocks=blocks.cortex_question, |
@@ -430,19 +436,21 @@ def ask_cortex_analyst(channel_id: str, client: WebClient, say, logger, question |
430 | 436 |
|
431 | 437 | client.chat_postMessage( |
432 | 438 | channel=channel_id, |
433 | | - text=f":hourglass_flowing_sand: Wait for a few seconds... while I ask the Cortex Analyst :robot_face:", |
| 439 | + text=":hourglass_flowing_sand: Wait for a few seconds... while I ask the Cortex Analyst :robot_face:", |
434 | 440 | ) |
435 | 441 |
|
436 | 442 | if os.getenv("PRIVATE_KEY_FILE_PATH") is None: |
437 | 443 | raise Exception( |
438 | | - f"Require PRIVATE_KEY_FILE_PATH to be set. Consult Snowflake documentation https://docs.snowflake.com/user-guide/key-pair-auth#configuring-key-pair-authentication." |
| 444 | + "Require PRIVATE_KEY_FILE_PATH to be set. Consult Snowflake documentation https://docs.snowflake.com/user-guide/key-pair-auth#configuring-key-pair-authentication." |
439 | 445 | ) |
440 | 446 |
|
441 | 447 | cortalyst = Cortlayst( |
442 | 448 | account=session.conf.get("account"), |
443 | 449 | user=session.conf.get("user"), |
444 | 450 | host=session.conf.get("host"), |
445 | 451 | private_key_file_path=os.getenv("PRIVATE_KEY_FILE_PATH"), |
| 452 | + database=db_setup.db_name, |
| 453 | + schema=db_setup.schema_name, |
446 | 454 | ) |
447 | 455 |
|
448 | 456 | ans = cortalyst.answer(question) |
@@ -487,15 +495,15 @@ def show_response(client: WebClient, channel_id, content: List[Dict[str, Any]], |
487 | 495 | match item["type"]: |
488 | 496 | case "sql": |
489 | 497 | # Send raw generated query for reference |
490 | | - logger.debug(f"Generating text block with generated SQL") |
| 498 | + logger.debug("Generating text block with generated SQL") |
491 | 499 | query = item["statement"] |
492 | 500 | say( |
493 | 501 | blocks=blocks.create_sql_block(query), |
494 | 502 | text="Generated SQL", |
495 | 503 | ) |
496 | 504 |
|
497 | 505 | # Build and Display Dataframe for Query Results |
498 | | - logger.debug(f"Building query result") |
| 506 | + logger.debug("Building query result") |
499 | 507 | df = session.sql(query).to_pandas() |
500 | 508 | say( |
501 | 509 | blocks=blocks.create_df_block(df), |
|
0 commit comments