Produits IA - SDK ovhai (EN)
Objective
The purpose of this document is to present the python ovhai library.
The ovhai library is a Python client that allows developers to easily use the OVHcloud AI API. With this SDK, you can run, manage, automate your notebooks, training and deployments in the cloud using OVHcloud's AI products (AI Notebooks, AI Training, AI Deploy).
Installation
To install the SDK, run the following command:
The SDK requires Python 3.8 or higher. For information about how to update your Python version, see the official Python documentation.
Getting started - Example Usage
Once you've installed the AI SDK, you can import it to use OVHcloud's AI products using the API.
You can start by the client creation:
The token used to create the client can be created via the OVHcloud Control Panel (UI), from the AI Dashboard.
Once your client is defined, you can call an endpoint:
Or do the same thing with an async version:
In the ovhai/api folder, you will find all the endpoints you can call up. They are grouped by folder according to their purpose (notebook, job, app, ...).
For example, to launch a notebook, you need to import the notebook_new file, located at /ovhai/api/notebook. You will also need to import the objects linked to this endpoint (those mentioned in the python file), since you will manipulate them (Notebook and NotebookSpec here, in addition to the classic AuthenticatedClient and Response). This will allow you to launch your first notebook using the ovhai python library, based on your specifications:
The Response object returned will contain various information, including your notebook UUID.
Things to know
Every OVHcloud's AI API endpoint has its dedicated Python module that comes with four functions:
sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successfulasyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blocking
To implement the call you want, find the folder and then the file corresponding to your needs in the api folder. Then choose the method that suits you best from the four mentioned above. Then import the objects you need to use this method.
Advanced customizations
There are more settings on the generated AuthenticatedClient class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client or httpx.AsyncClient (depending on your use-case):
For example, the previous code snippet shows how to define a custom request and response event hook using the httpx_args parameter of the AuthenticatedClient class. The httpx_args parameter is used to pass additional arguments to the underlying httpx.Client or httpx.AsyncClient. In this case, the event_hooks argument is used to specify custom functions that will be called before and after each HTTP request and response.
You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url).
Feedback
Please send us your questions, feedback and suggestions to improve the service: