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

Allow verified queries to be marked for onboarding #192

Merged
merged 3 commits into from
Oct 30, 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
30 changes: 22 additions & 8 deletions journeys/iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
yaml_to_semantic_model,
)
from semantic_model_generator.protos import semantic_model_pb2
from semantic_model_generator.snowflake_utils.env_vars import (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code cleanup, removing unused imports

SNOWFLAKE_ACCOUNT_LOCATOR,
SNOWFLAKE_HOST,
SNOWFLAKE_USER,
)
from semantic_model_generator.validate_model import validate


Expand Down Expand Up @@ -234,6 +229,11 @@ def edit_verified_query(

elif st.session_state.get("successful_sql", False):
# Moved outside the `if run:` block to ensure it's always evaluated
mark_as_onboarding = st.checkbox(
"Mark as onboarding question",
key=f"edit_onboarding_idx_{message_index}",
help="Mark this question as an onboarding verified query.",
)
save = st.button(
"Save as verified query",
use_container_width=True,
Expand All @@ -243,12 +243,18 @@ def edit_verified_query(
sql_no_analyst_comment = user_updated_sql.replace(
" /* Generated by Cortex Analyst */", ""
)
add_verified_query(question, sql_no_analyst_comment)
add_verified_query(
question,
sql_no_analyst_comment,
is_onboarding_question=mark_as_onboarding,
)
st.session_state["editing"] = False
st.session_state["confirmed_edits"] = True


def add_verified_query(question: str, sql: str) -> None:
def add_verified_query(
question: str, sql: str, is_onboarding_question: bool = False
) -> None:
"""Save verified question and SQL into an in-memory list with additional details."""
# Verified queries follow the Snowflake definitions.
verified_query = semantic_model_pb2.VerifiedQuery(
Expand All @@ -257,6 +263,7 @@ def add_verified_query(question: str, sql: str) -> None:
sql=sql,
verified_by=st.session_state["user_name"],
verified_at=int(time.time()),
use_as_onboarding_question=is_onboarding_question,
)
st.session_state.semantic_model.verified_queries.append(verified_query)
st.success(
Expand Down Expand Up @@ -307,6 +314,11 @@ def display_content(
df = pd.read_sql(sql, conn)
st.dataframe(df, hide_index=True)

mark_as_onboarding = st.checkbox(
"Mark as onboarding question",
key=f"onboarding_idx_{message_index}",
help="Mark this question as an onboarding verified query.",
)
left, right = st.columns(2)
if right.button(
"Save as verified query",
Expand All @@ -317,7 +329,9 @@ def display_content(
cleaned_sql = sql_no_cte.replace(
" /* Generated by Cortex Analyst */", ""
)
add_verified_query(question, cleaned_sql)
add_verified_query(
question, cleaned_sql, is_onboarding_question=mark_as_onboarding
)

if left.button(
"Edit",
Expand Down
3 changes: 3 additions & 0 deletions semantic_model_generator/protos/semantic_model.proto
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ message VerifiedQuery {
int64 verified_at = 5 [(optional) = true];
// Name of the person who verified this query.
string verified_by = 6 [(optional) = true];
// Whether to always include in this question in the suggested questions
// module
bool use_as_onboarding_question = 7 [(optional) = true];
}

// VerifiedQueryRepository is a simply a collection of verified queries.
Expand Down
Loading
Loading