Skip to content

Commit 8a19bb9

Browse files
Add Python ML examples to the API docs (#2489)
Co-authored-by: Quentin Pradet <[email protected]>
1 parent 8a97cc1 commit 8a19bb9

21 files changed

+256
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ml/trained-models/apis/infer-trained-model.asciidoc:1043
2+
3+
[source, python]
4+
----
5+
resp = client.ml.infer_trained_model(
6+
model_id="cross-encoder__ms-marco-tinybert-l-2-v2",
7+
body={
8+
"docs": [
9+
{
10+
"text_field": "Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."
11+
},
12+
{
13+
"text_field": "New York City is famous for the Metropolitan Museum of Art."
14+
},
15+
],
16+
"inference_config": {
17+
"text_similarity": {"text": "How many people live in Berlin?"}
18+
},
19+
},
20+
)
21+
print(resp)
22+
----
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ml/trained-models/apis/start-trained-model-deployment.asciidoc:173
2+
3+
[source, python]
4+
----
5+
resp = client.ml.start_trained_model_deployment(
6+
model_id="my_model",
7+
deployment_id="my_model_for_ingest",
8+
wait_for="started",
9+
timeout="1m",
10+
)
11+
print(resp)
12+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ml/trained-models/apis/put-trained-models-aliases.asciidoc:82
2+
3+
[source, python]
4+
----
5+
resp = client.ml.put_trained_model_alias(
6+
model_id="flight-delay-prediction-1574775339910",
7+
model_alias="flight_delay_model",
8+
)
9+
print(resp)
10+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ml/trained-models/apis/put-trained-model-vocabulary.asciidoc:63
2+
3+
[source, python]
4+
----
5+
resp = client.ml.put_trained_model_vocabulary(
6+
model_id="elastic__distilbert-base-uncased-finetuned-conll03-english",
7+
body={"vocabulary": ["[PAD]", "[unused0]", ...]},
8+
)
9+
print(resp)
10+
----
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ml/trained-models/apis/infer-trained-model.asciidoc:849
2+
3+
[source, python]
4+
----
5+
resp = client.ml.infer_trained_model(
6+
model_id="lang_ident_model_1",
7+
body={
8+
"docs": [
9+
{
10+
"text": "The fool doth think he is wise, but the wise man knows himself to be a fool."
11+
}
12+
]
13+
},
14+
)
15+
print(resp)
16+
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ml/trained-models/apis/infer-trained-model.asciidoc:1008
2+
3+
[source, python]
4+
----
5+
resp = client.ml.infer_trained_model(
6+
model_id="model2",
7+
body={
8+
"docs": [{"text_field": "<long text to extract answer>"}],
9+
"inference_config": {
10+
"question_answering": {"question": "<question to be answered>"}
11+
},
12+
},
13+
)
14+
print(resp)
15+
----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ml/trained-models/apis/get-trained-models.asciidoc:1460
2+
3+
[source, python]
4+
----
5+
resp = client.ml.get_trained_models()
6+
print(resp)
7+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ml/trained-models/apis/start-trained-model-deployment.asciidoc:181
2+
3+
[source, python]
4+
----
5+
resp = client.ml.start_trained_model_deployment(
6+
model_id="my_model",
7+
deployment_id="my_model_for_search",
8+
)
9+
print(resp)
10+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ml/trained-models/apis/infer-trained-model.asciidoc:880
2+
3+
[source, python]
4+
----
5+
resp = client.ml.infer_trained_model(
6+
model_id="model2",
7+
body={"docs": [{"text_field": "The movie was awesome!!"}]},
8+
)
9+
print(resp)
10+
----
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ml/trained-models/apis/clear-trained-model-deployment-cache.asciidoc:43
2+
3+
[source, python]
4+
----
5+
resp = client.ml.clear_trained_model_deployment_cache(
6+
model_id="elastic__distilbert-base-uncased-finetuned-conll03-english",
7+
)
8+
print(resp)
9+
----

0 commit comments

Comments
 (0)