Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Customer-Eval] Make changes to work in Sis #220

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ SELECT SYSTEM$BEHAVIOR_CHANGE_BUNDLE_STATUS('2024_08');

> For more information on this bundle please see our [BCR Documentation](https://docs.snowflake.com/en/release-notes/behavior-changes).

**UPDATED WITH EVAL INSTALL INSTRUCTION**

[Snowflake CLI](https://docs.snowflake.com/en/developer-guide/snowflake-cli-v2/index) is recommended for deploying the app in Streamlit in Snowflake. Please see Snowflake CLI [installation instructions](https://docs.snowflake.com/en/developer-guide/snowflake-cli-v2/installation/installation) to install. **Snowflake CLI version 3.0+ is recommended**. Follow the below instructions to install the Semantic Model Generator in Streamlit in Snowflake.

If you do not have Snowflake CLI installed, the setup can be replicated manually with the [VS Code Snowflake extension](https://docs.snowflake.com/en/user-guide/vscode-ext), Snowsight or [Snowflake Native Git Integration](https://docs.snowflake.com/en/developer-guide/git/git-overview):
- If using Snowsight, you may use the files upload wizard to upload files. Please pay close attention to maintain the directory structure referenced in `setup_sis/app_setup.sql`.
- If using the Native Git Integration, copy and paste the code from this [setup file](https://github.com/Snowflake-Labs/semantic-model-generator/blob/main/sis_setup/sissetup_snowsightgit.sql) and run in Snowsight.
- If using Snowsight, you may use the files upload wizard to upload files. Please pay close attention to maintain the directory structure referenced in `setup_sis/app_setup_eval_branch.sql`.
- If using the Native Git Integration, copy and paste the code from this [setup file](https://github.com/Snowflake-Labs/semantic-model-generator/blob/customer-eval/sis_setup/sissetup_snowsightgit_eval_branch.sql) and run in Snowsight.

### Snowflake CLI Installation

Expand Down
5 changes: 4 additions & 1 deletion journeys/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any

import pandas as pd
import snowflake.snowpark._internal.utils as snowpark_utils
import streamlit as st
from loguru import logger
from snowflake.connector.pandas_tools import write_pandas
Expand Down Expand Up @@ -114,7 +115,6 @@ def _llm_judge(frame: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame({"EXPLANATION": [], "CORRECT": []})

# create prompt frame series
table_name = "__LLM_JUDGE_TEMP_TABLE"
col_name = "LLM_JUDGE_PROMPT"

prompt_frame = frame.apply(
Expand All @@ -126,6 +126,9 @@ def _llm_judge(frame: pd.DataFrame) -> pd.DataFrame:
),
).to_frame(name=col_name)
conn = get_snowflake_connection()
table_name = snowpark_utils.random_name_for_temp_object(
snowpark_utils.TempObjectType.TABLE
)
_ = write_pandas(
conn=conn,
df=prompt_frame,
Expand Down
51 changes: 51 additions & 0 deletions sis_setup/app_setup_eval_branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
SET (streamlit_warehouse)=(SELECT CURRENT_WAREHOUSE());

CREATE DATABASE IF NOT EXISTS CORTEX_ANALYST_SEMANTICS_EVAL
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';

CREATE SCHEMA IF NOT EXISTS CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';

-- Create stage for App logic and 3rd party packages
CREATE OR REPLACE STAGE CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE
DIRECTORY = (ENABLE = true)
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';

-- Upload 3rd party packages
-- Run from sis_setup/ as paths are relative to this directory
PUT file://app_utils/*.zip @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE OVERWRITE = TRUE AUTO_COMPRESS = FALSE;

-- Upload App logic
PUT file://app.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://environment.yml @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://semantic_model_generator/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://semantic_model_generator/data_processing/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/data_processing/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://semantic_model_generator/protos/*.p* @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/protos/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://semantic_model_generator/snowflake_utils/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/snowflake_utils/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://semantic_model_generator/validate/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/validate/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://images/*.png @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/images/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://journeys/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/journeys/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://partner/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/partner/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;
PUT file://app_utils/*.py @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/app_utils/ OVERWRITE = TRUE AUTO_COMPRESS = FALSE;

-- Create Streamlit
CREATE OR REPLACE STREAMLIT CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.SEMANTIC_MODEL_GENERATOR
ROOT_LOCATION = '@CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator'
MAIN_FILE = 'app.py'
TITLE = "Semantic Model Generator (Eval)"
IMPORTS = ('@cortex_analyst_semantics_eval.semantic_model_generator.streamlit_stage/looker_sdk.zip',
'@cortex_analyst_semantics_eval.semantic_model_generator.streamlit_stage/strictyaml.zip')
QUERY_WAREHOUSE = $streamlit_warehouse
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';
85 changes: 85 additions & 0 deletions sis_setup/sissetup_snowsightgit_eval_branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
SET (streamlit_warehouse)=(SELECT CURRENT_WAREHOUSE());

CREATE DATABASE IF NOT EXISTS CORTEX_ANALYST_SEMANTICS_EVAL;
USE DATABASE CORTEX_ANALYST_SEMANTICS_EVAL;

-- Create API Integration for Git
CREATE OR REPLACE API INTEGRATION git_api_integration_snowflake_labs
API_PROVIDER = git_https_api
API_ALLOWED_PREFIXES = ('https://github.com/Snowflake-Labs')
ENABLED = TRUE;

-- Create Git Repository
CREATE OR REPLACE GIT REPOSITORY git_snowflake_semantic_model_generator
API_INTEGRATION = git_api_integration_snowflake_labs
ORIGIN = 'https://github.com/Snowflake-Labs/semantic-model-generator.git';

ALTER GIT REPOSITORY git_snowflake_semantic_model_generator FETCH;

-- Create Schema to host streamlit app
CREATE SCHEMA IF NOT EXISTS CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';


-- Create stage for App logic and 3rd party packages
CREATE OR REPLACE STAGE CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE
DIRECTORY = (ENABLE = true)
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';

-- Copy Files from Git Repository into App Stage
COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/app_utils/
PATTERN='.*[.]zip';

COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/
FILES = ('environment.yml', 'app.py');

COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/semantic_model_generator/
PATTERN='.*[.]py';

RM @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/tests;
RM @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/semantic_model_generator/output_models;

COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/images/
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/images/
PATTERN='.*[.]png';

COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/journeys/
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/journeys/
PATTERN='.*[.]py';

COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/partner/
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/partner/
PATTERN='.*[.]py';

COPY FILES
INTO @CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator/app_utils/
FROM @CORTEX_ANALYST_SEMANTICS_EVAL.PUBLIC.git_snowflake_semantic_model_generator/branches/customer-eval/app_utils/
PATTERN='.*[.]py';

-- Create Streamlit App
CREATE OR REPLACE STREAMLIT CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.SEMANTIC_MODEL_GENERATOR
ROOT_LOCATION = '@CORTEX_ANALYST_SEMANTICS_EVAL.SEMANTIC_MODEL_GENERATOR.STREAMLIT_STAGE/semantic_model_generator'
MAIN_FILE = 'app.py'
TITLE = "Semantic Model Generator (with Eval)"
IMPORTS = ('@cortex_analyst_semantics_eval.semantic_model_generator.streamlit_stage/looker_sdk.zip',
'@cortex_analyst_semantics_eval.semantic_model_generator.streamlit_stage/strictyaml.zip')
QUERY_WAREHOUSE = $streamlit_warehouse
COMMENT = '{"origin": "sf_sit",
"name": "skimantics",
"version": {"major": 2, "minor": 0},
"attributes": {"deployment": "sis"}}';