Metadata-Version: 2.5
Name: laya-weights
Version: 0.1.1
Summary: Run laya without Hugging Face access: pip install laya-weights and laya.load() works offline
Project-URL: Model (Hugging Face), https://huggingface.co/convaiinnovations/laya
Project-URL: laya on PyPI, https://pypi.org/project/laya/
Project-URL: laya-weights guide, https://pypi.org/project/laya-weights/
Author: Aleeza Noor
Maintainer: Aleeza Noor
License-Expression: Apache-2.0
Keywords: agent-routing,huggingface,laya,offline,weights
Requires-Python: >=3.8
Requires-Dist: laya
Requires-Dist: laya-weights-part-00==0.1.0
Requires-Dist: laya-weights-part-01==0.1.0
Requires-Dist: laya-weights-part-02==0.1.0
Requires-Dist: laya-weights-part-03==0.1.0
Requires-Dist: laya-weights-part-04==0.1.0
Requires-Dist: laya-weights-part-05==0.1.0
Requires-Dist: laya-weights-part-06==0.1.0
Requires-Dist: laya-weights-part-07==0.1.0
Requires-Dist: laya-weights-part-08==0.1.0
Description-Content-Type: text/markdown

# laya-weights

Run [laya](https://pypi.org/project/laya/) without access to the Hugging Face Hub.

laya normally downloads its model from Hugging Face the first time you use it. Many organisations
allow `pip install` (directly or through an internal mirror such as Artifactory or Nexus) but block
Hugging Face, so laya fails there. This package ships laya's English checkpoint through pip instead:

```bash
pip install laya-weights
```

That's all. Your existing laya code works unchanged and never contacts Hugging Face for this model.

**Maintainer:** Aleeza Noor

## Quick start

**1. Install** (about 850 MB download; also installs `laya`):

```bash
pip install laya-weights
```

**2. Run the built-in example** to check everything works:

```bash
python -m laya_weights.example
```

```
tech_support_agent     <- The app crashes every time I open settings
billing_agent          <- I was charged twice this month, please refund one
sales_agent            <- Do you offer a discount for teams of 50?
```

Try your own query:

```bash
python -m laya_weights.example "My invoice shows the wrong company name"
```

The first run takes a little longer while the weights are unpacked (see [How it works](#how-it-works)).

## Use it in your code: agent routing

The English checkpoint suits agent routing and orchestration: read a query and pick the agent whose
description fits it best. Save this as `route.py` and edit `AGENTS` to describe your own agents:

```python
import laya

AGENTS = {
    "billing_agent": "refunds, invoices, duplicate charges, payment failures",
    "tech_support_agent": "crashes, bugs, error messages, login problems",
    "sales_agent": "pricing, plans, demos, upgrades for new customers",
}

agent = laya.load()   # load once and reuse; no Hugging Face access needed

def route(query):
    questions = {"agent": {
        "type": "choice",
        "instructions": "Which agent should handle this request?",
        "criteria": AGENTS,
    }}
    return agent.predict(query, questions)["answers"]["agent"]["choice"]

print(route("The app crashes every time I open settings"))   # tech_support_agent
```

Tips:
- Load the model once (`laya.load()` takes several seconds) and reuse it for every query.
- Write specific descriptions that don't overlap. "refunds, invoices" routes better than "money stuff".
- See the [laya documentation](https://pypi.org/project/laya/) for other question types.

## Installing on a machine with no internet

On a machine that can reach PyPI, download every wheel:

```bash
pip download laya-weights -d laya-wheels
```

Copy the `laya-wheels` folder across, then install from it:

```bash
pip install --no-index --find-links laya-wheels laya-weights
```

Download on the same OS and Python version as the target machine, because laya's dependencies
(such as torch) have platform-specific wheels.

## Docker

```dockerfile
FROM python:3.11-slim
RUN pip install --no-cache-dir laya-weights \
 && python -m laya_weights          # unpack the weights at build time, not at first request
```

## How it works

- PyPI rejects files over 100 MB, so the 843 MB `model.safetensors` ships as 9 small
  `laya-weights-part-NN` packages that `laya-weights` depends on.
- On first load, the parts are joined back into one file in `~/.cache/laya-weights`, checked
  against a SHA-256 and reused afterwards. Run `python -m laya_weights` to do this ahead of time
  (it prints the folder).
- A small startup hook catches laya's Hugging Face download request for this checkpoint and serves
  it from that folder. Requests for other models still go to Hugging Face as normal.

## Configuration

| Setting | Default | Purpose |
|---|---|---|
| `LAYA_WEIGHTS_HOME` | `~/.cache/laya-weights` | Where the joined weights are stored. Point it at a writable folder if your home directory is read-only. |

Disk space: about 1.7 GB in total (the installed parts plus the joined copy).

## Troubleshooting

- **laya still tries to reach Hugging Face.** Check that `laya-weights` is installed in the same
  environment as your code (`pip show laya-weights`), and that you're using the default English
  checkpoint (`laya.load()` with no model name).
- **`rebuilt model.safetensors fails its SHA-256 check`.** A part is corrupt or from a different version.
  Run `pip install --force-reinstall laya-weights`.
- **Permission error on first load.** Set `LAYA_WEIGHTS_HOME` to a writable folder.

## Limitations

- Only the English checkpoint is included. The multilingual and typed-decisions checkpoints are not,
  and `Router()` sends non-English text to the multilingual checkpoint, which still needs Hugging Face.
- Tested with laya 0.4.34 and 0.4.37.

## Building and releasing (maintainers)

```bash
pip install build hatchling twine huggingface_hub
python -c "from huggingface_hub import snapshot_download as s; s('convaiinnovations/laya', revision='55cf4c4ebb4ebe31b2550e8bdf3bd21b99753851', local_dir='hf_snapshot', allow_patterns=['rl_agent_config.json','model.safetensors','tokenizer/*','encoder/*'])"
python build_weights.py --version 0.1.1 --parts-version 0.1.0
pip install dist/*.whl && python -m pytest tests
twine upload dist/laya_weights-0.1.1-py3-none-any.whl
```

For a docs or code change, keep `--parts-version` on the published parts and upload only the
`laya_weights` wheel. Bump the parts only when the weights change.
