Lepton AI Platform

0.27.0 · active · verified Wed Apr 15

The LeptonAI Python library is a framework designed to simplify AI service building, enabling developers to convert research and modeling code into production-ready services with minimal Python. It provides abstractions for launching models from platforms like HuggingFace, includes AI-tailored features such as autobatching and background jobs, and offers a Python client for interacting with deployed services as native functions. The library also comes with a command-line interface (`lep`) for local and cloud service management. Currently at version 0.27.0, it maintains an active development and release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to interact with a locally running Lepton AI service (a "Photon") using the Python client. First, you typically launch a model (e.g., a HuggingFace GPT-2 model) using the `lep` CLI tool (`lep photon runlocal --name gpt2 --model hf:gpt2`). Then, the Python client can connect to this local service to send inputs and receive outputs. For remote deployments, an API token and deployment details would be required.

import os
from leptonai.client import Client, local

# NOTE: This example assumes you have run 'lep photon runlocal --name gpt2 --model hf:gpt2' in your terminal.
# It also requires the Lepton AI CLI to be installed and potentially HuggingFace credentials
# if you're using models that require them (set HUGGING_FACE_HUB_TOKEN env var).

# Initialize client for local service running on port 8080
c = Client(local(port=8080))

# Check available paths (endpoints) of the deployed service
print(f"Available paths: {c.paths()}")

# Call the 'run' method of the gpt2 model
response = c.run(inputs="I enjoy walking with my cute dog, and")
print(f"Model response: {response}")

# Example of using a remote client (replace with your actual workspace/token/deployment)
# from leptonai.client import Client
# LEPTIN_API_TOKEN = os.environ.get('LEPTON_API_TOKEN', 'YOUR_LEPTON_API_TOKEN')
# # If you have a specific workspace_id and deployment_id
# # remote_client = Client(f"workspace_id", "deployment_id", token=LEPTIN_API_TOKEN)
# # Or if using a direct URL:
# # remote_client = Client("https://your-deployment-url.lepton.run/api", token=LEPTIN_API_TOKEN)
# # response = remote_client.run(inputs="What is Lepton AI?")
# # print(f"Remote model response: {response}")

view raw JSON →