HTTP Client#

Danger

The aiohttp-based BaseClient has been deprecated in v1.0.0 and will be removed in a future version. We recommend using httpx to make HTTP requests instead.

We have removed the top-level library dependency on aiohttp - existing code using the BaseClient will require manual installation of the aiohttp package.

If your language model backend exposes an HTTP API, you can create a subclass of BaseClient to interface with it. Your engine should then create an instance of the new HTTP client and call it to make predictions.

Minimally, to use the HTTP client, your subclass should set the SERVICE_BASE class variable.

class kani.engines.httpclient.BaseClient(http: ClientSession | None = None)[source]

aiohttp-based HTTP client to help implement HTTP-based engines.

Deprecated since version 1.0.0: We recommend using httpx.AsyncClient instead. This aiohttp-based client will be removed in a future version.

Parameters:

http – The aiohttp.ClientSession to use; if not provided, creates a new session.

SERVICE_BASE: str

The base route of the HTTP API.

async request(method: str, route: str, **kwargs) ClientResponse[source]

Makes an HTTP request to the given route (relative to the base route).

Parameters:
  • method – The HTTP method to use (e.g. ‘GET’, ‘POST’).

  • route – The route to make the request to (relative to the SERVICE_BASE).

Raises:
async get(route: str, **kwargs)[source]

Convenience method; equivalent to self.request("GET", route, **kwargs).json().

async post(route: str, **kwargs)[source]

Convenience method; equivalent to self.request("POST", route, **kwargs).json().

async close()[source]

Close the underlying aiohttp session.