Swarmauri LLM LeptonAI
Integration package for calling Lepton AI's hosted language and image generation models from Swarmauri agents. Ships LLM and image-gen adapters with synchronous, streaming, and asynchronous workflows that match Swarmauri conventions.
Features
- Chat completion support for Lepton AI models (e.g.,
llama3-8b,mixtral-8x7b) with automatic usage tracking. - Streaming and async token generation for latency-sensitive experiences.
- SDXL-based image generation with convenience helpers to save or display returned bytes.
- Single configuration surface for model name, base URL, and API key; reuse the same credential for both text and image endpoints.
Prerequisites
- Python 3.10 or newer.
- A Lepton AI API key stored outside source control (environment variables or secret stores recommended).
- Network access to
*.lepton.runendpoints; theopenaiPython client is installed automatically as a dependency.
Installation
# pip
pip install swarmauri_llm_leptonai
# poetry
poetry add swarmauri_llm_leptonai
# uv (pyproject-based projects)
uv add swarmauri_llm_leptonai
Quickstart: Chat Completions
import os
from swarmauri_llm_leptonai import LeptonAIModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage
api_key = os.environ["LEPTON_API_KEY"]
conversation = Conversation()
conversation.add_message(HumanMessage(content="Summarize Swarmauri in two sentences."))
model = LeptonAIModel(api_key=api_key, name="llama3-8b")
response = model.predict(conversation=conversation)
print(response.get_last().content)
print("Tokens used", response.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:
convo = Conversation()
convo.add_message(HumanMessage(content=prompt))
model = LeptonAIModel(api_key=os.environ["LEPTON_API_KEY"], name="mixtral-8x7b")
result = await model.apredict(conversation=convo)
print(result.get_last().content)
def stream_story(prompt: str) -> None:
convo = Conversation()
convo.add_message(HumanMessage(content=prompt))
model = LeptonAIModel(api_key=os.environ["LEPTON_API_KEY"])
for token in model.stream(conversation=convo):
print(token, end="", flush=True)
# asyncio.run(ask_async("Draft a product announcement."))
# stream_story("Write a haiku about distributed agents.")
Generate Images with SDXL
import os
from pathlib import Path
from swarmauri_llm_leptonai import LeptonAIImgGenModel
img_model = LeptonAIImgGenModel(api_key=os.environ["LEPTON_API_KEY"], model_name="sdxl")
prompt = "A cyberpunk skyline at blue hour in watercolor style"
image_bytes = img_model.generate_image(prompt=prompt, width=768, height=512)
output = Path("leptonai_cyberpunk.png")
img_model.save_image(image_bytes, output.as_posix())
# Display in a notebook or desktop environment
# img_model.display_image(image_bytes)
Operational Tips
- Models are invoked via
https://<model>.lepton.run/api/v1/; updatingnameonLeptonAIModelswitches endpoints without altering the client setup. - Streaming responses emit usage data at stream completion; consume the generator fully before inspecting
conversation.get_last().usage. - Respect Lepton AI rate limits—add retries with exponential backoff or queue requests during traffic spikes.
- Store API keys securely and rotate them regularly; avoid hard-coding credentials in notebooks or scripts.
- Large image generations may take longer and consume more credits; adjust
width,height,steps, andguidance_scaleto balance quality versus latency.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Metadata
Release files for swarmauri_llm_leptonai 0.9.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_llm_leptonai-0.9.3.tar.gz | 10.2 kB | Without provenance | Details for swarmauri_llm_leptonai-0.9.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_llm_leptonai-0.9.3-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_llm_leptonai-0.9.3-py3-none-any.whl |
Total release size: 21.8 kB
Release files / swarmauri_llm_leptonai-0.9.3.tar.gz
| Download URL | swarmauri_llm_leptonai-0.9.3.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
650c311b3629fba9be23533d5c6af0203293f104d9602eeefcd04e8b2857347f
|
|
BLAKE2b-256 checksum How to use checksums |
45346cc0c2b5239ab278a0f4781e4c3d9faa1b9dbe8ba089ad31e2fa2e46772a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","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}
|
Release files / swarmauri_llm_leptonai-0.9.3-py3-none-any.whl
| Download URL | swarmauri_llm_leptonai-0.9.3-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de6f1149d04d1a0895a5c938f0ace8dbab69540e695834d1cfd29bdc4372d07b
|
|
BLAKE2b-256 checksum How to use checksums |
cb018c4d07372e8e703e84625367af0849c0d9cf7af10d7b80f0274ce5a089fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","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}
|
Security for swarmauri_llm_leptonai 0.9.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.