Skip to content

Commit 006b613

Browse files
iuliaferoligithub-actions[bot]
authored andcommitted
Add inference doc code examples (#2488)
* Add inference examples * switching from `model_id` to `inference_id` as per discussion. (cherry picked from commit 135c60a)
1 parent d8ed032 commit 006b613

16 files changed

+146
-6
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// inference/put-inference.asciidoc:276
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="my-e5-model",
8+
body={
9+
"service": "elasticsearch",
10+
"service_settings": {
11+
"num_allocations": 1,
12+
"num_threads": 1,
13+
"model_id": ".multilingual-e5-small",
14+
},
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// inference/put-inference.asciidoc:371
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="my-msmarco-minilm-model",
8+
body={
9+
"service": "elasticsearch",
10+
"service_settings": {
11+
"num_allocations": 1,
12+
"num_threads": 1,
13+
"model_id": "msmarco-MiniLM-L12-cos-v5",
14+
},
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// inference/post-inference.asciidoc:72
2+
3+
[source, python]
4+
----
5+
resp = client.inference.inference(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
body={
9+
"input": "The sky above the port was the color of television tuned to a dead channel."
10+
},
11+
)
12+
print(resp)
13+
----

docs/examples/3541d4a85e27b2c3896a7a7ee98b4b37.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// health/health.asciidoc:470
1+
// health/health.asciidoc:478
22

33
[source, python]
44
----
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// inference/put-inference.asciidoc:252
2+
3+
[source, python]
4+
----
5+
6+
resp = client.inference.put_model(
7+
task_type="text_embedding",
8+
inference_id="cohere_embeddings",
9+
body={
10+
"service": "cohere",
11+
"service_settings": {
12+
"api_key": "api_key",
13+
"model_id": "embed-english-v3.0",
14+
"embedding_type": "int8",
15+
},
16+
"task_settings": {},
17+
},
18+
)
19+
print(resp)
20+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// inference/delete-inference.asciidoc:51
2+
3+
[source, python]
4+
----
5+
resp = client.inference.delete_model(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
)
9+
print(resp)
10+
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// inference/put-inference.asciidoc:301
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
body={
9+
"service": "elser",
10+
"service_settings": {"num_allocations": 1, "num_threads": 1},
11+
"task_settings": {},
12+
},
13+
)
14+
print(resp)
15+
----

docs/examples/73be1f93d789264e5b972ddb5991bc66.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// setup/logging-config.asciidoc:156
1+
// setup/logging-config.asciidoc:158
22

33
[source, python]
44
----

docs/examples/87733deeea4b441b595d19a0f97346f0.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// health/health.asciidoc:463
1+
// health/health.asciidoc:471
22

33
[source, python]
44
----

docs/examples/8e286a205a1f84f888a6d99f2620c80e.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// setup/logging-config.asciidoc:233
1+
// setup/logging-config.asciidoc:235
22

33
[source, python]
44
----

docs/examples/9d79645ab3a9da3f63c54a1516214a5a.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// health/health.asciidoc:455
1+
// health/health.asciidoc:463
22

33
[source, python]
44
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// inference/get-inference.asciidoc:68
2+
3+
[source, python]
4+
----
5+
resp = client.inference.get_model(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
)
9+
print(resp)
10+
----

docs/examples/b7a9f60b3646efe3834ca8381f8aa560.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// setup/logging-config.asciidoc:169
1+
// setup/logging-config.asciidoc:171
22

33
[source, python]
44
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// inference/put-inference.asciidoc:396
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="my_openai_embedding_model",
8+
body={
9+
"service": "openai",
10+
"service_settings": {"api_key": "api_key"},
11+
"task_settings": {"model": "text-embedding-ada-002"},
12+
},
13+
)
14+
print(resp)
15+
----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// inference/put-inference.asciidoc:341
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="hugging-face-embeddings",
8+
body={
9+
"service": "hugging_face",
10+
"service_settings": {
11+
"api_key": "<access_token>",
12+
"url": "<url_endpoint>",
13+
},
14+
},
15+
)
16+
print(resp)
17+
----

utils/generate-examples.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106
"cluster/update-settings.asciidoc",
107107
"health/health.asciidoc",
108108
"cluster/reroute.asciidoc",
109+
"inference/get-inference.asciidoc",
110+
"inference/delete-inference.asciidoc",
111+
"inference/post-inference.asciidoc",
112+
"inference/put-inference.asciidoc",
109113
]
110114

111115

0 commit comments

Comments
 (0)