Skip to content

Commit 2399022

Browse files
authored
Improvements to GPT Actions library - Snowflake Direct (#1410)
1 parent 027ad90 commit 2399022

File tree

1 file changed

+76
-16
lines changed

1 file changed

+76
-16
lines changed

examples/chatgpt/gpt_actions_library/gpt_action_snowflake_direct.ipynb

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"\n",
143143
"### OpenAPI Schema\n",
144144
"\n",
145-
"Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail."
145+
"Once you've created a Custom GPT, copy the text below in the Actions panel. Update the servers url to match your Snowflake Account Name url plus `/api/v2` as described [here](https://docs.snowflake.com/en/user-guide/organizations-connect#standard-account-urls). Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail."
146146
]
147147
},
148148
{
@@ -161,7 +161,7 @@
161161
" version: 1.0.0\n",
162162
" description: API for executing statements in Snowflake with specific warehouse and role settings.\n",
163163
"servers:\n",
164-
" - url: 'https://<your server ID>.<your cloud region>.<your cloud provider>.snowflakecomputing.com/api/v2'\n",
164+
" - url: 'https://<orgname>-<account_name>.snowflakecomputing.com/api/v2'\n",
165165
"\n",
166166
"\n",
167167
"paths:\n",
@@ -238,16 +238,53 @@
238238
"cell_type": "markdown",
239239
"metadata": {},
240240
"source": [
241-
"Before you set up authentication in ChatGPT, please take the following steps in the application."
241+
"Before you set up authentication in ChatGPT, please take the following steps in Snowflake.\n",
242+
"\n",
243+
"### 1. Optional: Configure IP Whitelisting for ChatGPT\n",
244+
"Snowflake accounts with network policies that limit connections by IP, may require exceptions to be added for ChatGPT.\n",
245+
"* Review the Snowflake documentation on [Network Policies](https://docs.snowflake.com/en/user-guide/network-policies)\n",
246+
"* Go to the Snowflake Worksheets\n",
247+
"* Create a network rule with the ChatGPT IP egress ranges listed [here](https://platform.openai.com/docs/actions/production/ip-egress-ranges)\n",
248+
"* Create a corresponding Network Policy"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": null,
254+
"metadata": {
255+
"vscode": {
256+
"languageId": "yaml"
257+
}
258+
},
259+
"outputs": [],
260+
"source": [
261+
"## Example with ChatGPT IPs as of September 19, 2024\n",
262+
"## Make sure to get the current IP ranges from https://platform.openai.com/docs/actions/production\n",
263+
"CREATE NETWORK RULE chatgpt_network_rule\n",
264+
" MODE = INGRESS\n",
265+
" TYPE = IPV4\n",
266+
" VALUE_LIST = ('23.102.140.112/28',\n",
267+
" '13.66.11.96/28',\n",
268+
" '104.210.133.240/28',\n",
269+
" '20.97.188.144/28',\n",
270+
" '20.161.76.48/28',\n",
271+
" '52.234.32.208/28',\n",
272+
" '52.156.132.32/28',\n",
273+
" '40.84.220.192/28',\n",
274+
" '23.98.178.64/28',\n",
275+
" '40.84.180.128/28');\n",
276+
"\n",
277+
"CREATE NETWORK POLICY chatgpt_network_policy\n",
278+
" ALLOWED_NETWORK_RULE_LIST = ('chatgpt_network_rule');"
242279
]
243280
},
244281
{
245282
"cell_type": "markdown",
246283
"metadata": {},
247284
"source": [
285+
"### 2. Set up the Securit Integration\n",
248286
"* Review the Snowflake OAuth Overview: [https://docs.snowflake.com/en/user-guide/oauth-snowflake-overview](https://docs.snowflake.com/en/user-guide/oauth-snowflake-overview)\n",
249-
"* Go to the Snowflake Worksheets\n",
250-
"* Create new OAuth credentials through a [Security Integration](https://docs.snowflake.com/en/sql-reference/sql/create-security-integration-oauth-snowflake) - you will need a new one for each OAuth app/custom GPT since Snowflake Redirect URIs are 1-1 mapped to Security Integrations\n"
287+
"* Create new OAuth credentials through a [Security Integration](https://docs.snowflake.com/en/sql-reference/sql/create-security-integration-oauth-snowflake) - you will need a new one for each OAuth app/custom GPT since Snowflake Redirect URIs are 1-1 mapped to Security Integrations"
251288
]
252289
},
253290
{
@@ -267,7 +304,8 @@
267304
" OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'\n",
268305
" OAUTH_REDIRECT_URI = 'https://oauth.pstmn.io/v1/callback' --- // this is a temporary value while testing your integration. You will replace this with the value your GPT provides\n",
269306
" OAUTH_ISSUE_REFRESH_TOKENS = TRUE\n",
270-
" OAUTH_REFRESH_TOKEN_VALIDITY = 7776000;"
307+
" OAUTH_REFRESH_TOKEN_VALIDITY = 7776000;\n",
308+
" NETWORK_POLICY = chatgpt_network_policy --- // this line should only be included if you followed step 1 above"
271309
]
272310
},
273311
{
@@ -312,11 +350,30 @@
312350
"metadata": {},
313351
"source": [
314352
"\n",
315-
"* Retrieve your OAuth Client Secret\n",
353+
"* Retrieve your OAuth Client Secret"
354+
]
355+
},
356+
{
357+
"cell_type": "code",
358+
"execution_count": null,
359+
"metadata": {
360+
"vscode": {
361+
"languageId": "yaml"
362+
}
363+
},
364+
"outputs": [],
365+
"source": [
366+
"select SYSTEM$SHOW_OAUTH_CLIENT_SECRETS('CHATGPT_INTEGRATION');"
367+
]
368+
},
369+
{
370+
"cell_type": "markdown",
371+
"metadata": {},
372+
"source": [
316373
"\n",
317-
"You’ll find the Client Secret in OAUTH_CLIENT_SECRET.\n",
374+
"You’ll find the Client Secret in OAUTH_CLIENT_SECRET. Do not include the double quotes when copying the value.\n",
318375
"\n",
319-
"You’re now set to test your action in Postman. Once you get a successful API response there, you can proceed with your GPT Action."
376+
"Now is a good time to [test your Snowflake integration in Postman](https://community.snowflake.com/s/article/How-to-configure-postman-for-testing-SQL-API-with-OAuth). If you copnfigured a network policy for your security integration, ensure that it includes the IP of the machine you're using to test."
320377
]
321378
},
322379
{
@@ -332,12 +389,15 @@
332389
"source": [
333390
"In ChatGPT, click on \"Authentication\" and choose \"OAuth\". Enter in the information below.\n",
334391
"\n",
335-
"* Client ID: use Client ID from steps above\n",
336-
"* Client Secret: use Client Secret from steps above\n",
337-
"* Authorization URL: use Authorization Endpoint from steps above\n",
338-
"* Token URL: use Token Endpoint from steps above\n",
339-
"* Scope: &lt;empty>*\n",
340-
"* Token: Default (POST)\n",
392+
"| Form Field | Value |\n",
393+
"| -------- | -------- |\n",
394+
"| Authentication Type | OAuth |\n",
395+
"| Client ID | OAUTH_CLIENT_ID from SHOW_OAUTH_CLIENT_SECRETS |\n",
396+
"| Authorization URL | OAUTH_AUTHORIZATION_ENDPOINT from DESCRIBE SECURITY INTEGRATION |\n",
397+
"| Token URL | OAUTH_TOKEN_ENDPOINT from DESCRIBE SECURITY INTEGRATION |\n",
398+
"| Scope | &lt;empty>* |\n",
399+
"| Token Exchange Method | Default (POST Request) |\n",
400+
"\n",
341401
"\n",
342402
"*Snowflake scopes pass the role, but you’ll notice the action itself also specifies the role as a parameter in runQuery, so the Scope is unnecessary. You may elect to pass roles in the scope instead of the action parameters if it makes more sense for your GPT."
343403
]
@@ -384,7 +444,7 @@
384444
"cell_type": "markdown",
385445
"metadata": {},
386446
"source": [
387-
"\n",
447+
"* The callback url can change if you update the YAML, double check it is correct when making changes.\n",
388448
"* _Callback URL Error:_ If you get a callback URL error in ChatGPT, pay close attention to the Post-Action Steps above. You need to add the callback URL directly into your Security Integration for the action to authenticate correctly\n",
389449
"* _Schema calls the wrong warehouse or database:_ If ChatGPT calls the wrong warehouse or database, consider updating your instructions to make it more explicit either (a) which warehouse / database should be called or (b) to require the user provide those exact details before it runs the query\n"
390450
]

0 commit comments

Comments
 (0)