-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
54 lines (46 loc) · 1.4 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
logging.basicConfig(
format="%(asctime)s : %(levelname)s : %(threadName)-10s : %(name)s : %(message)s", level=logging.INFO,
)
logger = logging.getLogger(__name__)
from requests import post
from cortex_serving_client.cortex_client import get_cortex_client_instance
# Instantiate Cortex Client
cortex = get_cortex_client_instance(
cortex_env='cortex-serving-client-test',
pg_user='cortex_test',
pg_password='cortex_test',
pg_db='cortex_test',
)
# Deployment config
deployment = {
"name": "dummy-a",
"project_name": "test",
"predictor_path": "dummy_predictor",
"kind": "RealtimeAPI",
"pod": {
"containers": [
{
"config": {"geo": "cz", "model_name": "CoolModel", "version": "000000-000000"},
"env": {
"SECRET_ENV_VAR": "secret",
},
"compute": {"cpu": '200m', "mem": f"{0.1}Gi"},
}
],
},
"autoscaling": {
},
}
# Deploy
with cortex.deploy_temporarily(
deployment,
deploy_dir="dummy_dir",
api_timeout_sec=30 * 60,
verbose=True,
) as get_result:
# Predict
response = post(get_result.endpoint, json={"question": "Do you love ML?"}).json()
# Print the response
logger.info(f"API Response: {response}")
# assert result['yes']