Metadata-Version: 2.4
Name: wso2-gateway-policy-prompt-compression
Version: 0.1.2
Summary: Prompt compression policy for WSO2 AI Gateway — reduces LLM token usage using statistical compression
License: Apache-2.0
Keywords: wso2,gateway,policy,llm,prompt-compression,ai
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: compression-prompt>=0.1.2

# Prompt Compression Policy — WSO2 AI Gateway

Reduces LLM token usage by statistically compressing prompts before they reach the upstream provider, while preserving semantic meaning.

## Features

- Configurable compression ratio (0.1 – 0.9)
- JSONPath selector for targeting specific message fields
- Automatic protection for code blocks and JSON structures
- Domain-term preservation list
- Minimum token threshold — short inputs pass through unchanged

## Installation

```bash
pip install wso2-gateway-policy-prompt-compression
```

## Usage in WSO2 Gateway

Add to your `build.yaml`:

```yaml
policies:
  - name: prompt-compression
    pipPackage: wso2-gateway-policy-prompt-compression==0.1.2
```

Then reference the policy in your API definition:

```yaml
operations:
  - method: POST
    path: /chat
    policies:
      - name: prompt-compression
        version: v0.1.2
        params:
          compressionRatio: 0.5
          jsonPath: "$.messages[-1].content"
          minInputTokens: 100
```

## Parameters

| Parameter | Type | Default | Description |
|---|---|---|---|
| `compressionRatio` | number | `0.5` | Target ratio (0.1–0.9). Lower = more aggressive. |
| `jsonPath` | string | `$.messages[-1].content` | JSONPath to the text field to compress. |
| `minInputTokens` | integer | `100` | Skip compression if input is shorter than this. |
| `preserveCodeBlocks` | boolean | `true` | Protect `` ``` `` blocks from compression. |
| `preserveJson` | boolean | `true` | Protect JSON structures from compression. |
| `domainTerms` | array | `[]` | Terms that must never be removed. |

## License

Apache License 2.0 — see [LICENSE](https://www.apache.org/licenses/LICENSE-2.0).
