Skip to content

Commit 9484cde

Browse files
committed
(fix): explicit DB/Schema for Agent
1 parent 32ea8ad commit 9484cde

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

app.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424
logger = logger("demo_mate_bot")
2525

2626
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+
}
2935
).create()
3036
logger.debug(
3137
f"Account:{session.conf.get('account')},User:{session.conf.get('user')}"
@@ -80,7 +86,7 @@ def do_setup(
8086
try:
8187
client.chat_postMessage(
8288
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:",
8490
)
8591

8692
global db_setup
@@ -255,7 +261,7 @@ def cleanup_handler(ack, client, command, respond):
255261
# Send the response with wait message
256262
client.chat_postMessage(
257263
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:",
259265
)
260266
db_name = command.get("text", "").strip()
261267
logger.debug(f"command_text:{db_name}")
@@ -308,7 +314,7 @@ def handle_cortalyst(ack, client: WebClient, say, command, respond, logger):
308314
command_text = command.get("text", "").strip()
309315
if not command_text:
310316
try:
311-
logger.debug(f"No question asking user")
317+
logger.debug("No question asking user")
312318
# Send the response with input block
313319
respond(
314320
blocks=blocks.cortex_question,
@@ -430,19 +436,21 @@ def ask_cortex_analyst(channel_id: str, client: WebClient, say, logger, question
430436

431437
client.chat_postMessage(
432438
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:",
434440
)
435441

436442
if os.getenv("PRIVATE_KEY_FILE_PATH") is None:
437443
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."
439445
)
440446

441447
cortalyst = Cortlayst(
442448
account=session.conf.get("account"),
443449
user=session.conf.get("user"),
444450
host=session.conf.get("host"),
445451
private_key_file_path=os.getenv("PRIVATE_KEY_FILE_PATH"),
452+
database=db_setup.db_name,
453+
schema=db_setup.schema_name,
446454
)
447455

448456
ans = cortalyst.answer(question)
@@ -487,15 +495,15 @@ def show_response(client: WebClient, channel_id, content: List[Dict[str, Any]],
487495
match item["type"]:
488496
case "sql":
489497
# 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")
491499
query = item["statement"]
492500
say(
493501
blocks=blocks.create_sql_block(query),
494502
text="Generated SQL",
495503
)
496504

497505
# Build and Display Dataframe for Query Results
498-
logger.debug(f"Building query result")
506+
logger.debug("Building query result")
499507
df = session.sql(query).to_pandas()
500508
say(
501509
blocks=blocks.create_df_block(df),

0 commit comments

Comments
 (0)