Metadata-Version: 2.4
Name: cfprompt
Version: 0.1.1
Summary: Counterfactual prompting with adjusted paraphrase baselines
Author-email: Zihao Yang <yzh_xjy@126.com>
License-Expression: MIT
License-File: LICENSE
Requires-Python: <3.12,>=3.11
Requires-Dist: huggingface-hub>=1.0
Requires-Dist: numpy>=2.0
Requires-Dist: openai>=1.30
Requires-Dist: pandas>=2.2
Requires-Dist: pydantic>=2.5
Requires-Dist: pyyaml>=6.0
Requires-Dist: scipy>=1.11
Requires-Dist: statsmodels>=0.14
Requires-Dist: tiktoken>=0.6
Requires-Dist: torch>=2.1
Requires-Dist: transformers>=4.50
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: pip-tools>=7.4; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=4.1; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# cfprompt

Counterfactual prompting with adjusted paraphrase baselines.

Companion package to *"Compared to What? Baselines and Metrics for Counterfactual Prompting."*

## Install

```bash
pip install cfprompt   # PyPI release pending; for now:
pip install -e .       # from source clone
```

## Quickstart

```python
import pandas as pd
import cfprompt

df = pd.DataFrame({"question": [...]})

study = cfprompt.Study(
    data=df,
    perturb_column="question",
    target_perturbation=my_swap_function,
    prompt_template="Q: {question}\nA:",
    target_model=cfprompt.HFModel("hf-internal-testing/tiny-random-LlamaForCausalLM"),
    paraphrase_model=cfprompt.OpenAIModel("gpt-4.1"),
    classes=["A", "B", "C", "D"],
    seed=42,
)
report = study.run_all(metrics=["jsd", "flip_rate"])
report.to_excel("results.xlsx")
```

See `examples/` for runnable scripts.

## CLI

```bash
cfprompt init my_study             # scaffold a starter directory
cfprompt validate config.yaml      # schema check
cfprompt run config.yaml           # execute the study
```

## Security

`cfprompt run` executes Python code referenced by the config (the
`target_perturbation` and `extract_label` `module:function` specs are imported
and called). Do not run untrusted YAML files.

**Pickle / `.pkl` files (Study.save / DiskCache):** `Study.load(path)` and a `cache_dir` populated by another user are equivalent to executing arbitrary Python on load. Never load a `.pkl` from an untrusted source, and treat `cache_dir` as user-private (do not point it at a directory another user can write to).

## License

MIT.
