Provider-specific Swarmauri import package for Lepton AI hosted chat models, streaming workflows, and SDXL image generation.
Project description
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
LeptonAIModelfor provider-hosted chat generation with sync, async, streaming, and batch execution.- Usage metadata capture on text responses through Swarmauri
UsageData. LeptonAIImgGenModelfor 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
LeptonAIModelfor provider-hosted chat inference when you want SwarmauriConversationobjects and token usage data. - Use
LeptonAIImgGenModelwhen an agent or application needs image generation without adding a separate provider package. - Use
streamorastreamfor latency-sensitive user interfaces that render tokens incrementally.
Related Packages
- swarmauri_llm_openai
- swarmauri_llm_mistral
- swarmauri_llm_deepinfra
- swarmauri_llm_hyperbolic
- swarmauri_llm_falai
- swarmauri_llm_groq
Foundational Swarmauri Packages
More Documentation
Best Practices
- Keep
LEPTON_API_KEYin environment variables or a secret manager. - Validate current provider model availability before deploying a specific allowlisted model to production.
- Tune
width,height,steps, andguidance_scalecarefully 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d064dd9d7c779dad7b7d038485ded69a4fee56467271475cea62da2a47984e6
|
|
| MD5 |
8c908bbd5af1b1bc5b2dcf9159d8be2a
|
|
| BLAKE2b-256 |
a3c100deec153ff686ae728727ef8e4ec804065da89a129962bc6118902a22c9
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63ae065e0e810e560d9cef5f0a0e7dd1cb69983b3c7b24ce34ba0907630068fd
|
|
| MD5 |
b415781116db42e301cd9329d8bfd984
|
|
| BLAKE2b-256 |
ca92529f0bada6d4eefc05f4f88ba870af6785fab834093794866ac908bd4e4c
|