Skip to content

A wrapper around Hugging Face's Inference API (written in Python)

License

Notifications You must be signed in to change notification settings

kabir-asani/intellecto-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

intellecto-python

A wrapper around Hugging Face's Inference API (written in Python)

Usage

from intellecto import Intellecto

client = Intellecto(
    access_token="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)

response = client.nlp.generate(
    model="microsoft/phi-2",
    input='Top 10 programming languages in the world.'
)

Exposed APIs

Intellecto

Intellecto has the following properties --

property description
nlp A property of type IntellectoNLP that deals with various NLP related tasks
audio A property of type IntellectoAudio that deals with various audio related tasks
vision A property of type IntellectoVision that deals with various vision related tasks

Code Structure

IntellectoBase

IntellectoBase spawns and holds onto a IntellectoClient which aids it in sending network requests to Inference API end points.

It receives the following parameters -

parameter description
model A <model-id> as specified on HF's model page
token A <bearer-token> as extracted from HF's console

IntellectoBase is extended by the classes mentioned below. They're divided & grouped as per their niche and tasks.

  1. IntellectoNLP

  2. IntellectoAudio

  3. IntellectoVision

Handling Errors

When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of IntellectoAPIError is raised.

When the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of IntellectoAPIStatusError is raised, containing status_code.

Error codes are as followed:

Status Code Error Type
400 BadRequestError
401 AuthenticationError
403 PermissionDeniedError
404 NotFoundError
422 UnprocessableEntityError
429 RateLimitError
5xx InternalServerError
N/A APIConnectionError

intellecto-python async WIP

A wrapper around Hugging Face's Inference API (written in Python) with async support

Usage

from asyncio import run
from intellecto import AsyncIntellecto

client = AsyncIntellecto(
    access_token="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)

async def main() -> None:
    response = await client.nlp.client.nlp.generate(
        model="microsoft/phi-2",
        input='Top 10 programming languages in the world.'
    )

run(main())

Exposed APIs

AsyncIntellecto

AsyncIntellecto has the following properties --

property description
nlp A property of type AsyncIntellectoNLP that deals with various NLP related tasks
audio A property of type AsyncIntellectoAudio that deals with various audio related tasks
vision A property of type AsyncIntellectoVision that deals with various vision related tasks

Code Structure

AsyncIntellectoBase

AsyncIntellectoBase spawns and holds onto an AsyncIntellectoClient which aids it in sending network requests to Inference API end points.

It receives the following parameters -

parameter description
model A <model-id> as specified on HF's model page
token A <bearer-token> as extracted from HF's console

AsyncIntellectoBase is extended by the classes mentioned below. They're divided & grouped as per their niche and tasks.

  1. AsyncIntellectoNLP

  2. AsyncIntellectoAudio

  3. AsyncIntellectoVision

About

A wrapper around Hugging Face's Inference API (written in Python)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages