Skip to content

Commit 83621bc

Browse files
authored
chore(examples): Use new field and make examples consistent (#61)
1 parent 3e6f0cc commit 83621bc

File tree

3 files changed

+84
-33
lines changed

3 files changed

+84
-33
lines changed

examples/feature_distributions_demo.ipynb

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,80 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Feature distributions from income classifier demo\n",
8+
"\n",
9+
"You'll need to have setup the pipeline for the income classifier and done some requests."
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"## API Configuration"
17+
]
18+
},
319
{
420
"cell_type": "code",
521
"execution_count": 3,
622
"metadata": {},
723
"outputs": [],
824
"source": [
925
"from seldon_deploy_sdk.rest import ApiException\n",
10-
"\n",
11-
"from seldon_deploy_sdk import MonitorApi,DeploymentFeatureData, Configuration, ApiClient\n",
26+
"from seldon_deploy_sdk import (\n",
27+
" MonitorApi,\n",
28+
" DeploymentFeatureData,\n",
29+
" Configuration,\n",
30+
" ApiClient,\n",
31+
")\n",
1232
"from seldon_deploy_sdk.auth import OIDCAuthenticator"
1333
]
1434
},
1535
{
1636
"cell_type": "code",
1737
"execution_count": 4,
1838
"metadata": {},
19-
"outputs": [
20-
{
21-
"name": "stderr",
22-
"output_type": "stream",
23-
"text": [
24-
"DEPRECATED!! Future versions of seldon_deploy_sdk will ignore the access_token field. Use the id_token field instead.\n"
25-
]
26-
}
27-
],
39+
"outputs": [],
2840
"source": [
29-
"INGRESS = \"http://localhost:8000\"\n",
41+
"# For local testing use\n",
42+
"INGRESS = \"http://localhost:8080\"\n",
3043
"\n",
44+
"# For production usecase set this to your ingress\n",
45+
"# for example if your SD URL is http://xxx.yyy.zzz.xyz/seldon-deploy/api/v1alpha1 set\n",
46+
"# INGRESS = \"http://xxx.yyy.zzz.xyz\""
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
3155
"config = Configuration()\n",
32-
"config.host = f\"{INGRESS}/seldon-deploy/api/v1alpha1\"\n",
33-
"config.verify_ssl = False\n",
56+
"config.host = f\"{INGRESS}/seldon-deploy/api/v1alpha1\""
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 7,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"# auth if needed\n",
3466
"config.oidc_server = f\"{INGRESS}/auth/realms/deploy-realm\"\n",
3567
"config.oidc_client_id = \"sd-api\"\n",
3668
"config.oidc_client_secret = \"sd-api-secret\"\n",
3769
"config.auth_method = \"client_credentials\"\n",
70+
"\n",
71+
"# Alternativey set instead of the \"client_credentials\" flow\n",
72+
"# config.username = \"admin@seldon.io\"\n",
73+
"# config.password = \"12341234\"\n",
74+
"# config.auth_method = \"password\"\n",
75+
"\n",
3876
"auth = OIDCAuthenticator(config)\n",
39-
"config.access_token = auth.authenticate()\n"
77+
"config.id_token = auth.authenticate()"
4078
]
4179
},
4280
{
@@ -49,24 +87,33 @@
4987
"api_instance = MonitorApi(api_client)"
5088
]
5189
},
90+
{
91+
"cell_type": "markdown",
92+
"metadata": {},
93+
"source": [
94+
"## Request feature distributions"
95+
]
96+
},
5297
{
5398
"cell_type": "code",
5499
"execution_count": 6,
55100
"metadata": {},
56101
"outputs": [],
57102
"source": [
58-
"deployment_name=\"income-classifier\"\n",
59-
"deployment_namespace=\"seldon\"\n",
103+
"deployment_name = \"income-classifier\"\n",
104+
"deployment_namespace = \"seldon\"\n",
60105
"feature_data = DeploymentFeatureData(\n",
61106
" feature=\"Education\",\n",
62107
" interaction=\"request\",\n",
63108
" aggregate_over_time=True,\n",
64109
" deployment_endpoint=\"default\",\n",
65-
" deployment_node=\"income-classifier-container\"\n",
110+
" deployment_node=\"income-classifier-container\",\n",
66111
")\n",
67112
"try:\n",
68113
" # Get feature distributions\n",
69-
" api_response = api_instance.seldon_deployment_feature_distributions(deployment_name,deployment_namespace,feature_data)\n",
114+
" api_response = api_instance.seldon_deployment_feature_distributions(\n",
115+
" deployment_name, deployment_namespace, feature_data\n",
116+
" )\n",
70117
"except ApiException as e:\n",
71118
" print(f\"Couldn't fetch distributions: {e}\")"
72119
]
@@ -102,9 +149,10 @@
102149
],
103150
"source": [
104151
"import matplotlib.pyplot as plt\n",
152+
"\n",
105153
"fig = plt.figure()\n",
106-
"ax = fig.add_axes([0,0,1,1])\n",
107-
"ax.bar(groups,counts)\n",
154+
"ax = fig.add_axes([0, 0, 1, 1])\n",
155+
"ax.bar(groups, counts)\n",
108156
"plt.show()"
109157
]
110158
}

examples/metadata_demo.ipynb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"cell_type": "markdown",
2424
"metadata": {},
2525
"source": [
26-
"## Api Configuration"
26+
"## API Configuration"
2727
]
2828
},
2929
{
@@ -33,7 +33,6 @@
3333
"outputs": [],
3434
"source": [
3535
"from seldon_deploy_sdk.rest import ApiException\n",
36-
"\n",
3736
"from seldon_deploy_sdk import V1Model, ModelMetadataServiceApi, Configuration, ApiClient\n",
3837
"from seldon_deploy_sdk.auth import OIDCAuthenticator"
3938
]
@@ -90,7 +89,7 @@
9089
"# config.auth_method = \"password\"\n",
9190
"\n",
9291
"auth = OIDCAuthenticator(config)\n",
93-
"config.access_token = auth.authenticate()"
92+
"config.id_token = auth.authenticate()"
9493
]
9594
},
9695
{
@@ -324,7 +323,9 @@
324323
"\n",
325324
"try:\n",
326325
" # List Model Metadata entries.\n",
327-
" api_response = api_instance.model_metadata_service_list_model_metadata(name=\"beta\", tags={\"author\": \"Jon\"})\n",
326+
" api_response = api_instance.model_metadata_service_list_model_metadata(\n",
327+
" name=\"beta\", tags={\"author\": \"Jon\"}\n",
328+
" )\n",
328329
" print(\"Filter by name=beta\")\n",
329330
" pprint(api_response)\n",
330331
"except ApiException as e:\n",
@@ -382,7 +383,9 @@
382383
"\n",
383384
"try:\n",
384385
" # List Model Metadata entries.\n",
385-
" api_response = api_instance.model_metadata_service_list_model_metadata(tags={\"author\": \"Bob\"})\n",
386+
" api_response = api_instance.model_metadata_service_list_model_metadata(\n",
387+
" tags={\"author\": \"Bob\"}\n",
388+
" )\n",
386389
" print(\"Filter by name=beta\")\n",
387390
" pprint(api_response)\n",
388391
"except ApiException as e:\n",
@@ -438,7 +441,9 @@
438441
"source": [
439442
"try:\n",
440443
" # Get Model Metadata entries.\n",
441-
" api_response = api_instance.model_metadata_service_list_model_metadata(uri=\"gs://test-model-alpha-v1.0.0\")\n",
444+
" api_response = api_instance.model_metadata_service_list_model_metadata(\n",
445+
" uri=\"gs://test-model-alpha-v1.0.0\"\n",
446+
" )\n",
442447
" print(\"Before update:\")\n",
443448
" pprint(api_response)\n",
444449
"except ApiException as e:\n",
@@ -464,7 +469,7 @@
464469
" pprint(api_response)\n",
465470
"except ApiException as e:\n",
466471
" print(f\"Failed to call API: {json.loads(e.body)['message']}\")\n",
467-
" \n",
472+
"\n",
468473
"try:\n",
469474
" # List Model Metadata entries.\n",
470475
" api_response = api_instance.model_metadata_service_list_model_metadata(\n",
@@ -542,8 +547,7 @@
542547
"try:\n",
543548
" # List Runtime Metadata for all deployments associated with a model.\n",
544549
" api_response = api_instance.model_metadata_service_list_runtime_metadata_for_model(\n",
545-
" model_uri=\"gs://seldon-models/sklearn/iris\", \n",
546-
" deployment_status=\"Running\"\n",
550+
" model_uri=\"gs://seldon-models/sklearn/iris\", deployment_status=\"Running\"\n",
547551
" )\n",
548552
" pprint(api_response)\n",
549553
"except ApiException as e:\n",
@@ -595,8 +599,7 @@
595599
"try:\n",
596600
" # List Runtime Metadata for all deployments associated with a model.\n",
597601
" api_response = api_instance.model_metadata_service_list_runtime_metadata_for_model(\n",
598-
" deployment_name=\"iris\", \n",
599-
" deployment_namespace=\"seldon\"\n",
602+
" deployment_name=\"iris\", deployment_namespace=\"seldon\"\n",
600603
" )\n",
601604
" pprint(api_response)\n",
602605
"except ApiException as e:\n",

examples/token-refresh-password-grant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def call_env():
3232

3333
auth = OIDCAuthenticator(config)
3434

35-
config.access_token = auth.authenticate()
35+
config.id_token = auth.authenticate()
3636

3737
print(config.access_token)
3838

0 commit comments

Comments
 (0)