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:
-
Import statements:
asyncio: Used for asynchronous programming in Python.aiohttp: An asynchronous HTTP client library.InferaSDK: The main class from the InferaSDK package.
-
async def main(): Defines the main asynchronous function. -
SDK initialization:
- Creates an instance of
InferaSDKwith your API key.
- Creates an instance of
-
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).
-
Asynchronous context manager:
async with aiohttp.ClientSession() as session: Creates an HTTP session for making API requests.
-
Job processing:
result = await sdk.process_job(...): Submits the job to the API and waits for the result.
-
Result output:
- Prints the result received from the API.
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inferasdk-0.1.1.tar.gz.
File metadata
- Download URL: inferasdk-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bfbc23218981ec4b28228a4f536f41e231231ee95108b7200095dab42628f58
|
|
| MD5 |
00fa737b5033bbe41d9719c98bf96d0d
|
|
| BLAKE2b-256 |
816a52618a24609fc758b7f87969fd070b4cfa8938c5713c84dfe2aac0feb301
|
File details
Details for the file inferasdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: inferasdk-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67f62dabf44635d3309693ef98d6dd376dd76081629b1a533e07db0fb412d865
|
|
| MD5 |
3699d482e7387a806b4f1dd6eff80a91
|
|
| BLAKE2b-256 |
9fae1758ba438248520897649e743053b8620bb95c20cbc8a75f981d762ab062
|