|
142 | 142 | "\n",
|
143 | 143 | "### OpenAPI Schema\n",
|
144 | 144 | "\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." |
146 | 146 | ]
|
147 | 147 | },
|
148 | 148 | {
|
|
161 | 161 | " version: 1.0.0\n",
|
162 | 162 | " description: API for executing statements in Snowflake with specific warehouse and role settings.\n",
|
163 | 163 | "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", |
165 | 165 | "\n",
|
166 | 166 | "\n",
|
167 | 167 | "paths:\n",
|
|
238 | 238 | "cell_type": "markdown",
|
239 | 239 | "metadata": {},
|
240 | 240 | "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');" |
242 | 279 | ]
|
243 | 280 | },
|
244 | 281 | {
|
245 | 282 | "cell_type": "markdown",
|
246 | 283 | "metadata": {},
|
247 | 284 | "source": [
|
| 285 | + "### 2. Set up the Securit Integration\n", |
248 | 286 | "* 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" |
251 | 288 | ]
|
252 | 289 | },
|
253 | 290 | {
|
|
267 | 304 | " OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'\n",
|
268 | 305 | " 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",
|
269 | 306 | " 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" |
271 | 309 | ]
|
272 | 310 | },
|
273 | 311 | {
|
|
312 | 350 | "metadata": {},
|
313 | 351 | "source": [
|
314 | 352 | "\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": [ |
316 | 373 | "\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", |
318 | 375 | "\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." |
320 | 377 | ]
|
321 | 378 | },
|
322 | 379 | {
|
|
332 | 389 | "source": [
|
333 | 390 | "In ChatGPT, click on \"Authentication\" and choose \"OAuth\". Enter in the information below.\n",
|
334 | 391 | "\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: <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 | <empty>* |\n", |
| 399 | + "| Token Exchange Method | Default (POST Request) |\n", |
| 400 | + "\n", |
341 | 401 | "\n",
|
342 | 402 | "*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."
|
343 | 403 | ]
|
|
384 | 444 | "cell_type": "markdown",
|
385 | 445 | "metadata": {},
|
386 | 446 | "source": [
|
387 |
| - "\n", |
| 447 | + "* The callback url can change if you update the YAML, double check it is correct when making changes.\n", |
388 | 448 | "* _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",
|
389 | 449 | "* _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"
|
390 | 450 | ]
|
|
0 commit comments