Skip to main content

Remote inference for language models

Project description

Remoteinference

Simple package to perform remote inference on language models of different providers.

Getting Started

Install the package

pip install remoteinference

To access an OpenAI model simply import the OpenAILLM and use the chat_completion endpoint to send your contents to the server endpoint. As a response you will receive a valid JSON containing the typicall OpenAI API conform response in a dictionary:

import os

from remoteinference.models import OpenAILLM
from remoteinference.util import user_prompt

model_type = 'gpt-4o-mini'
model = OpenAILLM(
    api_key=os.environ.get('OPEANI_API_KEY'),
    model=model_type
    )

response = model.chat_completion(
    prompt=[user_prompt('Who are you?')],
    temperature=0.5,
    max_tokens=50
)

print(response['choices'][0]['message']['content'])

If you have a LLM running on a remote server using llama.cpp you can initalize the model by running:

from remoteinference.models import LlamaCPPLLM
from remoteinference.util import user_prompt

# initalize the model
model = LlamaCPPLLM(
    server_address='localhost',
    server_port=8080
    )

# run simple completion
response = model.chat_completion(
    prompt=[user_prompt('Who are you?')],
    temperature=0.5,
    max_tokens=50
)

print(response['choices'][0]['message']['content'])

Supported Models

OpenAI

Initialize an OpenAI model by calling:

from remoteinference.models import OpenAILLM

model = OpenAILLM(
    api_key='your_key',
    model='gpt-4o-mini'
)

To view a full list of available models for the OpenAI endpoint see OpenAI docs

TogetherAI

Initialize an OpenAI model by calling:

from remoteinference.models import TogetherAILLM

model = TogetherAILLM(
    api_key='your_key',
    model='meta-llama/Llama-3-8b-hf'
)

To view a full list of available models for the OpenAI endpoint see TogetherAI docs

LlamaCPP

This package also provides functionality to query a self-hosted language model via llama.cpp

To initalize a model which is hosted locally just do:

from remoteinference.models import LlamaCPPLLM

model = LlamaCPPLLM(
    server_address='localhost',
    server_port=8080
)

To see the full specifications of the llama.cpp webserver see server docs.

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

remoteinference-0.0.10.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file remoteinference-0.0.10.tar.gz.

File metadata

  • Download URL: remoteinference-0.0.10.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for remoteinference-0.0.10.tar.gz
Algorithm Hash digest
SHA256 7d52f7bfb52e9f5cd2d2eeff4eb7af38eeb711bad8ac7bda35f0dbab5d73e1a8
MD5 c9a7bd99517e9b68c78c9b1b9273113e
BLAKE2b-256 1ce1cfca43eca85a1ce376a4cedd142bded3bdd88fdae3cf16ba44bea7505da3

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