Skip to main content

Python client library for the HelpingAI API

Project description

HelpingAI

The official Python library for the HelpingAI API

PyPI version Python Versions

Installation

pip install helpingai

Quick Start

First, set your API key as an environment variable:

export HAI_API_KEY='your-api-key'

Basic usage example:

from helpingai import HAI

hai = HAI()

response = hai.chat.completions.create(
    model="HelpingAI2.5-10B",
    messages=[
        {"role": "system", "content": "You are an expert in emotional intelligence."},
        {"role": "user", "content": "What makes a good leader?"}
    ]
)

print(response.choices[0].message.content)

Advanced Usage

Streaming Responses

for chunk in hai.chat.completions.create(
    model="HelpingAI2.5-10B",
    messages=[{"role": "user", "content": "Tell me about empathy"}],
    stream=True
):
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Advanced Parameters

response = hai.chat.completions.create(
    model="HelpingAI2.5-10B",
    messages=[{"role": "user", "content": "Write a story about empathy"}],
    temperature=0.7,        # Controls randomness (0-1)
    max_tokens=500,        # Maximum length of response
    top_p=0.9,            # Nucleus sampling parameter
    frequency_penalty=0.3, # Reduces repetition
    presence_penalty=0.3   # Encourages new topics
)

Robust Error Handling

from helpingai import HAI, HAIError, RateLimitError, InvalidRequestError
import time

def make_completion_with_retry(messages, max_retries=3):
    for attempt in range(max_retries):
        try:
            return hai.chat.completions.create(
                model="HelpingAI2.5-10B",
                messages=messages
            )
        except RateLimitError as e:
            if attempt == max_retries - 1:
                raise
            time.sleep(e.retry_after)
        except InvalidRequestError as e:
            print(f"Invalid request: {str(e)}")
            raise
        except HAIError as e:
            print(f"API error: {str(e)}")
            raise

Requirements

  • Python 3.7+
  • requests library
  • Valid HelpingAI API key

Documentation

For detailed information, check out our comprehensive documentation:

Support

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

helpingai-0.0.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

helpingai-0.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file helpingai-0.0.1.tar.gz.

File metadata

  • Download URL: helpingai-0.0.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for helpingai-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d6b6de3494bd09d743567bb44bebef90e8f7cf224269f79471e6b2801a0f9ab6
MD5 c4a855d01350607e10a04d19dc1fc44e
BLAKE2b-256 34e96890dc9f87f8939e337f8f762f87bb7581220abbf3f300a157eac67013a8

See more details on using hashes here.

File details

Details for the file helpingai-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: helpingai-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for helpingai-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b960103a48639313866bbb502f7e4ca3ec83e4738222badac6fa429bf606e3db
MD5 ff87f5a196905e00cf3285f4f0c0ba3b
BLAKE2b-256 b9326245bbeafb94ad2436a018570c24f85dc72dbea0fc149a4e5c1db76e6b66

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