Skip to content

Commit

Permalink
add some debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astepniak committed Oct 17, 2024
1 parent b1c4ce7 commit 7a23e37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 5 additions & 4 deletions admin_apps/journeys/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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}")
Expand Down
11 changes: 9 additions & 2 deletions semantic_model_generator/data_processing/cte_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = [
Expand All @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7a23e37

Please sign in to comment.