|
| 1 | +AI Quick Actions HTTP Client |
| 2 | +**************************** |
| 3 | + |
| 4 | +.. versionadded:: 2.13.0 |
| 5 | + |
| 6 | +The AI Quick Actions client is a centralized, reusable component for interacting with the OCI Model Deployment service. |
| 7 | + |
| 8 | +**Implementation Highlights:** |
| 9 | + |
| 10 | +- Offers both synchronous (Client) and asynchronous (AsyncClient) |
| 11 | +- Integrates with OCI Authentication patterns |
| 12 | + |
| 13 | +Authentication |
| 14 | +============== |
| 15 | + |
| 16 | +The AI Quick Actions client supports the same authentication methods as other OCI services, including API Key, session token, instance principal, and resource principal. For additional details, please refer to the `authentication guide <https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html>`_. Ensure you have the necessary `access policies <https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-policies-auth.htm>`_ to connect to the OCI Data Science Model Deployment endpoint. |
| 17 | + |
| 18 | +Usage |
| 19 | +===== |
| 20 | + |
| 21 | +Sync Usage |
| 22 | +---------- |
| 23 | + |
| 24 | +**Text Completion** |
| 25 | + |
| 26 | +.. code-block:: python3 |
| 27 | +
|
| 28 | + from ads.aqua import Client |
| 29 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 30 | +
|
| 31 | + client = Client(endpoint="https://<MD_OCID>/predict") |
| 32 | + response = client.generate( |
| 33 | + prompt="Tell me a joke", |
| 34 | + payload={"model": "odsc-llm"}, |
| 35 | + stream=False, |
| 36 | + ) |
| 37 | + print(response) |
| 38 | +
|
| 39 | +**Chat Completion** |
| 40 | + |
| 41 | +.. code-block:: python3 |
| 42 | +
|
| 43 | + from ads.aqua import Client |
| 44 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 45 | +
|
| 46 | + client = Client(endpoint="https://<MD_OCID>/predict") |
| 47 | + response = client.chat( |
| 48 | + messages=[{"role": "user", "content": "Tell me a joke."}], |
| 49 | + payload={"model": "odsc-llm"}, |
| 50 | + stream=False, |
| 51 | + ) |
| 52 | + print(response) |
| 53 | +
|
| 54 | +**Streaming** |
| 55 | + |
| 56 | +.. code-block:: python3 |
| 57 | +
|
| 58 | + from ads.aqua import Client |
| 59 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 60 | +
|
| 61 | + client = Client(endpoint="https://<MD_OCID>/predict") |
| 62 | + response = client.chat( |
| 63 | + messages=[{"role": "user", "content": "Tell me a joke."}], |
| 64 | + payload={"model": "odsc-llm"}, |
| 65 | + stream=True, |
| 66 | + ) |
| 67 | +
|
| 68 | + for chunk in response: |
| 69 | + print(chunk) |
| 70 | +
|
| 71 | +**Embedding** |
| 72 | + |
| 73 | +.. code-block:: python3 |
| 74 | +
|
| 75 | + from ads.aqua import Client |
| 76 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 77 | +
|
| 78 | + client = Client(endpoint="https://<MD_OCID>/predict") |
| 79 | + response = client.embeddings( |
| 80 | + input=["one", "two"] |
| 81 | + ) |
| 82 | + print(response) |
| 83 | +
|
| 84 | +
|
| 85 | +Async Usage |
| 86 | +----------- |
| 87 | + |
| 88 | +The following examples demonstrate how to perform the same operations using the asynchronous client with Python's async/await syntax. |
| 89 | + |
| 90 | +**Text Completion** |
| 91 | + |
| 92 | +.. code-block:: python3 |
| 93 | +
|
| 94 | + from ads.aqua import AsyncClient |
| 95 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 96 | +
|
| 97 | + client = AsyncClient(endpoint="https://<MD_OCID>/predict") |
| 98 | + response = await client.generate( |
| 99 | + prompt="Tell me a joke", |
| 100 | + payload={"model": "odsc-llm"}, |
| 101 | + stream=False, |
| 102 | + ) |
| 103 | + print(response) |
| 104 | +
|
| 105 | +**Streaming** |
| 106 | + |
| 107 | +.. code-block:: python3 |
| 108 | +
|
| 109 | + from ads.aqua import AsyncClient |
| 110 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 111 | +
|
| 112 | + client = AsyncClient(endpoint="https://<MD_OCID>/predict") |
| 113 | + async for chunk in await client.generate( |
| 114 | + prompt="Tell me a joke", |
| 115 | + payload={"model": "odsc-llm"}, |
| 116 | + stream=True, |
| 117 | + ): |
| 118 | + print(chunk) |
| 119 | +
|
| 120 | +**Embedding** |
| 121 | + |
| 122 | +.. code-block:: python3 |
| 123 | +
|
| 124 | + from ads.aqua import AsyncClient |
| 125 | + ads.set_auth(auth="security_token", profile="<replace-with-your-profile>") |
| 126 | +
|
| 127 | + client = AsyncClient(endpoint="https://<MD_OCID>/predict") |
| 128 | + response = await client.embeddings( |
| 129 | + input=["one", "two"] |
| 130 | + ) |
| 131 | + print(response) |
0 commit comments