-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make OMIClient async. This change is made to support running both as a Python script as well as in a Jupyter notebook. Since Jupyter uses IPython as the runtime, we cannot use the `asyncio` methods to try and run async functions outside of a larger event loop. This change adds a tiny bit of complexity to using the OMIClient but it should be familiar to anyone who's used async/await in Python. * Updated docs with new async OMIClient.
- Loading branch information
Showing
7 changed files
with
121 additions
and
119 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
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
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
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,14 +1,21 @@ | ||
import asyncio | ||
from chassis.client import OMIClient | ||
from chassis.guides import DigitsSampleData | ||
|
||
# Instantiate OMI Client connection to model running on localhost:45000 | ||
with OMIClient("localhost", 45000) as client: | ||
# Call and view results of status RPC | ||
status = client.status() | ||
print(f"Status: {status}") | ||
# Submit inference with quickstart sample data | ||
res = client.run(DigitsSampleData) | ||
# Parse results from output item | ||
result = res.outputs[0].output["results.json"] | ||
# View results | ||
print(f"Result: {result}") | ||
|
||
async def run_test(): | ||
# Instantiate OMI Client connection to model running on localhost:45000 | ||
async with OMIClient("localhost", 45000) as client: | ||
# Call and view results of status RPC | ||
status = await client.status() | ||
print(f"Status: {status}") | ||
# Submit inference with quickstart sample data | ||
res = await client.run(DigitsSampleData) | ||
# Parse results from output item | ||
result = res.outputs[0].output["results.json"] | ||
# View results | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(run_test()) |
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,9 +1,16 @@ | ||
import asyncio | ||
from chassis.client import OMIClient | ||
from chassis.guides import DigitsSampleData | ||
|
||
# Execute the test_container method to spin up the container, run inference, and return the results | ||
res = OMIClient.test_container(container_name="my-first-chassis-model", inputs=DigitsSampleData, pull=False) | ||
# Parse results from output item | ||
result = res.outputs[0].output["results.json"] | ||
# View results | ||
print(f"Result: {result}") | ||
|
||
async def run_test(): | ||
# Execute the test_container method to spin up the container, run inference, and return the results | ||
res = await OMIClient.test_container(container_name="my-first-chassis-model", inputs=DigitsSampleData, pull=False) | ||
# Parse results from output item | ||
result = res.outputs[0].output["results.json"] | ||
# View results | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(run_test()) |
Oops, something went wrong.