Upload Config per Context Class via REST API
While users can upload a complete config via REST or the dashboard, some users might need to update only a specific context class without changing or overriding the other classes.
For this, users can now leverage Mona's /upload_config_for_context_class REST API endpoint and upload a config only for the desired context class.
To access Mona's API, first, an accessToken must be generated and added to the request.
Once users have their accessToken they can add it to their authorization and send a POST request with the following mandatory params:
- "author"- name or email of user.
- "commit_message" - message about changes made for future reference .
- "context_class" - the name of class being updated.
- "config" - the configuration of the specific context class. The expected format is the context class configuration object, as shown in the example.
curl --location --request POST 'https://api{YOUR-USER-ID}.monalabs.io/upload_config_for_context_class' \
--header 'Authorization: Bearer YOUR-ACCESS-TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"commit_message": "updated context class LOAN_APPLICATION_TUTORIAL ",
"author": "user name or email",
"context_class": "LOAN_APPLICATION_TUTORIAL",
"config": {
"fields": {
"occupation": {
"type": "string",
"function": "identity",
"args": [],
"tags": [
"metadata"
]
},
"city": {
"type": "string",
"function": "concat_strings",
"args": [
"_"
],
"sources": [
{
"names": [
"state"
],
"default_value": null
},
{
"names": [
"city"
],
"default_value": null
}
]
},
"state": {
"type": "string"
},
"purpose": {
"type": "string"
},
"credit_score": {
"type": "numeric",
"function": "identity",
"args": [],
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.02
}
}
},
"loan_taken": {
"type": "boolean"
},
"return_until": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1000000
}
}
},
"offered_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"approved_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"feature_0": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 60000
}
}
},
"feature_1": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.4
}
}
},
"feature_2": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 30
}
}
},
"feature_3": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 6000
}
}
},
"feature_4": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.01
}
}
},
"feature_5": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.2
}
}
},
"feature_6": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"feature_7": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1
}
}
},
"feature_8": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 50
}
}
},
"feature_9": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"stage": {
"type": "string"
},
"model_version": {
"type": "string"
},
"label": {
"type": "boolean",
"function": "identity",
"args": []
},
"credit_label_delta": {
"type": "numeric",
"function": "delta",
"args": [
null
],
"sources": [
{
"names": [
"label"
]
},
{
"names": [
"credit_score"
]
}
],
"segmentations": {
"gvrew": {
"discrete": true,
"default": true
}
}
},
"risk_lable_delta_abs": {
"type": "numeric",
"function": "abs_value",
"args": [],
"sources": [
{
"names": [
"credit_label_delta"
]
}
],
"segmentations": {
"vewve": {
"discrete": true,
"default": true
}
}
},
"offered_approved_delta": {
"type": "numeric",
"function": "delta",
"args": [
null
],
"sources": [
{
"names": [
"offered_amount"
]
},
{
"names": [
"approved_amount"
]
}
],
"segmentations": {
"verwvwev": {
"discrete": true,
"default": true
}
}
},
"offered_approved_delta_normalized": {
"type": "numeric",
"function": "divide",
"args": [],
"sources": [
{
"names": [
"offered_approved_delta"
]
},
{
"names": [
"offered_amount"
]
}
],
"segmentations": {
"vewvw": {
"bucket_size": 0.05,
"bucket_offset": 0,
"default": true
}
}
},
"city_in_state": {
"type": "string",
"function": "concat_strings",
"args": [
"_"
],
"sources": [
{
"names": [
"city"
],
"default_value": null
},
{
"names": [
"state"
],
"default_value": null
}
]
}
},
"stanzas": {
"general": {
"description": "",
"verses": [
{
"type": "AverageDrift",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
{
"name": "occupation",
"avoid_values": [
"doctor"
]
}
],
"min_anomaly_level": 0.25,
"trend_directions": [
"desc"
],
"min_segment_size": 500
},
{
"type": "AverageOutlier",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
"city"
],
"min_anomaly_level": 0.65,
"min_segment_size": 50
}
]
}
}
}
}'
import requests
url = "https://api{YOUR-USER-ID}.monalabs.io/upload_config_for_context_class"
payload={
"commit_message": "updated context class LOAN_APPLICATION_TUTORIAL ",
"author": "user name or email",
"context_class": "LOAN_APPLICATION_TUTORIAL",
"config": {
"fields": {
"occupation": {
"type": "string",
"function": "identity",
"args": [],
"tags": [
"metadata"
]
},
"city": {
"type": "string",
"function": "concat_strings",
"args": [
"_"
],
"sources": [
{
"names": [
"state"
],
"default_value": null
},
{
"names": [
"city"
],
"default_value": null
}
]
},
"state": {
"type": "string"
},
"purpose": {
"type": "string"
},
"credit_score": {
"type": "numeric",
"function": "identity",
"args": [],
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.02
}
}
},
"loan_taken": {
"type": "boolean"
},
"return_until": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1000000
}
}
},
"offered_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"approved_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"feature_0": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 60000
}
}
},
"feature_1": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.4
}
}
},
"feature_2": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 30
}
}
},
"feature_3": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 6000
}
}
},
"feature_4": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.01
}
}
},
"feature_5": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.2
}
}
},
"feature_6": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"feature_7": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1
}
}
},
"feature_8": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 50
}
}
},
"feature_9": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"stage": {
"type": "string"
},
"model_version": {
"type": "string"
},
"label": {
"type": "boolean",
"function": "identity",
"args": []
},
"credit_label_delta": {
"type": "numeric",
"function": "delta",
"args": [
null
],
"sources": [
{
"names": [
"label"
]
},
{
"names": [
"credit_score"
]
}
],
"segmentations": {
"gvrew": {
"discrete": true,
"default": true
}
}
},
"risk_lable_delta_abs": {
"type": "numeric",
"function": "abs_value",
"args": [],
"sources": [
{
"names": [
"credit_label_delta"
]
}
],
"segmentations": {
"vewve": {
"discrete": true,
"default": true
}
}
},
"offered_approved_delta": {
"type": "numeric",
"function": "delta",
"args": [
null
],
"sources": [
{
"names": [
"offered_amount"
]
},
{
"names": [
"approved_amount"
]
}
],
"segmentations": {
"verwvwev": {
"discrete": true,
"default": true
}
}
},
"offered_approved_delta_normalized": {
"type": "numeric",
"function": "divide",
"args": [],
"sources": [
{
"names": [
"offered_approved_delta"
]
},
{
"names": [
"offered_amount"
]
}
],
"segmentations": {
"vewvw": {
"bucket_size": 0.05,
"bucket_offset": 0,
"default": true
}
}
},
"city_in_state": {
"type": "string",
"function": "concat_strings",
"args": [
"_"
],
"sources": [
{
"names": [
"city"
],
"default_value": null
},
{
"names": [
"state"
],
"default_value": null
}
]
}
},
"stanzas": {
"general": {
"description": "",
"verses": [
{
"type": "AverageDrift",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
{
"name": "occupation",
"avoid_values": [
"doctor"
]
}
],
"min_anomaly_level": 0.25,
"trend_directions": [
"desc"
],
"min_segment_size": 500
},
{
"type": "AverageOutlier",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
"city"
],
"min_anomaly_level": 0.65,
"min_segment_size": 50
}
]
}
}
}
}
headers = {
'Authorization': 'Bearer YOUR-ACCESS-TOKEN',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)
from mona_sdk.client import Client
api_key = <YOUR-API-KEY>
secret = <YOUR-SECRET>
my_mona_client = Client(api_key, secret)
my_mona_client.upload_config_per_context_class(
author="YOUR-USER-EMAIL",
commit_message="updated context class LOAN_APPLICATION_TUTORIAL",
context_class="LOAN_APPLICATION_TUTORIAL",
config={
"fields": {
"occupation": {
"type": "string",
"function": "identity",
"args": [],
"tags": [
"metadata"
]
},
"state": {
"type": "string"
},
"purpose": {
"type": "string"
},
"credit_score": {
"type": "numeric",
"function": "identity",
"args": [],
"segmentations": {
"original": {
"default": True,
"bucket_size": 0.02
}
}
},
},
"stanzas": {
"general": {
"description": "",
"verses": [
{
"type": "AverageDrift",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
{
"name": "occupation",
"avoid_values": [
"doctor"
]
}
],
"min_anomaly_level": 0.25,
"trend_directions": [
"desc"
],
"min_segment_size": 500
},
]
}
}
}
)
The response will be the complete new config with the updated context class and the unchanged ones. Also, a verses_diff to show the changes made to the verses.
{
"response_data": {
"new_config_id": "76d959db-5637-4294-9510-489148fa0f90",
"new_config": {
"OTHER_CLASS": {
"fields": {}
},
"LOAN_APPLICATION_TUTORIAL": {
"fields": {
"occupation": {
"type": "string",
"function": "identity",
"args": [],
"tags": [
"metadata"
],
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"city": {
"type": "string",
"function": "concat_strings",
"args": [
"_"
],
"sources": [
{
"names": [
"state"
],
"default_value": null
},
{
"names": [
"city"
],
"default_value": null
}
],
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"state": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"purpose": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"credit_score": {
"type": "numeric",
"function": "identity",
"args": [],
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.02
}
}
},
"loan_taken": {
"type": "boolean",
"segmentations": {
"default": {
"default": true,
"type": "boolean",
"zero_values": [
false,
0
],
"one_values": [
true,
1
],
"zero_name": "False",
"one_name": "True"
}
}
},
"return_until": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1000000
}
}
},
"offered_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"approved_amount": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 700
}
}
},
"feature_0": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 60000
}
}
},
"feature_1": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.4
}
}
},
"feature_2": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 30
}
}
},
"feature_3": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 6000
}
}
},
"feature_4": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.01
}
}
},
"feature_5": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.2
}
}
},
"feature_6": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"feature_7": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1
}
}
},
"feature_8": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 50
}
}
},
"feature_9": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 20
}
}
},
"stage": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"model_version": {
"type": "string",
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
},
"label": {
"type": "boolean",
"function": "identity",
"args": [],
"segmentations": {
"default": {
"default": true,
"type": "boolean",
"zero_values": [
false,
0
],
"one_values": [
true,
1
],
"zero_name": "False",
"one_name": "True"
}
}
},
"credit_label_delta": {
"type": "numeric",
"function": "delta",
"args": [
null
],
"sources": [
{
"names": [
"label"
]
},
{
"names": [
"credit_score"
]
}
],
"segmentations": {
"gvrew": {
"discrete": true,
"default": true
}
}
},
"risk_lable_delta_abs": {
"type": "numeric",
"function": "abs_value",
"args": [],
"sources": [
{
"names": [
"credit_label_delta"
]
}
],
"segmentations": {
"vewve": {
"discrete": true,
"default": true
}
}
},
"offered_approved_delta": {
"type": "numeric",
"function": "delta",
"args": [
null
],
"sources": [
{
"names": [
"offered_amount"
]
},
{
"names": [
"approved_amount"
]
}
],
"segmentations": {
"verwvwev": {
"discrete": true,
"default": true
}
}
},
"offered_approved_delta_normalized": {
"type": "numeric",
"function": "divide",
"args": [],
"sources": [
{
"names": [
"offered_approved_delta"
]
},
{
"names": [
"offered_amount"
]
}
],
"segmentations": {
"vewvw": {
"bucket_size": 0.05,
"bucket_offset": 0,
"default": true
}
}
},
"city_in_state": {
"type": "string",
"function": "concat_strings",
"args": [
"_"
],
"sources": [
{
"names": [
"city"
],
"default_value": null
},
{
"names": [
"state"
],
"default_value": null
}
],
"segmentations": {
"default": {
"default": true,
"type": "string"
}
}
}
},
"stanzas": {
"general": {
"description": "",
"verses": [
{
"type": "AverageDrift",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
{
"name": "occupation",
"avoid_values": [
"doctor"
]
}
],
"min_anomaly_level": 0.25,
"trend_directions": [
"desc"
],
"min_segment_size": 500
},
{
"type": "AverageOutlier",
"metrics": [
"credit_score",
"offered_amount",
"approved_amount",
"credit_label_delta",
"offered_approved_delta_normalized"
],
"segment_by": [
"occupation",
"purpose",
"stage",
"model_version",
"city"
],
"min_anomaly_level": 0.65,
"min_segment_size": 50
}
]
}
},
"kapis": [
"credit_score",
"loan_taken",
"return_until",
"offered_amount",
"approved_amount",
"feature_0",
"feature_1",
"feature_2",
"feature_3",
"feature_4",
"feature_5",
"feature_6",
"feature_7",
"feature_8",
"feature_9",
"label",
"credit_label_delta",
"risk_lable_delta_abs",
"offered_approved_delta",
"offered_approved_delta_normalized"
]
}
},
"verses_diff": [
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__SumDrift",
"diff": "Removed"
},
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__AverageSuddenChange",
"diff": "Removed"
},
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__AverageDriftAcrossVersions",
"diff": "Removed"
},
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__SegmentSizeOutlier",
"diff": "Removed"
},
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__SegmentSizeSuddenChange",
"diff": "Removed"
},
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__SegmentSizeDrift",
"diff": "Removed"
},
{
"arc_class": "LOAN_APPLICATION_TUTORIAL",
"stanza_name": "general",
"verse_name": "general__AverageThreshold",
"diff": "Removed"
}
]
},
"partial_data": false
}
Updated 25 days ago