-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add inference doc code examples (#2488)
* Add inference examples * switching from `model_id` to `inference_id` as per discussion.
- Loading branch information
1 parent
b9aa69e
commit 135c60a
Showing
16 changed files
with
146 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// health/health.asciidoc:470 | ||
// health/health.asciidoc:478 | ||
|
||
[source, python] | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// health/health.asciidoc:463 | ||
// health/health.asciidoc:471 | ||
|
||
[source, python] | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// health/health.asciidoc:455 | ||
// health/health.asciidoc:463 | ||
|
||
[source, python] | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters