A client library for accessing ♾️ Infinity - Embedding Inference Server
Maintained. Last release 3 weeks ago, commits in 6 of the last 26 weeks. Weaker on contributor spread.
pip install infinity-clientinfinity_client
Requires Python 3.11 or newer. A client library for accessing ♾️ Infinity - Embedding Inference Server
Installation
pip install infinity_client
Usage
First, create a client:
from infinity_client import Client
i_client = Client(base_url="https://infinity.modal.michaelfeil.eu")
If the endpoints you're going to hit require authentication, use AuthenticatedClient instead:
from infinity_client import AuthenticatedClient
i_client = AuthenticatedClient(base_url="https://infinity.modal.michaelfeil.eu", token="SuperSecretToken")
Now call your endpoint and use your models:
from infinity_client.models import OpenAIModelInfo
from infinity_client.api.default import models, health
from infinity_client.types import Response
with i_client as client:
model_info: OpenAIModelInfo = models.sync(client=client)
# or if you need more info (e.g. status_code)
response: Response[OpenAIModelInfo] = models.sync_detailed(client=client)
Or use the POST methods:
from infinity_client.models import OpenAIEmbeddingInputText, OpenAIEmbeddingResult
from infinity_client.api.default import classify, embeddings, embeddings_image, rerank
from infinity_client.types import Response
with i_client as client:
embeds: OpenAIEmbeddingResult = embeddings.sync(client=client, body=OpenAIEmbeddingInputText.from_dict({
"input": ["Hello, this is a sentence-to-embed", "Hello, my cat is cute"],
"model": "michaelfeil/bge-small-en-v1.5",
}))
Or do the same thing with an async version:
from infinity_client.models import OpenAIModelInfo
from infinity_client.api.default import models
from infinity_client.types import Response
async with i_client as client:
model_info: OpenAIModelInfo = await models.asyncio(client=client)
response: Response[OpenAIModelInfo] = await models.asyncio_detailed(client=client)
By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
i_client = AuthenticatedClient(
base_url="https://internal_api.example.com",
token="SuperSecretToken",
verify_ssl="/path/to/certificate_bundle.pem",
)
You can also disable certificate validation altogether, but beware that .