Skip to main content

Official Asymmetric (https://asymmetric.sh) SDK

Project description

asymmetric-py

Read the docs at https://asymmetric.sh/docs

Install

pip install asymmetric-py

Usage

from asymmetric import Asymmetric, GuardrailViolation

client = Asymmetric(api_key="sk_live_...")

Guardrails

Basic completion

try:
    response = client.chat.completions.create(
        model="openai/gpt-4o-mini",
        messages=[{"role": "user", "content": "Tell me about Caltech"}],
        guardrail_policy="Flag any content mentioning Caltech",
    )
    print(response.choices[0].message.content)
except GuardrailViolation as e:
    print(e.policy)

Streaming

try:
    for chunk in client.chat.completions.create(
        model="openai/gpt-4o-mini",
        messages=[{"role": "user", "content": "Tell me about Caltech"}],
        guardrail_policy="Flag any content mentioning Caltech",
        stream=True,
    ):
        if chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="")
except GuardrailViolation as e:
    print(f"\nViolation: {e.policy}")

Multiple policies

response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
    guardrail_policy=[
        "Flag any content promoting violence",
        "Flag any content containing profanity",
    ],
)

Violation history

violations = client.guardrails.list_violations()
for v in violations:
    print(v.timestamp, v.guardrail_policy)

Memories

Log and use memories in a request

response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "What did Darwin discover?"}],
    memory=[
        {"group": "darwin_agent", "goal": "Historical records about Darwin"}
    ],
)
print(response.choices[0].message.content)

Finetuning

Trigger training and inspect status

job = client.finetuning.train(
    memory_group="darwin_agent",
    lora_name="darwin_adapter",
)
print(job.status, job.message)

status = client.finetuning.status(
    memory_group="darwin_agent",
    lora_name="darwin_adapter",
)
print(f"Ready: {status.lora_ready}")

# List all adapters
adapters = client.finetuning.list()
for a in adapters:
    print(f"{a.lora_name}: {a.status}")

LoRA inference

response = client.chat.completions.create(
    model="asymmetric/Qwen3-8B",
    messages=[{"role": "user", "content": "Tell me about Darwin's voyages"}],
    finetuning={"lora_name": "darwin_adapter"},
)
print(response.choices[0].message.content)

Auto-training with memory

response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "What did Darwin discover?"}],
    memory=[{"group": "darwin_agent", "goal": "Historical records about Darwin"}],
    finetuning={
        "lora_name": "darwin_adapter",
        "finetune_thresh": 3,
        "min_finetune_group": 5,
    },
)

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

asymmetric_py-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

asymmetric_py-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file asymmetric_py-0.2.0.tar.gz.

File metadata

  • Download URL: asymmetric_py-0.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for asymmetric_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cae326be7621e91bd8ef45becb4366edcd71dbc72ba43c6f172282feb5aeafe5
MD5 52031ecf2d3123ec69eecfeb40269c57
BLAKE2b-256 38ac93cdc09704e67eebeaa0cfcb7f918f2aff7475b024f0c4f032eb0791a8d9

See more details on using hashes here.

File details

Details for the file asymmetric_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: asymmetric_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for asymmetric_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 011ee6acf379e15c20961645ce9efc2bcf0bf14957dc34a6de5b3858b8e35d4d
MD5 705d7bb3c13bc2facf1ae28151908e17
BLAKE2b-256 72201781aa5c74be135fce9235a4074408084dc1e17dca10d20e10ac159a23ad

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