Skip to content

Commit 2beaa4d

Browse files
committed
Updated Streamlit UI and added functions for Cortex Agents
1 parent 399b423 commit 2beaa4d

File tree

6 files changed

+61
-13
lines changed

6 files changed

+61
-13
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Get a hybrid (vector and keyword) search engine on your text data in minutes,
1818
- Use Cortex Search for your RAG Application
1919
- Use Cortex Search Powered Chat
2020

21+
### Agent
22+
23+
2124
## Prerequisites
2225

2326
Before you begin, ensure you have met the following requirements:
@@ -60,6 +63,41 @@ To configure the application mode, update the `mode` parameter in `src/settings_
6063
- Set to `"debug"` for local development and editing.
6164
- Set to `"native"` for running natively in Snowflake.
6265

66+
### Authentication for Cortex Agent – JWT Token Support Only
67+
68+
This app currently supports **only JWT-based authentication** using RSA key pairs for Cortex Agents. OAuth is **not supported** at this time.
69+
70+
#### Step 1: Generate RSA Key Pair
71+
72+
```bash
73+
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_private_key.p8 -nocrypt
74+
openssl rsa -in rsa_private_key.p8 -pubout -out rsa_public_key.pub
75+
```
76+
77+
#### Step 2: Upload Public Key to Snowflake
78+
79+
1. Copy the content from `rsa_public_key.pub` (exclude `-----BEGIN PUBLIC KEY-----` headers).
80+
2. In Snowflake, run:
81+
82+
```sql
83+
alter user <your_username> set rsa_public_key='<paste_public_key_here>';
84+
```
85+
86+
3. Retrieve the public key fingerprint:
87+
88+
```sql
89+
desc user <your_username>;
90+
```
91+
92+
Use the fingerprint in `rsa_public_key_fp`.
93+
94+
#### Step 3: Add to `settings_config.json`
95+
96+
- Paste full contents of `rsa_private_key.p8` into `rsa_private_key` (escape newlines if needed).
97+
- Paste fingerprint into `rsa_public_key_fp`.
98+
99+
For more details, refer to the [Snowflake documentation](https://docs.snowflake.com/en/user-guide/key-pair-auth.html#using-key-pair-authentication).
100+
63101
## Running the App
64102

65103
### Locally

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ PyPDF2
44
langchain
55
pandas
66
pyarrow
7-
snowflake
7+
snowflake
8+
PyJWT

snowflake.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
definition_version: "1"
1+
definition_version: '1'
22
streamlit:
33
name: snowflake_ai_toolkit
44
stage: sf_ai_stage
@@ -8,6 +8,7 @@ streamlit:
88
#pages_dir: pages/
99
additional_source_files:
1010
- src/cortex_functions.py
11+
- src/cortex_agent.py
1112
- src/utils.py
1213
- src/html_snippets.py
1314
- src/styles.css

src/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import threading
88
import json
99
from snowflake.core import Root
10-
10+
import os
1111

1212
config_path = Path("src/settings_config.json")
1313
with open(config_path, "r") as f:
@@ -29,7 +29,7 @@ def display_search(session):
2929
# st.write(res)
3030

3131

32-
warehouse = config["snowflake"]["warehouse"]
32+
warehouse = config["warehouse"]
3333

3434
if create_or_use == "Create":
3535

src/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ def create_prompt_for_rag(session, question: str, rag: bool, column: str, databa
284284
"""
285285
return prompt
286286

287-
def create_prompt_for_search_service(session, question: str, search_service: str, chat_history: list):
288-
289-
return
290-
291287
def get_cortex_complete_result(session, query: str):
292288
"""
293289
Executes a Cortex complete query and returns the result.
@@ -394,8 +390,8 @@ def create_database_and_stage_if_not_exists(session: Session):
394390
session (Session): Snowflake session object
395391
"""
396392
# Fetch database and stage details from the config file
397-
database_name = config["snowflake"]["database"]
398-
stage_name = config["snowflake"]["stage"]
393+
database_name = config["database"]
394+
stage_name = config["stage"]
399395

400396
# Check if the database exists, and create if it doesn't
401397
database_query = f"SHOW DATABASES LIKE '{database_name}'"

streamlit_app.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from snowflake.snowpark.exceptions import SnowparkSQLException
88
from src.notification import *
99
from src.search import *
10+
from src.cortex_agent import *
11+
# from trulens.connectors.snowflake import SnowflakeConnector
12+
# from trulens.core.session import TruSession
13+
# from trulens.dashboard import run_dashboard
1014

1115
# Load the config file
1216
config_path = Path("src/settings_config.json")
@@ -33,10 +37,15 @@
3337
elif config["mode"] == "debug":
3438
try:
3539
connection_parameters = {
36-
"account": config["snowflake"]["account"],"user": config["snowflake"]["user"],"password": config["snowflake"]["password"],
37-
"role": config["snowflake"]["role"],"warehouse": config["snowflake"]["warehouse"],"database": config["snowflake"]["database"],
38-
"schema": config["snowflake"]["schema"]
40+
"account": config["account"],"user": config["user"],"password": config["password"],
41+
"role": config["role"],"warehouse": config["warehouse"],"database": config["database"],
42+
"schema": config["schema"],
43+
# "init_server_side": True
3944
}
45+
# connector = SnowflakeConnector(**connection_parameters)
46+
# truelens_session = TruSession(connector)
47+
# st.session_state.truelens_session = truelens_session
48+
# run_dashboard(truelens_session)
4049
st.session_state.snowflake_session = Session.builder.configs(connection_parameters).create()
4150
except Exception as e:
4251
st.error(f"Failed to create session in debug mode: {e}")
@@ -114,6 +123,8 @@
114123
st.session_state.page = "Build"
115124
if st.button("🔍 Cortex Search"):
116125
st.session_state.page = "Cortex Search"
126+
if st.button("🤖 Cortex Agent"):
127+
st.session_state.page = "Cortex Agent"
117128
if st.button("🔔 Notification"):
118129
st.session_state.page = "Notification"
119130

@@ -124,6 +135,7 @@
124135
"Build": build.display_build,
125136
"Notification": notification.display_notification,
126137
"Cortex Search": display_search,
138+
"Cortex Agent": display_cortex_agent,
127139
"Setup": setup.display_setup
128140
}
129141

0 commit comments

Comments
 (0)