From 7a23e37e00e3c594baa6d744f2e85171d7326d08 Mon Sep 17 00:00:00 2001 From: Adrian Stepniak Date: Thu, 17 Oct 2024 17:09:05 +0200 Subject: [PATCH] add some debug logs --- admin_apps/journeys/iteration.py | 9 +++++---- semantic_model_generator/data_processing/cte_utils.py | 11 +++++++++-- .../snowflake_utils/snowflake_connector.py | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/admin_apps/journeys/iteration.py b/admin_apps/journeys/iteration.py index b1c01f10..bb9a8dd1 100644 --- a/admin_apps/journeys/iteration.py +++ b/admin_apps/journeys/iteration.py @@ -6,6 +6,7 @@ import requests import sqlglot import streamlit as st +from loguru import logger from snowflake.connector import ProgrammingError, SnowflakeConnection from streamlit.delta_generator import DeltaGenerator from streamlit_extras.row import row @@ -93,11 +94,10 @@ def send_message( "messages": messages, "semantic_model": proto_to_yaml(st.session_state.semantic_model), } - host = st.session_state.host_name + api_endpoint = API_ENDPOINT.format(HOST=st.session_state.host_name) + logger.debug(f"Sending request to Analyst API at {api_endpoint}: {request_body}") resp = requests.post( - API_ENDPOINT.format( - HOST=host, - ), + api_endpoint, json=request_body, headers={ "Authorization": f'Snowflake Token="{_conn.rest.token}"', # type: ignore[union-attr] @@ -106,6 +106,7 @@ def send_message( ) if resp.status_code < 400: json_resp: Dict[str, Any] = resp.json() + logger.debug(f"Received response from Analyst API: {json_resp}") return json_resp else: raise Exception(f"Failed request with status {resp.status_code}: {resp.text}") diff --git a/semantic_model_generator/data_processing/cte_utils.py b/semantic_model_generator/data_processing/cte_utils.py index 92857c54..8300a54f 100644 --- a/semantic_model_generator/data_processing/cte_utils.py +++ b/semantic_model_generator/data_processing/cte_utils.py @@ -142,6 +142,7 @@ def _generate_cte_for( cte += ",\n".join(expr_columns) + "\n" cte += f"FROM {fully_qualified_table_name(table.base_table)}" cte += ")" + return cte @@ -266,7 +267,10 @@ def generate_select( non_agg_cte + f"SELECT * FROM {logical_table_name(table_in_column_format)} LIMIT {limit}" ) - sqls_to_return.append(_convert_to_snowflake_sql(non_agg_sql)) + # sqls_to_return.append(_convert_to_snowflake_sql(non_agg_sql)) + sqls_to_return.append( + non_agg_sql + ) # do not convert to snowflake sql for now, as sqlglot make mistakes sometimes, e.g. with TO_DATE() # Generate select query for columns with aggregation exprs. agg_cols = [ @@ -280,7 +284,10 @@ def generate_select( agg_cte + f"SELECT * FROM {logical_table_name(table_in_column_format)} LIMIT {limit}" ) - sqls_to_return.append(_convert_to_snowflake_sql(agg_sql)) + # sqls_to_return.append(_convert_to_snowflake_sql(agg_sql)) + sqls_to_return.append( + agg_sql + ) # do not convert to snowflake sql for now, as sqlglot make mistakes sometimes, e.g. with TO_DATE() return sqls_to_return diff --git a/semantic_model_generator/snowflake_utils/snowflake_connector.py b/semantic_model_generator/snowflake_utils/snowflake_connector.py index ea00f4bf..15966a86 100644 --- a/semantic_model_generator/snowflake_utils/snowflake_connector.py +++ b/semantic_model_generator/snowflake_utils/snowflake_connector.py @@ -16,7 +16,7 @@ ConnectionType = TypeVar("ConnectionType") # Append this to the end of the auto-generated comments to indicate that the comment was auto-generated. AUTOGEN_TOKEN = "__" -_autogen_model = "llama3-8b" +_autogen_model = "llama3.1-70b" # This is the raw column name from snowflake information schema or desc table _COMMENT_COL = "COMMENT" @@ -115,6 +115,7 @@ def _get_column_comment( values: {';'.join(column_values) if column_values else ""}; Please provide a business description for the column. Only return the description without any other text.""" complete_sql = f"select SNOWFLAKE.CORTEX.COMPLETE('{_autogen_model}', '{comment_prompt}')" + logger.debug(f"Complete_sql: {complete_sql}") cmt = conn.cursor().execute(complete_sql).fetchall()[0][0] # type: ignore[union-attr] return str(cmt + AUTOGEN_TOKEN) except Exception as e: