Skip to content

Commit

Permalink
Add inference doc code examples (#2488)
Browse files Browse the repository at this point in the history
* Add inference examples

* switching from `model_id` to `inference_id`
 as per discussion.
  • Loading branch information
iuliaferoli authored Mar 26, 2024
1 parent b9aa69e commit 135c60a
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 6 deletions.
18 changes: 18 additions & 0 deletions docs/examples/00fea15cbca83be9d5f1a024ff2ec708.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// inference/put-inference.asciidoc:276

[source, python]
----
resp = client.inference.put_model(
task_type="text_embedding",
inference_id="my-e5-model",
body={
"service": "elasticsearch",
"service_settings": {
"num_allocations": 1,
"num_threads": 1,
"model_id": ".multilingual-e5-small",
},
},
)
print(resp)
----
18 changes: 18 additions & 0 deletions docs/examples/10c3fe2265bb34964bd1005f9da66773.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// inference/put-inference.asciidoc:371

[source, python]
----
resp = client.inference.put_model(
task_type="text_embedding",
inference_id="my-msmarco-minilm-model",
body={
"service": "elasticsearch",
"service_settings": {
"num_allocations": 1,
"num_threads": 1,
"model_id": "msmarco-MiniLM-L12-cos-v5",
},
},
)
print(resp)
----
13 changes: 13 additions & 0 deletions docs/examples/13ecdf99114098c76b050397d9c3d4e6.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// inference/post-inference.asciidoc:72

[source, python]
----
resp = client.inference.inference(
task_type="sparse_embedding",
inference_id="my-elser-model",
body={
"input": "The sky above the port was the color of television tuned to a dead channel."
},
)
print(resp)
----
2 changes: 1 addition & 1 deletion docs/examples/3541d4a85e27b2c3896a7a7ee98b4b37.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// health/health.asciidoc:470
// health/health.asciidoc:478

[source, python]
----
Expand Down
20 changes: 20 additions & 0 deletions docs/examples/46884e00674f82e7a7bc8b418d1777de.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// inference/put-inference.asciidoc:252

[source, python]
----
resp = client.inference.put_model(
task_type="text_embedding",
inference_id="cohere_embeddings",
body={
"service": "cohere",
"service_settings": {
"api_key": "api_key",
"model_id": "embed-english-v3.0",
"embedding_type": "int8",
},
"task_settings": {},
},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/4e3414fc712b16311f9e433dd366f49d.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// inference/delete-inference.asciidoc:51

[source, python]
----
resp = client.inference.delete_model(
task_type="sparse_embedding",
inference_id="my-elser-model",
)
print(resp)
----
15 changes: 15 additions & 0 deletions docs/examples/4ea91a3ff42de540bb4c9ef268d607a6.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// inference/put-inference.asciidoc:301

[source, python]
----
resp = client.inference.put_model(
task_type="sparse_embedding",
inference_id="my-elser-model",
body={
"service": "elser",
"service_settings": {"num_allocations": 1, "num_threads": 1},
"task_settings": {},
},
)
print(resp)
----
2 changes: 1 addition & 1 deletion docs/examples/73be1f93d789264e5b972ddb5991bc66.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// setup/logging-config.asciidoc:156
// setup/logging-config.asciidoc:158

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/87733deeea4b441b595d19a0f97346f0.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// health/health.asciidoc:463
// health/health.asciidoc:471

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/8e286a205a1f84f888a6d99f2620c80e.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// setup/logging-config.asciidoc:233
// setup/logging-config.asciidoc:235

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/9d79645ab3a9da3f63c54a1516214a5a.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// health/health.asciidoc:455
// health/health.asciidoc:463

[source, python]
----
Expand Down
10 changes: 10 additions & 0 deletions docs/examples/a4a3c3cd09efa75168dab90105afb2e9.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// inference/get-inference.asciidoc:68

[source, python]
----
resp = client.inference.get_model(
task_type="sparse_embedding",
inference_id="my-elser-model",
)
print(resp)
----
2 changes: 1 addition & 1 deletion docs/examples/b7a9f60b3646efe3834ca8381f8aa560.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// setup/logging-config.asciidoc:169
// setup/logging-config.asciidoc:171

[source, python]
----
Expand Down
15 changes: 15 additions & 0 deletions docs/examples/c0f4cbcb104747f38acdbc9a30bd13bf.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// inference/put-inference.asciidoc:396

[source, python]
----
resp = client.inference.put_model(
task_type="text_embedding",
inference_id="my_openai_embedding_model",
body={
"service": "openai",
"service_settings": {"api_key": "api_key"},
"task_settings": {"model": "text-embedding-ada-002"},
},
)
print(resp)
----
17 changes: 17 additions & 0 deletions docs/examples/eee6110831c08b9c1b3f56b24656e95b.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// inference/put-inference.asciidoc:341

[source, python]
----
resp = client.inference.put_model(
task_type="text_embedding",
inference_id="hugging-face-embeddings",
body={
"service": "hugging_face",
"service_settings": {
"api_key": "<access_token>",
"url": "<url_endpoint>",
},
},
)
print(resp)
----
4 changes: 4 additions & 0 deletions utils/generate-examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
"cluster/update-settings.asciidoc",
"health/health.asciidoc",
"cluster/reroute.asciidoc",
"inference/get-inference.asciidoc",
"inference/delete-inference.asciidoc",
"inference/post-inference.asciidoc",
"inference/put-inference.asciidoc",
]


Expand Down

0 comments on commit 135c60a

Please sign in to comment.