Skip to main content

Provider-specific Swarmauri import package for DeepInfra OpenAI-compatible chat completions with sync, async, streaming, batch, and JSON workflows.

Project description

Swarmauri Logo

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

Swarmauri DeepInfra LLM

swarmauri_llm_deepinfra provides the DeepInfraModel import path for Swarmauri applications that use DeepInfra's OpenAI-compatible chat completions API. The package re-exports the maintained implementation from swarmauri_standard, giving projects a provider-specific dependency for hosted open-source LLM inference through Swarmauri conversations.

Why Swarmauri DeepInfra LLM?

Use this package when you want DeepInfra-hosted models behind the Swarmauri LLMBase interface. DeepInfraModel formats Swarmauri messages for OpenAI-compatible chat completions, supports sync and async prediction, streams response chunks, runs sequential and concurrent batches, supports stop sequences, and can request JSON-object responses on compatible models.

FAQ

Q: Which DeepInfra endpoint does this adapter call?

A: The adapter uses https://api.deepinfra.com/v1/openai/chat/completions, DeepInfra's OpenAI-compatible chat completions endpoint.

Q: Which model names are configured locally?

A: The local allowed-model list includes models such as Qwen/Qwen2-72B-Instruct, Qwen/Qwen2.5-72B-Instruct, meta-llama/Meta-Llama-3.1-70B-Instruct, meta-llama/Meta-Llama-3.1-405B-Instruct, mistralai/Mixtral-8x7B-Instruct-v0.1, codellama/CodeLlama-70b-Instruct-hf, and other DeepInfra model identifiers. The default is 01-ai/Yi-34B-Chat.

Q: Does this package contain a separate DeepInfra implementation?

A: No. It re-exports DeepInfraModel from swarmauri_standard.llms.DeepInfraModel so applications can depend on this provider package while sharing the common implementation.

Q: How does JSON mode work?

A: Pass enable_json=True to predict(), apredict(), batch(), or abatch(). The adapter sends response_format={"type": "json_object"} to the OpenAI-compatible endpoint.

Features

  • Provider-specific import: from swarmauri_llm_deepinfra import DeepInfraModel.
  • Swarmauri Conversation, HumanMessage, SystemMessage, and AgentMessage integration.
  • Sync predict() and async apredict() chat completion calls.
  • Sync stream() and async astream() SSE-style streaming.
  • Sync batch() and async abatch() helpers.
  • Configurable temperature, max_tokens, stop, and enable_json.
  • OpenAI-compatible request fields: messages, top_p, frequency_penalty, presence_penalty, and stream.
  • Model discovery through the DeepInfra /models endpoint.
  • Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.

Prerequisites

  • DeepInfra API key.
  • Network access to api.deepinfra.com.
  • A DeepInfra model ID that supports chat completions.
  • Swarmauri conversations built from Swarmauri message classes.

Installation

Install with uv:

uv add swarmauri_llm_deepinfra

Install with pip:

pip install swarmauri_llm_deepinfra

Usage

Run a DeepInfra chat completion:

import os

from swarmauri_llm_deepinfra import DeepInfraModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage
from swarmauri_standard.messages.SystemMessage import SystemMessage

conversation = Conversation()
conversation.add_message(SystemMessage(content="Answer with concise technical prose."))
conversation.add_message(HumanMessage(content="What is DeepInfra?"))

model = DeepInfraModel(
    api_key=os.environ["DEEPINFRA_API_KEY"],
    name="Qwen/Qwen2.5-72B-Instruct",
)
result = model.predict(conversation=conversation, temperature=0.2, max_tokens=256)

print(result.get_last().content)

Stream response chunks:

import os

from swarmauri_llm_deepinfra import DeepInfraModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content="Draft a short model card summary."))

model = DeepInfraModel(api_key=os.environ["DEEPINFRA_API_KEY"])

for token in model.stream(conversation=conversation, max_tokens=200):
    print(token, end="")

Request JSON output:

import os

from swarmauri_llm_deepinfra import DeepInfraModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content='Return {"status": "ok"} as JSON.'))

model = DeepInfraModel(api_key=os.environ["DEEPINFRA_API_KEY"])
result = model.predict(conversation=conversation, enable_json=True)

print(result.get_last().content)

Related Packages

LLM provider packages:

Foundational packages:

Best Practices

  • Store DEEPINFRA_API_KEY in a secret manager or environment variable.
  • Set name explicitly because hosted model availability can change.
  • Validate JSON-mode behavior on the exact model you deploy.
  • Use async methods for high-concurrency workloads.
  • Keep stop sequences close to the prompt design that was tested for a given model.

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_deepinfra-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.

swarmauri_llm_deepinfra-0.11.0.dev1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: swarmauri_llm_deepinfra-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_deepinfra-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 63ea246fca836a9971358d9f469c256d3173bf0e1af0e02eb6a0de2663a2e248
MD5 be3c4912c20dca3383bc8311c45dd813
BLAKE2b-256 056ccc6678f94a3c680905577258623d9902444f986ec83f2e58d3b6abaa6985

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_llm_deepinfra-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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_deepinfra-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 46a5783172ea533fcff834f8b81bdf4e1a1b567134522282782830779e63df66
MD5 d5f61bb3d3c51db651e97e5991128afc
BLAKE2b-256 a80815bc01447fcfe3b76f998f5d8946542c87e0d114f8efb13cbbcc9fe8b2db

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