Skip to main content

Provider-specific Swarmauri import package for Perplexity chat, streaming, async, batch, and citation-aware LLM workflows.

Project description

Swarmauri Logo

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

Swarmauri Perplexity LLM

swarmauri_llm_perplexity provides the provider-specific Swarmauri import package for PerplexityModel. It wraps Perplexity's chat completion API so Swarmauri applications can use the tracked sonar and r1-1776 model families through the standard Conversation workflow.

The runtime targets https://api.perplexity.ai/chat/completions, supports sync, async, streaming, and batch generation, and exposes controls such as return_citations, top_p, top_k, presence_penalty, and frequency_penalty.

Why Use This Package?

  • Keep Perplexity-specific imports explicit in Swarmauri applications.
  • Use Swarmauri Conversation objects against Perplexity's hosted chat completion API.
  • Stream Perplexity responses while preserving the same component model used across other provider packages.
  • Access Perplexity's current repo-tracked sonar and reasoning model families from a dedicated package boundary.

FAQ

What does swarmauri_llm_perplexity install?

It installs PerplexityModel under swarmauri.llms.

Which Perplexity model families are tracked?

The current runtime allowlist includes sonar-deep-research, sonar-reasoning-pro, sonar-reasoning, sonar-pro, sonar, and r1-1776.

Does the package support streaming?

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

Can it request citations?

Yes. The runtime exposes a return_citations option so the provider can include citation data when supported by the selected model.

Can I set both top_p and top_k?

No. The runtime rejects that combination and raises a ValueError.

Where should I verify current model and pricing details?

Use the Perplexity section in docs/LLM_PROVIDER_MODEL_PRICING_LINKS.md, which links to the current model cards and pricing documentation.

Features

  • PerplexityModel import package for hosted Perplexity chat completion workflows.
  • Sync, async, streaming, and batch generation support.
  • Optional citation-return behavior for supported Perplexity responses.
  • Usage metadata capture through Swarmauri UsageData when enabled.
  • Compatibility with Python 3.10, 3.11, 3.12, 3.13, and 3.14.

Installation

uv add swarmauri_llm_perplexity
pip install swarmauri_llm_perplexity

Usage

Set PPLX_API_KEY in your environment before creating the model.

Chat Completion

import os

from swarmauri_llm_perplexity import PerplexityModel
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 = PerplexityModel(
    api_key=os.environ["PPLX_API_KEY"],
    name="sonar",
)
result = model.predict(conversation=conversation, max_tokens=200)

print(result.get_last().content)

Streaming

import os

from swarmauri_llm_perplexity import PerplexityModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content="List three differences between hosted and local inference."))

model = PerplexityModel(
    api_key=os.environ["PPLX_API_KEY"],
    name="sonar-reasoning",
)

for token in model.stream(conversation=conversation, return_citations=True):
    print(token, end="", flush=True)

Async

import asyncio
import os

from swarmauri_llm_perplexity import PerplexityModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage


async def main() -> None:
    conversation = Conversation()
    conversation.add_message(HumanMessage(content="Explain retrieval-augmented generation briefly."))

    model = PerplexityModel(
        api_key=os.environ["PPLX_API_KEY"],
        name="sonar-pro",
    )
    result = await model.apredict(conversation=conversation, return_citations=True)
    print(result.get_last().content)


# asyncio.run(main())

Examples

  • Use sonar for general-purpose hosted Perplexity chat workflows.
  • Use sonar-reasoning or sonar-reasoning-pro when you want the reasoning-oriented family explicitly.
  • Use return_citations=True when the downstream experience should expose provider citations alongside the generated response.

Related Packages

Foundational Swarmauri Packages

More Documentation

Best Practices

  • Keep PPLX_API_KEY in environment variables or a secret manager.
  • Choose the Perplexity model family intentionally, especially when switching between search-style and reasoning-oriented variants.
  • Do not set both top_p and top_k in the same request.
  • Use citation-return mode only when the consuming application is prepared to surface or process citation metadata.

License

Apache-2.0

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

swarmauri_llm_perplexity-0.11.0.dev1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

File details

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

File metadata

  • Download URL: swarmauri_llm_perplexity-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 8.0 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_perplexity-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 ee0f3be006df6af288f876c00ef8c8e5e1a03383f5c54fba3ee194cd0fe4bddf
MD5 f9c76673d8f58537323e8194d948dd27
BLAKE2b-256 cf2f3bf92709242a9dbc30d9d7c8148870d9ee1cbbad285f9a1d0e216b6ba57c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_llm_perplexity-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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_perplexity-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a9d1d4b5ae1d73dedba6c8278d511e322b96c9c91e1d140d0938a513dfa7be8
MD5 648c6287c17a507244887be978a123aa
BLAKE2b-256 396ef01facba292096227cf7a344f5785220160cb7193a6e01e46017233f1fca

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