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.0.tar.gz (7.8 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.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for parallax_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f2596e0ebeb07da32ff4011a8581bd5041ed3a97424266b8517fbf4c74a207e3
MD5 e4c915bb32397639a6b3e4b9b3e79c30
BLAKE2b-256 d25afc42e73c86dc2069b66af5dbd4ca10aed5251e366b798ceb849be1fe5a4f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for parallax_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed1bcdaef139770946fee1fe6449e7c194ac763b439afa77efbd6634d09b310e
MD5 8af691c6e3b726bb1b6a73251148c977
BLAKE2b-256 a2c75810b1d42807c3fe5b7f626b05f805578048f6b5036d6500290adb300ad6

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