Skip to main content

Lightweight parallel AI API calls in Python.

Project description

Parallax-AI

Lightweight parallel AI API calls in Python.

Installation

You can install Parallax using pip:

pip install parallax-ai

Testing

vllm serve google/gemma-3-27b-it
python -m parallax_ai.test
>>>
ParallaxOpenAIClient.completions:
First Output Elapsed Time: 7.10s
Total Elapsed Time (500 requires): 7.10s
ParallaxOpenAIClient.icompletions:
First Output Elapsed Time: 2.85s
Total Elapsed Time (500 requires): 6.99s
ParallaxOpenAIClient.chat_completions:
First Output Elapsed Time: 7.32s
Total Elapsed Time (500 requires): 7.32s
ParallaxOpenAIClient.ichat_completions:
First Output Elapsed Time: 2.85s
Total Elapsed Time (500 requires): 7.09s
Vanilla OpenAI Client:
First Output Elapsed Time: 1.78s
Total Elapsed Time (500 requires): 672.02s

Usage (Compatible with any OpenAI-API–compatible server, e.g., vLLM)

Initialize Client

from parallax_ai import ParallaxOpenAIClient

# Initialize Client
parallax_client = ParallaxOpenAIClient(
    api_key=YOUR_API_KEY,
    base_url=YOUR_API_BASE_URL,
)

list_of_messages = [
    [{"role": "user", "content": "..."}],
    [{"role": "user", "content": "..."}],
    [{"role": "user", "content": "..."}],
    .
    .
    .
    [{"role": "user", "content": "..."}],
]

chat_completions: Returns a list of outputs in order (waits until all are finished)

outputs = parallax_client.chat_completions(list_of_messages, model="gpt-3.5-turbo")
for output in outputs:
    # PROCESS OUTPUT
    pass

ichat_completions: Returns outputs one by one in order (yields as soon as each finishes)

for output in parallax_client.ichat_completions(list_of_messages, model="gpt-3.5-turbo"):
    # PROCESS OUTPUT
    pass

ichat_completions_unordered: Returns outputs as they finish (order not guaranteed)

for output, index in parallax_client.ichat_completions_unordered(list_of_messages, model="gpt-3.5-turbo"):
    # PROCESS OUTPUT
    pass

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

parallax_ai-0.2.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

parallax_ai-0.2.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file parallax_ai-0.2.2.tar.gz.

File metadata

  • Download URL: parallax_ai-0.2.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for parallax_ai-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7c53100becff8eb43aabe719ea0e6d8dc277e5bedb855d8d685cc61b1caf1411
MD5 25e449fb7d04f17b3c316e0917a876d2
BLAKE2b-256 6c5fdcd6decb4f3baa359d798809e54dfb83b76538fd517114cb12766aae8b19

See more details on using hashes here.

File details

Details for the file parallax_ai-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: parallax_ai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for parallax_ai-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c70c2e54c8acfd8887fdd2c4c67c7d5a2102e4194e43b131c923f7ed31f2dd1e
MD5 daf18e75d4b145558283289a5d76a5d4
BLAKE2b-256 f09a0a20c57c9d85b7188e59c61b3bef6aa24841a19bbf55146d2c8cbfeaab28

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