Python client library for the HelpingAI API
Project description
HelpingAI
The official Python library for the HelpingAI API
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+
requestslibrary- Valid HelpingAI API key
Documentation
For detailed information, check out our comprehensive documentation:
Support
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(12.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
HelpingAI-0.0.2-py3-none-any.whl
(14.3 kB
view details)
File details
Details for the file helpingai-0.0.2.tar.gz.
File metadata
- Download URL: helpingai-0.0.2.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
687975e104643d37a7661a313efe9a0cf649e31bb0eedcec4ec8e3719cffac89
|
|
| MD5 |
7c50f39c4e884c06e9566c50b8262e6b
|
|
| BLAKE2b-256 |
f367034897292844b431796787d82358e6c2b0438d98d818f5abe4fe8f4164c0
|
File details
Details for the file HelpingAI-0.0.2-py3-none-any.whl.
File metadata
- Download URL: HelpingAI-0.0.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
637706cb7f334f01fbf37f22e771d10c5e9e92589102904ff79220db471ed3ef
|
|
| MD5 |
7c738172763dac8d1405f00c85e1f233
|
|
| BLAKE2b-256 |
cb25e5ef44cc94483d571cd1a21b68dff668a4267843cc8719b90c6ca23ee8a8
|