A lightweight utility library for modern Python development
Project description
ZGI SDK
A lightweight Python SDK with OpenAI-compatible API interface.
Installation
pip install zgiai
Quick Start
OpenAI-Compatible API Client
from zgi import ZGI
# Initialize client
client = ZGI(api_key="your-api-key")
# Or use environment variable
# export ZGI_API_KEY="your-api-key"
client = ZGI()
# Chat completions
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response['choices'][0]['message']['content'])
# Upload a file
with open("training_data.jsonl", "rb") as f:
file = client.files.create(
file=f,
purpose="fine-tune"
)
print(f"Uploaded file: {file['id']}")
# Create fine-tuning job
job = client.fine_tuning.jobs.create(
training_file=file['id'],
model="gpt-3.5-turbo",
hyperparameters={
"n_epochs": 3
}
)
print(f"Fine-tuning job created: {job['id']}")
# Check job status
job_status = client.fine_tuning.jobs.retrieve(job['id'])
print(f"Status: {job_status['status']}")
# List models
models = client.models.list()
for model in models['data']:
print(model['id'])
Utility Functions
from zgi import is_empty, deep_clone, debounce, sleep, random_string, format_date
# Check if a value is empty
is_empty('') # True
is_empty([]) # True
is_empty({}) # True
# Deep clone an object
original = {'a': 1, 'b': {'c': 2}}
cloned = deep_clone(original)
# Debounce a function
@debounce(wait=0.3)
def my_function():
print('Debounced!')
# Sleep for a duration
sleep(1) # Sleep for 1 second
# Generate a random string
random_str = random_string(10) # Random 10-character string
# Format a date
from datetime import datetime
formatted = format_date(datetime.now()) # "2024-01-01"
API Reference
ZGI Client
ZGI(api_key, base_url, organization, timeout)
Initialize the ZGI client.
Parameters:
api_key(str): Your ZGI API key (or setZGI_API_KEYenv var)base_url(str, optional): Base URL for API (default:https://api.zgi.ai/v1)organization(str, optional): Organization IDtimeout(int, optional): Request timeout in seconds (default: 60)
Chat API
client.chat.completions.create(**kwargs)
Create a chat completion.
Parameters:
model(str): Model ID (e.g., "gpt-4", "gpt-3.5-turbo")messages(list): List of message dicts with 'role' and 'content'temperature(float): Sampling temperature (0-2, default: 1.0)max_tokens(int, optional): Maximum tokens to generatestream(bool): Whether to stream responses (default: False)
Files API
client.files.create(file, purpose)
Upload a file.
Parameters:
file(BinaryIO): File object to uploadpurpose(str): Purpose ("fine-tune", "assistants", etc.)
client.files.list(purpose=None)
List all files.
client.files.retrieve(file_id)
Get file information.
client.files.delete(file_id)
Delete a file.
Fine-tuning API
client.fine_tuning.jobs.create(training_file, model, **kwargs)
Create a fine-tuning job.
Parameters:
training_file(str): File ID of training datamodel(str): Base model to fine-tunevalidation_file(str, optional): File ID of validation datahyperparameters(dict, optional): Training hyperparameterssuffix(str, optional): Custom model name suffix
client.fine_tuning.jobs.list(limit=20, after=None)
List fine-tuning jobs.
client.fine_tuning.jobs.retrieve(job_id)
Get job details.
client.fine_tuning.jobs.cancel(job_id)
Cancel a job.
Models API
client.models.list()
List all available models.
client.models.retrieve(model_id)
Get model information.
Utility Functions
is_empty(value: Any) -> bool
Check if a value is empty (None, empty string, empty list, or empty dict).
deep_clone(obj: T) -> T
Create a deep copy of an object.
debounce(wait: float = 0.3)
Decorator to debounce a function with an optional wait time (default: 0.3 seconds).
sleep(seconds: float) -> None
Sleep for a specified duration in seconds.
random_string(length: int = 10) -> str
Generate a random alphanumeric string with specified length (default: 10).
format_date(date: datetime = None, fmt: str = "%Y-%m-%d") -> str
Format a date to a string (default: current date, format: YYYY-MM-DD).
Environment Variables
ZGI_API_KEY: Your ZGI API keyZGI_BASE_URL: Custom API base URL (optional)ZGI_ORGANIZATION: Organization ID (optional)
Requirements
- Python >= 3.7
- requests >= 2.20.0
License
MIT
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
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
File details
Details for the file zgiai-1.0.0.tar.gz.
File metadata
- Download URL: zgiai-1.0.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cddc7891934015c6efa8bdda944ee5d87d923f8c5cb53bf6940781af48482076
|
|
| MD5 |
9429b96f64828d51e701d989fe5458d7
|
|
| BLAKE2b-256 |
b61d6f9b4b78db073fffb6f6f1273b8ac81e8e3e3b7872fcc02be33774d2696a
|
File details
Details for the file zgiai-1.0.0-py3-none-any.whl.
File metadata
- Download URL: zgiai-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a254c06c29dbfc8f9340453d5ff641c7b29d173dd410d05e1ed7879cf2a85a5
|
|
| MD5 |
7fcfb17cd0eb0d06ae9b189bf5279ecd
|
|
| BLAKE2b-256 |
667f5602ffad04864717784df18b8e9053a55b353a204079d92fcf2797c39135
|