Skip to main content

A Python SDK for the Infera API

Project description

InferaSDK

InferaSDK is a Python package that provides a fast, flexible, and intuitive interface for interacting with the Infera API. It aims to simplify the process of submitting jobs, processing multiple requests concurrently, and retrieving results efficiently from various language models.

Table of Contents

Main Features

Here are just a few of the things that InferaSDK does well:

  • Asynchronous API interactions for efficient processing
  • Concurrent job submission and handling
  • Easy integration with multiple language models
  • Automatic job status polling and result retrieval
  • Flexible parameter configuration for each job (e.g., max_output, temperature)
  • Timeout handling to manage long-running requests

Where to get it

The source code is currently hosted on GitHub at: https://github.com/inferanetwork/InferaSDK

Binary installers for the latest released version are available at the Python Package Index (PyPI).

Installation:

Install InferaSDK using pip:

pip install InferaSDK

For the latest development version, you can install directly from the Github repository:

Usage

Here's a quick example of how to use InferaSDK:

import asyncio
import aiohttp
from inferaSDK import InferaSDK

async def main():
    api_key = "your_api_key_here"  # Replace with your actual API key
    sdk = InferaSDK(api_key)
    
    model = "llama3.1:latest"
    messages = [{"role": "user", "content": "What is the capital of France?"}]
    max_output = 100
    temperature = 0.7

    async with aiohttp.ClientSession() as session:
        result = await sdk.process_job(session, model, messages, max_output, temperature)
        
        print("Result:")
        print(result)

if __name__ == "__main__":
    asyncio.run(main())

This code demonstrates how to use the InferaSDK to submit a job to the Infera API and retrieve the result. Let's break it down:

  1. Import statements:

    • asyncio: Used for asynchronous programming in Python.
    • aiohttp: An asynchronous HTTP client library.
    • InferaSDK: The main class from the InferaSDK package.
  2. SDK initialization:

    • Creates an instance of InferaSDK with your API key.
  3. Job parameters:

    • model: Specifies the language model to use (in this case, "llama3.1:latest").
    • messages: A list containing a single message dictionary with the user's question.
    • max_output: Limits the maximum number of tokens in the response.
    • temperature: Controls the randomness of the output (0.7 is a balanced setting).
  4. Asynchronous context manager:

    • async with aiohttp.ClientSession() as session: Creates an HTTP session for making API requests.
  5. Job processing:

    • result = await sdk.process_job(...): Submits the job to the API and waits for the result.
  6. Result output:

    • Prints the result received from the API.
  7. Script execution:

    • if __name__ == "__main__":: Ensures the script runs only when executed directly.
    • asyncio.run(main()): Runs the asynchronous main function.

This example showcases a simple, single-job submission to the Infera API using the InferaSDK, demonstrating how to interact with AI models asynchronously.

Documentation

The official documentation is hosted here.

Getting Help

You can also reach out to our support team at white@infera.org.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inferasdk-0.1.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inferasdk-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file inferasdk-0.1.2.tar.gz.

File metadata

  • Download URL: inferasdk-0.1.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for inferasdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1f0e2daefca08472137465f6084631844af98fc5fc1fcceee1cb0e704f31a791
MD5 4cb9c496ac7259f143cf3cb67f446fb8
BLAKE2b-256 b3722577ee8e6de3b2cb335301b73fa4e1bc582be638e99e70f5bfda35792857

See more details on using hashes here.

File details

Details for the file inferasdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: inferasdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for inferasdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cda0f59ed18b0d4b2f9e0c7a1a0beea4edfe18bf64636d29b1dbb694897b7678
MD5 742e1ed8f42f545db888ff336bd4398e
BLAKE2b-256 411a98ba70f95136a87194a3c766b50d7ded61c5608efc3823e4a0fbe7a4233a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page