Skip to main content

ai_library

ai_library is a Python package that exposes model training, inference, metrics recording, cron scheduling, and package-based configuration management.

Package Overview

Available Top-Level APIs

  • ai_library.validate_config(config_path=None)

    • Loads and validates the package default ai_library/config.yaml if no path is provided.
    • Returns the parsed configuration dictionary.
  • ai_library.update_config(config_path=None, updates=...)

    • Updates the package config file by default.
    • Supports a dictionary, a [key, value] pair, or a list of [key, value] pairs.
  • ai_library.show_config(config_path=None)

    • Prints the current configuration to stdout.
  • ai_library.train()

    • Loads configuration from the package config.
    • Reads data, builds the selected pipeline, and trains the model.
  • ai_library.infer()

    • Loads package configuration.
    • Loads a saved model and performs inference.
    • returns predictions, first_predicted, last_predicted, data_frequency, conformal_q
    • conformal_q is the safety margin in order to be 1-alpha accurate for the predicted time window
  • ai_library.record

    • Use ai_library.record.main() or run the module directly to start metric collection.
  • ai_library.add_to_cron() / ai_library.remove_from_cron()

    • Manage cron scheduling for recurring training runs.
    • Adds or removes a cron job that runs python3 -m ai_library.codebase.setup.train.

How to Use

Install

pip install ai-library-swch==0.1.1 

a safe python version is 3.12.3

Configuration

this is an example of how config can be printed and updated.

from ai_library import validate_config, update_config, show_config

update_config(None, updates=["parquet_train_size", 100000])
show_config()
validate_config()

Metric Recorder Function

Make sure that .env is reachable in the folder where this is executed, and that the specified port is reachable. Sample .env configuration:

MON_CLIENT_STOMP_HOST=127.0.0.1
MON_CLIENT_STOMP_PORT=61622

Execution command:

nohup python3 -c "from ai_library import record; record.main()" > record.log 2>&1 &

nohup is not necessary, but make sure to run the recorder in the background.

Train and Infer

import the functions:

from ai_library import train, infer

Manually use train (no cron)

the standard way is to use the cron functions to train in intervals. This might still be useful, for example when switching models.

train()

Cron Scheduling

add_to_cron creates a cron job that runs the train function in intervals.

import ai_library.codebase.setup.cron_manager as cron_manager

cron_manager.add_to_cron()
cron_manager.remove_from_cron()

Inference

after a trained model is accessible via the path, that is given in the config file, inference can be applied:

predictions, first_predicted, last_predicted, data_frequency, conformal_q = infer()

Metadata

Release files for ai-library-swch 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-library-swch 0.1.2
File Size Uploaded
ai_library_swch-0.1.2.tar.gz 23.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-library-swch 0.1.2
File Interpreter ABI Platform
ai_library_swch-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 52.6 kB

Release files / ai_library_swch-0.1.2.tar.gz

Download URL ai_library_swch-0.1.2.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8c1ab687651f23a06c69fc7df81626e46028c5af7db86daa2d6a1ea43badf589
BLAKE2b-256 checksum
How to use checksums
e0ad4ebc7ee1b6c1a88c2314b2f00fab779fc9b02bafc1f738326072af28538e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / ai_library_swch-0.1.2-py3-none-any.whl

Download URL ai_library_swch-0.1.2-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f07adb58011de16f984bfd6af9fb84a0d08cc09d2f69605e102af8462e344db
BLAKE2b-256 checksum
How to use checksums
7aec5c3ca4a7f9796454e85cee97de7d5eba769fde15f2f366f7dab50c48dc5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page