Skip to main content

Provider-specific Swarmauri import package for Lepton AI hosted chat models, streaming workflows, and SDXL image generation.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_llm_leptonai Discord

Swarmauri LeptonAI LLM

swarmauri_llm_leptonai provides provider-specific Swarmauri imports for Lepton AI hosted chat models and SDXL image generation. The package exposes LeptonAIModel for synchronous, asynchronous, streaming, and batch text generation workflows, plus LeptonAIImgGenModel for prompt-to-image generation against Lepton-hosted image endpoints.

The runtime uses model-specific Lepton endpoints in the form https://<model>.lepton.run/api/v1/ for chat and https://sdxl.lepton.run/run for image generation. That keeps Lepton-specific configuration isolated in one provider package while preserving the shared Swarmauri Conversation and component model.

Why Use This Package?

  • Keep Lepton AI imports explicit in Swarmauri applications instead of importing provider implementations from broader runtime packages.
  • Run hosted chat models with sync, async, streaming, and batch interfaces that align with Swarmauri LLM conventions.
  • Generate images with a Swarmauri image generation component instead of managing raw HTTP calls directly.
  • Reuse shared Swarmauri message, conversation, and serialization behavior while keeping provider credentials and model names local to the Lepton package.

FAQ

What does swarmauri_llm_leptonai install?

It installs two provider entry points: LeptonAIModel under swarmauri.llms and LeptonAIImgGenModel under swarmauri.image_gens.

Which Lepton AI capabilities are wrapped today?

The package currently wraps hosted chat completion style inference for the allowlisted text models in LeptonAIModel and SDXL image generation through LeptonAIImgGenModel.

Does LeptonAIModel support streaming and async workflows?

Yes. LeptonAIModel supports predict, apredict, stream, astream, batch, and abatch.

How does model selection work?

LeptonAIModel builds its base URL from the configured name, so changing name="llama3-8b" to another allowlisted model switches the Lepton endpoint without changing the rest of the application code.

Does the image generator support batch workflows?

Yes. LeptonAIImgGenModel supports generate_image, agenerate_image, batch_generate, and abatch_generate.

Where should I verify current provider model availability and pricing?

Lepton's public model and pricing documentation is limited compared with other providers. Use the provider-facing surfaces in the Lepton dashboard and review docs/LLM_PROVIDER_MODEL_PRICING_LINKS.md for the current project-level documentation links before publishing model or pricing claims.

Features

  • LeptonAIModel for provider-hosted chat generation with sync, async, streaming, and batch execution.
  • Usage metadata capture on text responses through Swarmauri UsageData.
  • LeptonAIImgGenModel for prompt-to-image generation against Lepton-hosted SDXL endpoints.
  • Endpoint selection derived from the configured model name for text generation workflows.
  • Compatibility with Python 3.10, 3.11, 3.12, 3.13, and 3.14.

Installation

uv add swarmauri_llm_leptonai
pip install swarmauri_llm_leptonai

Usage

Set LEPTON_API_KEY in your environment before creating either component.

Chat Completion

import os

from swarmauri_llm_leptonai import LeptonAIModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content="Summarize Swarmauri in two sentences."))

model = LeptonAIModel(
    api_key=os.environ["LEPTON_API_KEY"],
    name="llama3-8b",
)
result = model.predict(conversation=conversation)

print(result.get_last().content)
print(result.get_last().usage.total_tokens)

Async and Streaming

import asyncio
import os

from swarmauri_llm_leptonai import LeptonAIModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage


async def ask_async(prompt: str) -> None:
    conversation = Conversation()
    conversation.add_message(HumanMessage(content=prompt))

    model = LeptonAIModel(
        api_key=os.environ["LEPTON_API_KEY"],
        name="mixtral-8x7b",
    )
    result = await model.apredict(conversation=conversation)
    print(result.get_last().content)


def stream_text(prompt: str) -> None:
    conversation = Conversation()
    conversation.add_message(HumanMessage(content=prompt))

    model = LeptonAIModel(api_key=os.environ["LEPTON_API_KEY"])
    for token in model.stream(conversation=conversation):
        print(token, end="", flush=True)


# asyncio.run(ask_async("Draft a short release note."))
# stream_text("Write a haiku about composable AI systems.")

Image Generation

import os
from pathlib import Path

from swarmauri_llm_leptonai import LeptonAIImgGenModel

image_model = LeptonAIImgGenModel(
    api_key=os.environ["LEPTON_API_KEY"],
    model_name="sdxl",
)

image_bytes = image_model.generate_image(
    prompt="A cyberpunk skyline at blue hour in watercolor style",
    width=768,
    height=512,
)

output = Path("leptonai_cyberpunk.png")
image_model.save_image(image_bytes, output.as_posix())

Examples

  • Use LeptonAIModel for provider-hosted chat inference when you want Swarmauri Conversation objects and token usage data.
  • Use LeptonAIImgGenModel when an agent or application needs image generation without adding a separate provider package.
  • Use stream or astream for latency-sensitive user interfaces that render tokens incrementally.

Related Packages

Foundational Swarmauri Packages

More Documentation

Best Practices

  • Keep LEPTON_API_KEY in environment variables or a secret manager.
  • Validate current provider model availability before deploying a specific allowlisted model to production.
  • Tune width, height, steps, and guidance_scale carefully for image generation to balance quality, latency, and cost.
  • Consume full streaming responses before reading usage metadata from the final conversation message.

License

Apache-2.0

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

swarmauri_llm_leptonai-0.11.0.dev1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

swarmauri_llm_leptonai-0.11.0.dev1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_llm_leptonai-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_llm_leptonai-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_llm_leptonai-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 4d064dd9d7c779dad7b7d038485ded69a4fee56467271475cea62da2a47984e6
MD5 8c908bbd5af1b1bc5b2dcf9159d8be2a
BLAKE2b-256 a3c100deec153ff686ae728727ef8e4ec804065da89a129962bc6118902a22c9

See more details on using hashes here.

File details

Details for the file swarmauri_llm_leptonai-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_llm_leptonai-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_llm_leptonai-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 63ae065e0e810e560d9cef5f0a0e7dd1cb69983b3c7b24ce34ba0907630068fd
MD5 b415781116db42e301cd9329d8bfd984
BLAKE2b-256 ca92529f0bada6d4eefc05f4f88ba870af6785fab834093794866ac908bd4e4c

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