|
| 1 | +Stardog Cloud |
| 2 | +############### |
| 3 | + |
| 4 | +The :obj:`stardog.cloud` subpackage provides clients for accessing Stardog Cloud services, such as `Stardog Voicebox <https://stardog.ai/>`_. |
| 5 | + |
| 6 | +.. list-table:: Clients |
| 7 | + :widths: 50 50 |
| 8 | + :header-rows: 1 |
| 9 | + |
| 10 | + * - Class |
| 11 | + - Description |
| 12 | + * - :class:`stardog.cloud.client.Client` |
| 13 | + - Ideal for simple blocking operations in traditional Python applications. |
| 14 | + * - :class:`stardog.cloud.client.AsyncClient` |
| 15 | + - Suitable for async programming models, such as ``asyncio``. |
| 16 | + |
| 17 | +Voicebox Integration |
| 18 | +************************ |
| 19 | + |
| 20 | +Access Stardog's Voicebox capabilities through an instance of :class:`stardog.cloud.voicebox.VoiceboxApp` class. |
| 21 | + |
| 22 | +.. note:: |
| 23 | + The :class:`stardog.cloud.voicebox.VoiceboxApp` provides both synchronous and asynchronous methods, offering the same functionality. Asynchronous methods are prefixed with `async_` and return coroutines that can be awaited, while synchronous methods return objects directly. For example, :obj:`stardog.cloud.voicebox.VoiceboxApp.async_ask` returns a coroutine, while :obj:`stardog.cloud.voicebox.VoiceboxApp.ask` returns a :class:`stardog.cloud.voicebox.VoiceboxAnswer`. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +Synchronous usage |
| 28 | +======================== |
| 29 | + |
| 30 | +.. code-block:: python |
| 31 | +
|
| 32 | + from stardog.cloud.client import Client |
| 33 | +
|
| 34 | + with Client() as client: |
| 35 | + app = client.voicebox_app(app_api_token="your-token", client_id="your-client-id") |
| 36 | + response = app.ask(question="Your question here") |
| 37 | +
|
| 38 | +Asynchronous usage |
| 39 | +======================== |
| 40 | + |
| 41 | + |
| 42 | +.. code-block:: python |
| 43 | +
|
| 44 | + from stardog.cloud.client import AsyncClient |
| 45 | +
|
| 46 | + async with AsyncClient() as client: |
| 47 | + app = client.voicebox_app(app_api_token="your-token", client_id="your-client-id") |
| 48 | + response = await app.async_ask(question="Your question here") |
| 49 | +
|
| 50 | +
|
| 51 | +Error Handling |
| 52 | +======================== |
| 53 | + |
| 54 | +The package raises custom exceptions defined in the :obj:`stardog.cloud.exceptions` module. These exceptions can be caught when interacting with the Stardog Cloud clients. |
| 55 | + |
| 56 | +All clients raise exceptions if needed, with :class:`stardog.cloud.exceptions.StardogCloudException` serving as the base exception for any error raised. |
| 57 | + |
| 58 | +.. code-block:: python |
| 59 | +
|
| 60 | + from stardog.cloud.exceptions import ( |
| 61 | + StardogCloudException, |
| 62 | + RateLimitExceededException |
| 63 | + ) |
| 64 | +
|
| 65 | + try: |
| 66 | + with Client() as client: |
| 67 | + app = client.voicebox_app(app_api_token="your-token", client_id="your-client-id") |
| 68 | + response = app.ask(question="Your question") |
| 69 | + except RateLimitExceededException as e: |
| 70 | + print(f"Rate limit exceeded: {e}") |
| 71 | + except StardogCloudException as e: |
| 72 | + print(f"Error occurred: {e}") |
| 73 | +
|
| 74 | +
|
| 75 | +
|
| 76 | +API Reference |
| 77 | +********************* |
| 78 | + |
| 79 | +stardog.cloud.client |
| 80 | +============================ |
| 81 | + |
| 82 | +.. automodule:: stardog.cloud.client |
| 83 | + :members: |
| 84 | + :undoc-members: |
| 85 | + :show-inheritance: |
| 86 | + :special-members: __init__ |
| 87 | + |
| 88 | +stardog.cloud.voicebox |
| 89 | +============================ |
| 90 | + |
| 91 | +.. automodule:: stardog.cloud.voicebox |
| 92 | + :members: |
| 93 | + :undoc-members: |
| 94 | + :show-inheritance: |
| 95 | + :special-members: __init__ |
| 96 | + |
| 97 | +stardog.cloud.exceptions |
| 98 | +============================ |
| 99 | + |
| 100 | +.. automodule:: stardog.cloud.exceptions |
| 101 | + :members: |
| 102 | + :undoc-members: |
| 103 | + :show-inheritance: |
| 104 | + :special-members: __init__ |
| 105 | + |
0 commit comments