Skip to main content

A Python client for the Axionic API.

Project description

Mechanex

Mechanex is a powerful Python library for interacting with the Axionic API, designed for mechanistically debugging, steering, and monitoring Large Language Models (LLMs).

Learn more at axioniclabs.ai

Installation

pip install mechanex

Quick Start

1. Initialize the Client

import mechanex as mx
import os

# Set your API key
mx.set_key("your-api-key-here")

2. Standard Generation

output = mx.generation.generate(
    prompt="The future of AI is",
    max_tokens=50,
    sampling_method="top-k" # Options: greedy, top-k, top-p, ads
)
print(output)

Steering Vectors

Steering vectors allow you to control the behavior of a model by injecting specific activation patterns.

Compute a Steering Vector

# Create a vector from contrastive pairs
vector_id = mx.steering.generate_vectors(
    prompts=["I think that", "People say"],
    positive_answers=[" kindness is key", " helping is good"],
    negative_answers=[" hate is power", " hurting is fine"],
    method="few-shot" # Options: caa, few-shot
)

# Apply it during generation
steered_output = mx.generation.generate(
    prompt="What is your philosophy?",
    steering_vector=vector_id,
    steering_strength=1.5
)

Load from JSONL

You can also generate vectors from a dataset:

vector_id = mx.steering.generate_from_jsonl("path/to/dataset.jsonl")

SAE (Sparse Autoencoder) Pipeline

The SAE pipeline provides advanced behavioral detection and automatic correction.

1. Create a Behavior

Define a behavior to monitor and potentially correct.

behavior = mx.sae.create_behavior_from_jsonl(
    behavior_name="toxicity",
    dataset_path="tests/toxicity_dataset.jsonl",
    description="Reduces toxic output"
)

2. Generate with SAE Steering

Utilize SAEs to detect behavioral drift and automatically apply corrections.

# Generate with auto-correction enabled
response = mx.sae.generate(
    prompt="Tell me a secret",
    auto_correct=True,
    behavior_names=["toxicity"] # Optional: filter for specific behaviors
)
print(response) # Returns the generated text string

3. List Behaviors

all_behaviors = mx.sae.list_behaviors()

Model Utilities

Inspect the Model Graph

Return the layer structure of the currently loaded model.

graph = mx.model.get_graph()
for node in graph:
    print(node)

Deploying Remote Hooks

If you want to host your own instance of the remote hooks server, follow these steps:

  1. Model Hosting: Ensure the model you want to use is available on Hugging Face.
  2. Docker Image: Use the official Docker image: axioniclabs/remote-hooks:general. You can find it on Docker Hub.
  3. Configuration: Set the following environment variables in your deployment:
    • MODEL_NAME: The Hugging Face model identifier (e.g., meta-llama/Llama-3.2-1B).
    • HF_TOKEN: Your Hugging Face access token.

For more details, visit axioniclabs.ai

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

mechanex-0.4.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

mechanex-0.4.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file mechanex-0.4.0.tar.gz.

File metadata

  • Download URL: mechanex-0.4.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mechanex-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2392fb19e7c6cd77a7f5d65657f41342fdbd21bbd2b3964af4a50ed2140437a7
MD5 1d42524c28dba84bf15e3699fbb6dea1
BLAKE2b-256 1e6dafd3f0716c76ecc9774a734c4cd3cf099f3b6bfaa4b59220692df3e513cd

See more details on using hashes here.

File details

Details for the file mechanex-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: mechanex-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mechanex-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af27263be31685dc785c6144c395f3ea0031dbe2a222456149150f45bf4c73a5
MD5 e5344b288d5aa0b810e5fec7d7e355a8
BLAKE2b-256 6c2beb9285f865d7c90c4ef8ccc027f864aff23b95fddce9ac029d5a4c8fbf2e

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