Add Prompt Compressor Policy v0.1#176
Conversation
Introduce a new prompt-compressor policy for the WSO2 AI Gateway (version 0.1.0). Adds package files (README.md, __init__.py, policy-definition.yaml, policy.py, pyproject.toml, requirements.txt) implementing a Python executor policy that buffers request bodies, extracts a prompt via a configurable jsonPath (default $.messages[0].content), and applies configurable compression rules. Supports selective compression using <APIP-COMPRESS> tags, rule-based ratio/token modes, dynamic metadata reporting, and uses the compression-prompt dependency. Includes packaging metadata so the policy can be installed/consumed by the gateway builder.
Add Prompt Compressor v0 documentation and metadata, and adjust package layout and imports. Files added: docs/prompt-compressor/v0.1/docs/prompt-compressor.md and docs/prompt-compressor/v0.1/metadata.json; docs/README.md updated to list the new policy. policies/prompt-compressor/README.md simplified usage and updated the build.yaml pipPackage example. policy.py import updated from wso2_gateway_policy_sdk to apip_sdk_core. pyproject.toml updated to rename the package and Python package directory from prompt_compressor to prompt_compressor_v0 (including package-data mapping) to reflect the v0 packaging changes.
Introduce comprehensive unit tests for the prompt-compressor policy (policies/prompt-compressor/test_policy.py). Adds fake dependency stubs and a FakeCompressor to exercise policy behavior: mode selection, params normalization and sorting, rule selection and ratio resolution, JSONPath extraction/updating and error cases, selective tagging and nested tag handling, on_request_body transformations and metadata, non-fatal and fatal compressor errors, and compressor instance caching by rounded ratio.
Add a new "Notes" section to the prompt-compressor docs covering semantic preservation, compression efficiency caveats, and a list of protected content types (code blocks, JSON, file paths/URLs, technical identifiers, hashes/large numbers, and bracketed content).
Co-authored-by: Renuka Piyumal Fernando <renukapiyumal@gmail.com>
Co-authored-by: Renuka Piyumal Fernando <renukapiyumal@gmail.com>
Rename the request context parameter from ctx to req_ctx in policy.on_request_body and update all references (body access and guards) accordingly. Update unit tests to call on_request_body with req_ctx and adjust a long test line for readability. Simplify README to briefly describe the package as a Python policy that compresses prompt text.
Add Prompt Compressor Policy
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummaryThis PR adds a new Prompt Compressor policy (v0.1) to the gateway, enabling automatic compression of selected prompt text in JSON request bodies before forwarding to upstream LLM services. Changes OverviewPolicy Implementation
Documentation & Metadata
Configuration & Dependencies
Testing & Quality
Documentation Updates
Key Features
WalkthroughThis change introduces a new Prompt Compressor policy ( Sequence Diagram(s)sequenceDiagram
participant Client
participant Gateway as "Gateway\nPromptCompressorPolicy"
participant Compressor as "Compressor\n(cache)"
participant Upstream as "Upstream LLM"
Client->>Gateway: HTTP request with JSON body
Gateway->>Gateway: Buffer body, parse JSON
Gateway->>Gateway: Extract target string via jsonPath
alt selective tags present
Gateway->>Gateway: Identify <APIP-COMPRESS> regions
Gateway->>Compressor: Request compression per region (resolved ratio)
else no tags
Gateway->>Compressor: Request compression for whole target (resolved ratio)
end
Compressor-->>Gateway: Compressed text (or error/no-op)
Gateway->>Gateway: Update JSON value, remove tags, compact serialize
Gateway->>Upstream: Forward modified request with dynamic_metadata
Upstream-->>Client: Upstream response (unchanged by policy)
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (13)
docs/prompt-compressor/v0.1/docs/prompt-compressor.md (2)
184-189: Clarify the behavior whenvalueexceeds the estimated token count intokenmode.For the fallback rule
{ upperTokenLimit: -1, type: token, value: 1200 }, prompts whose estimated tokens are at or below 1200 result in the rule being skipped (per the implementation,resolve_ratioreturnsNonewhentarget_tokens >= estimated_tokens). The current wording suggests the rule always "targets approximately 1200 retained tokens." A short note that the rule is a no-op when the prompt is already at/under the target would help readers reason about edge cases.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/prompt-compressor/v0.1/docs/prompt-compressor.md` around lines 184 - 189, Clarify that in token mode (e.g., the fallback rule with upperTokenLimit: -1, type: token, value: 1200) the rule is a no-op when the prompt's estimated token count is already <= value: the implementation's resolve_ratio function returns None if target_tokens >= estimated_tokens, so add a short note stating the rule only applies when estimated_tokens > value and is skipped otherwise.
50-58: Document behavior for malformed selective-compression tags.The "Selective Compression Tags" section explains the happy path but does not document what happens when tags are unmatched (e.g., a stray
</APIP-COMPRESS>or an unclosed<APIP-COMPRESS>). Based on the implementation snippet shared, the policy tolerates these cases (an unclosed open tag still compresses the trailing region; a stray close tag is dropped). Please document the expected handling so users can rely on it.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/prompt-compressor/v0.1/docs/prompt-compressor.md` around lines 50 - 58, Update the "Selective Compression Tags" section to document handling of malformed tag pairs for `<APIP-COMPRESS>` and `</APIP-COMPRESS>`: state that an unmatched opening tag compresses until end-of-string (i.e., an unclosed `<APIP-COMPRESS>` will compress the trailing region) and that stray closing tags (`</APIP-COMPRESS>`) are ignored/dropped; also clarify that tags are removed from the final forwarded text and that behavior applies when using selective-region compression in the policy.policies/prompt-compressor/__init__.py (1)
1-3: LGTM.
__version__here matchespyproject.toml(0.1.0). Consider sourcing it from package metadata (e.g.,importlib.metadata.version("prompt-compressor-v0")) in a future iteration to avoid drift between the two files.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/__init__.py` around lines 1 - 3, Current __version__ in policies/prompt-compressor/__init__.py is hardcoded as "0.1.0" which can drift from pyproject.toml; replace the hardcoded __version__ with a runtime lookup using importlib.metadata.version("prompt-compressor-v0") (or importlib_metadata for older Python) and set __version__ to that value, adding a fallback (e.g., default string or empty) and handling PackageNotFoundError so imports won’t fail when metadata is unavailable; update the module-level symbol __version__ and ensure any import names remain unchanged.policies/prompt-compressor/README.md (1)
1-3: Consider expanding the package README.A single sentence is sufficient as a placeholder, but a brief section on configuration entry points and a link to
docs/prompt-compressor/v0.1/docs/prompt-compressor.mdwould help developers landing here from PyPI orpip show.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/README.md` around lines 1 - 3, Update the README for the prompt-compressor package to include a one-sentence placeholder summary plus a short "Configuration" section that lists the package entry points and where to configure behavior (e.g., environment variables, config files, or middleware hooks used by the prompt-compressor package) and add a direct link to docs/prompt-compressor/v0.1/docs/prompt-compressor.md so external devs (pip/ PyPI consumers) can quickly find usage and configuration details; ensure the README still includes the original package description and the linked docs path.policies/prompt-compressor/policy-definition.yaml (3)
39-56: Document or constrainvaluesemantics pertype.
valueis declared asnumber, so floats are accepted in both modes. Intokenmode the implementation casts toint, which silently truncates fractional values (e.g.,value: 800.9→800). Either tighten the description to state the truncation, or split into per-mode validation (e.g.,exclusiveMinimum: 0, plus a note thattokenmode expects an integer-valued number). At minimum, addexclusiveMinimum: 0so non-positive values are rejected during validation rather than silently ignored at runtime.♻️ Suggested change
value: type: number + exclusiveMinimum: 0 description: | Rule value. For "ratio", use a retained-size ratio such as 0.8. - For "token", use the target retained token estimate. + For "token", use the target retained token estimate. Fractional + values in "token" mode are truncated to an integer.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/policy-definition.yaml` around lines 39 - 56, The schema currently allows any number for the "value" property but the implementation truncates fractional values in token mode; update the policy-definition.yaml to validate and document per-type semantics: add "exclusiveMinimum: 0" to "value" to reject non-positive numbers, and enforce integer-only for token mode (e.g., use an if: {properties:{type:{const:"token"}}} then: {properties:{value:{multipleOf:1}}, required:["value"]}) or alternately state in the "value" description that token mode truncates fractions; reference the "type" enum (ratio|token), the "value" field, and required list (upperTokenLimit/type/value) when making the change.
34-38: Consider adding aminimum: -1constraint onupperTokenLimit.The schema currently allows any integer (e.g.,
-5,-100), which the implementation silently treats as invalid. Addingminimum: -1would surface configuration errors at validation time rather than at runtime.♻️ Suggested change
upperTokenLimit: type: integer + minimum: -1 description: | Inclusive upper bound for the estimated token count. Use -1 as the fallback rule for all remaining cases.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/policy-definition.yaml` around lines 34 - 38, The schema for upperTokenLimit currently allows any integer and should enforce minimum: -1 to prevent invalid negative values; update the policy-definition.yaml schema for the upperTokenLimit property by adding "minimum: -1" under upperTokenLimit (keeping the existing type and description) so invalid values like -5 fail validation at config load rather than at runtime.
22-32: Consider documenting the "exactly one fallback" expectation.The description states
upperTokenLimit: -1is the catch-all, but the schema does not prevent multiple rules from using-1(only the first matching one wins after sorting). A short note in therulesdescription that defining more than one fallback is not recommended would help avoid configuration mistakes.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/policy-definition.yaml` around lines 22 - 32, The rules array allows multiple entries with upperTokenLimit: -1 but the description only calls it a catch-all; update the rules description to clearly state that exactly one fallback rule (upperTokenLimit: -1) should be defined and that defining more than one is not recommended to avoid ambiguous behavior, and optionally add a schema-level validation note (or a custom validation rule) to enforce or warn about multiple -1 entries; reference the rules array, its items object and the upperTokenLimit field when making the change.policies/prompt-compressor/pyproject.toml (1)
11-11: License classifier is redundant under PEP 639.With
setuptools>=77, the combination oflicense = { text = "Apache-2.0" }and the"License :: OSI Approved :: Apache Software License"classifier (line 19) is deprecated. Consider removing the classifier to align with modern practices and avoid future warnings, or simplify tolicense = "Apache-2.0"(string form) and drop the classifier entirely.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/pyproject.toml` at line 11, The license is declared with the table form license = { text = "Apache-2.0" } while also including the classifier "License :: OSI Approved :: Apache Software License", which is redundant under modern setuptools; fix by either removing the classifier entry and keeping license = { text = "Apache-2.0" } or simplify to license = "Apache-2.0" (string form) and drop the classifier "License :: OSI Approved :: Apache Software License" so only the canonical license declaration remains.policies/prompt-compressor/requirements.txt (1)
1-1: Confirm the pinnedcompression-prompt==0.1.2package source.The version is available on PyPI with no known security advisories. The package is sourced from GitHub (https://github.com/hivellm/compression-prompt) and requires Python >=3.8. Note that this dependency is pinned in both
pyproject.tomlandrequirements.txtin the same directory. Consider consolidating to a single source of truth ifpyproject.tomlis the authoritative definition for the built wheel.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/requirements.txt` at line 1, Verify and document the source and compatibility of the pinned dependency compression-prompt==0.1.2 (confirm it comes from https://github.com/hivellm/compression-prompt and supports Python >=3.8), then consolidate dependency declarations so there is a single authoritative source of truth: either keep the pin in pyproject.toml (recommended for building wheels) and remove it from requirements.txt, or vice versa; update the remaining declaration to include the source/URL and a comment noting the Python requirement.policies/prompt-compressor/policy.py (3)
220-222: Bareexcept Exceptionis intentional defensive guard.Acknowledged via the
# pragma: no covercomment; this prevents an upstream library bug from breaking the request path. No change needed, but consider logging aterrorlevel (rather thanwarning) and including the exception type for easier post-mortem in production logs.♻️ Optional tweak
- except Exception as exc: # pragma: no cover - defensive guard for library/runtime issues - LOGGER.warning("PromptCompressor: unexpected compression failure: %s", exc) + except Exception as exc: # pragma: no cover - defensive guard for library/runtime issues + LOGGER.exception("PromptCompressor: unexpected compression failure (%s)", type(exc).__name__) return text, False🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/policy.py` around lines 220 - 222, Change the log level and enrich the message in the exception handler that currently does "LOGGER.warning(...)" (the except block in the PromptCompressor compression flow — look for the LOGGER usage in the compress/attempt_compress method). Replace the warning with LOGGER.error and include the exception's type/name alongside the message and exception instance (e.g., include type(exc).__name__ plus exc) so production logs show the exception class and details for post-mortem while keeping the existing fallback return of (text, False).
25-25: JSONPath support is intentionally minimal; document limitations or adopt a library.The custom resolver only handles
$-rooted, dot-segmented paths with optionalname[index]array access. Common JSONPath features (bracketed string keys like['messages'], multi-index[0][1], recursive descent.., filter expressions, wildcards, escaped dots in keys) are silently rejected. For v0.1 this may be acceptable, but consider either:
- documenting the supported subset prominently in the README/policy docs, or
- delegating to a maintained library (e.g.,
jsonpath-ng) to reduce custom parsing surface and make user-supplied paths behave predictably.Also applies to: 412-453
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/policy.py` at line 25, The custom JSONPath resolver in policy.py (the `_ARRAY_INDEX_RE` regex and the resolver logic around the same module that handles `$`-rooted, dot-segmented paths) is overly limited; either explicitly document the supported subset in the policy/README (call out unsupported features like bracketed string keys, recursive `..`, filters, wildcards, escaped dots, multi-indexing) or replace the custom parsing with a maintained library (e.g., use `jsonpath-ng` to evaluate user-supplied paths), updating the resolver entrypoint to call the library and adjusting tests and error messages accordingly so unsupported inputs are handled predictably.
379-409: Minor: redundant regex match inset_value_at_jsonpath.Line 389 calls
_ARRAY_INDEX_RE.match(final_component), then line 391 callsparse_array_component(final_component)which re-runs the same regex. Same redundancy exists inget_path_component(lines 424–426). Negligible cost, but trivially deduplicable by inlining the match result.♻️ Proposed refactor
- final_component = components[-1] - match = _ARRAY_INDEX_RE.match(final_component) - if match: - array_name, index = parse_array_component(final_component) + final_component = components[-1] + match = _ARRAY_INDEX_RE.match(final_component) + if match: + array_name = match.group(1) + index = int(match.group(2))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/policy.py` around lines 379 - 409, The code redundantly calls _ARRAY_INDEX_RE.match(final_component) and then calls parse_array_component(final_component) which repeats the regex; update set_value_at_jsonpath (and similarly get_path_component) to reuse the initial match result: store match = _ARRAY_INDEX_RE.match(final_component), and if match is truthy extract the array name and index from match.groups() (or call a new parse_array_component_from_match(match) helper) instead of re-invoking parse_array_component(final_component); adjust error handling to use the reused match-derived values so the regex is executed only once per component.policies/prompt-compressor/test_policy.py (1)
62-68: UseClassVarannotation for the shared instance registry.Ruff (RUF012) flags the mutable list as a class attribute without
ClassVartyping. Sinceinstancesis intentionally shared across instances for test inspection, annotate it explicitly to silence the lint and document intent.♻️ Proposed refactor
+from typing import ClassVar @@ class FakeCompressor: - instances: list["FakeCompressor"] = [] + instances: ClassVar[list["FakeCompressor"]] = []🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@policies/prompt-compressor/test_policy.py` around lines 62 - 68, The class-level mutable registry FakeCompressor.instances should be annotated as a ClassVar to satisfy RUF012 and document intent; import ClassVar from typing and change the annotation to ClassVar[list["FakeCompressor"]] for the instances attribute in the FakeCompressor class so the shared list is explicitly marked as a class variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/prompt-compressor/v0.1/docs/prompt-compressor.md`:
- Around line 263-265: The "Compression Efficiency" note is ambiguous; update
the text for clarity by stating that achieved compression ratios are often less
aggressive than the configured/expected target because protected content and
conservative defaults limit how much can be removed — e.g., replace the existing
sentence about a "considerable gap" with a clear statement that the policy
typically yields less reduction than the target (not that the compressed prompt
becomes larger than the original) and mention that protected regions and
retention ratios are the primary constraints.
In `@policies/prompt-compressor/policy.py`:
- Around line 9-16: The imports of Compressor, CompressorConfig and the
exceptions CompressionError, InputTooShortError, NegativeGainError rely on the
non-existent PyPI package declared as compression-prompt==0.1.2; fix by updating
the dependency to the correct package name/version or switching to a supported
alternative and adjust imports accordingly (e.g., replace imports from
compression_prompt with the real package or local module providing
Compressor/CompressorConfig and the three exception classes), and ensure
pyproject.toml reflects that valid package source (or add the private index
configuration) so the module can import Compressor, CompressorConfig,
CompressionError, InputTooShortError, and NegativeGainError successfully.
In `@policies/prompt-compressor/pyproject.toml`:
- Around line 28-36: The pyproject config currently uses package auto-discovery
with [tool.setuptools] packages = ["prompt_compressor_v0"] and
[tool.setuptools.package-dir] prompt_compressor_v0 = "." which causes
test_policy.py to be packaged; fix by preventing test files from being included:
either add a [tool.setuptools.packages.find] section with skip = ['*test*'] to
exclude test modules, or replace the auto-discovery with an explicit py-modules
= ["policy"] entry so only the intended module is packaged, or move
test_policy.py out of the package root into a top-level tests/ directory; update
the prompt_compressor_v0/package-dir or packages settings accordingly so tests
are not shipped.
---
Nitpick comments:
In `@docs/prompt-compressor/v0.1/docs/prompt-compressor.md`:
- Around line 184-189: Clarify that in token mode (e.g., the fallback rule with
upperTokenLimit: -1, type: token, value: 1200) the rule is a no-op when the
prompt's estimated token count is already <= value: the implementation's
resolve_ratio function returns None if target_tokens >= estimated_tokens, so add
a short note stating the rule only applies when estimated_tokens > value and is
skipped otherwise.
- Around line 50-58: Update the "Selective Compression Tags" section to document
handling of malformed tag pairs for `<APIP-COMPRESS>` and `</APIP-COMPRESS>`:
state that an unmatched opening tag compresses until end-of-string (i.e., an
unclosed `<APIP-COMPRESS>` will compress the trailing region) and that stray
closing tags (`</APIP-COMPRESS>`) are ignored/dropped; also clarify that tags
are removed from the final forwarded text and that behavior applies when using
selective-region compression in the policy.
In `@policies/prompt-compressor/__init__.py`:
- Around line 1-3: Current __version__ in policies/prompt-compressor/__init__.py
is hardcoded as "0.1.0" which can drift from pyproject.toml; replace the
hardcoded __version__ with a runtime lookup using
importlib.metadata.version("prompt-compressor-v0") (or importlib_metadata for
older Python) and set __version__ to that value, adding a fallback (e.g.,
default string or empty) and handling PackageNotFoundError so imports won’t fail
when metadata is unavailable; update the module-level symbol __version__ and
ensure any import names remain unchanged.
In `@policies/prompt-compressor/policy-definition.yaml`:
- Around line 39-56: The schema currently allows any number for the "value"
property but the implementation truncates fractional values in token mode;
update the policy-definition.yaml to validate and document per-type semantics:
add "exclusiveMinimum: 0" to "value" to reject non-positive numbers, and enforce
integer-only for token mode (e.g., use an if:
{properties:{type:{const:"token"}}} then: {properties:{value:{multipleOf:1}},
required:["value"]}) or alternately state in the "value" description that token
mode truncates fractions; reference the "type" enum (ratio|token), the "value"
field, and required list (upperTokenLimit/type/value) when making the change.
- Around line 34-38: The schema for upperTokenLimit currently allows any integer
and should enforce minimum: -1 to prevent invalid negative values; update the
policy-definition.yaml schema for the upperTokenLimit property by adding
"minimum: -1" under upperTokenLimit (keeping the existing type and description)
so invalid values like -5 fail validation at config load rather than at runtime.
- Around line 22-32: The rules array allows multiple entries with
upperTokenLimit: -1 but the description only calls it a catch-all; update the
rules description to clearly state that exactly one fallback rule
(upperTokenLimit: -1) should be defined and that defining more than one is not
recommended to avoid ambiguous behavior, and optionally add a schema-level
validation note (or a custom validation rule) to enforce or warn about multiple
-1 entries; reference the rules array, its items object and the upperTokenLimit
field when making the change.
In `@policies/prompt-compressor/policy.py`:
- Around line 220-222: Change the log level and enrich the message in the
exception handler that currently does "LOGGER.warning(...)" (the except block in
the PromptCompressor compression flow — look for the LOGGER usage in the
compress/attempt_compress method). Replace the warning with LOGGER.error and
include the exception's type/name alongside the message and exception instance
(e.g., include type(exc).__name__ plus exc) so production logs show the
exception class and details for post-mortem while keeping the existing fallback
return of (text, False).
- Line 25: The custom JSONPath resolver in policy.py (the `_ARRAY_INDEX_RE`
regex and the resolver logic around the same module that handles `$`-rooted,
dot-segmented paths) is overly limited; either explicitly document the supported
subset in the policy/README (call out unsupported features like bracketed string
keys, recursive `..`, filters, wildcards, escaped dots, multi-indexing) or
replace the custom parsing with a maintained library (e.g., use `jsonpath-ng` to
evaluate user-supplied paths), updating the resolver entrypoint to call the
library and adjusting tests and error messages accordingly so unsupported inputs
are handled predictably.
- Around line 379-409: The code redundantly calls
_ARRAY_INDEX_RE.match(final_component) and then calls
parse_array_component(final_component) which repeats the regex; update
set_value_at_jsonpath (and similarly get_path_component) to reuse the initial
match result: store match = _ARRAY_INDEX_RE.match(final_component), and if match
is truthy extract the array name and index from match.groups() (or call a new
parse_array_component_from_match(match) helper) instead of re-invoking
parse_array_component(final_component); adjust error handling to use the reused
match-derived values so the regex is executed only once per component.
In `@policies/prompt-compressor/pyproject.toml`:
- Line 11: The license is declared with the table form license = { text =
"Apache-2.0" } while also including the classifier "License :: OSI Approved ::
Apache Software License", which is redundant under modern setuptools; fix by
either removing the classifier entry and keeping license = { text = "Apache-2.0"
} or simplify to license = "Apache-2.0" (string form) and drop the classifier
"License :: OSI Approved :: Apache Software License" so only the canonical
license declaration remains.
In `@policies/prompt-compressor/README.md`:
- Around line 1-3: Update the README for the prompt-compressor package to
include a one-sentence placeholder summary plus a short "Configuration" section
that lists the package entry points and where to configure behavior (e.g.,
environment variables, config files, or middleware hooks used by the
prompt-compressor package) and add a direct link to
docs/prompt-compressor/v0.1/docs/prompt-compressor.md so external devs (pip/
PyPI consumers) can quickly find usage and configuration details; ensure the
README still includes the original package description and the linked docs path.
In `@policies/prompt-compressor/requirements.txt`:
- Line 1: Verify and document the source and compatibility of the pinned
dependency compression-prompt==0.1.2 (confirm it comes from
https://github.com/hivellm/compression-prompt and supports Python >=3.8), then
consolidate dependency declarations so there is a single authoritative source of
truth: either keep the pin in pyproject.toml (recommended for building wheels)
and remove it from requirements.txt, or vice versa; update the remaining
declaration to include the source/URL and a comment noting the Python
requirement.
In `@policies/prompt-compressor/test_policy.py`:
- Around line 62-68: The class-level mutable registry FakeCompressor.instances
should be annotated as a ClassVar to satisfy RUF012 and document intent; import
ClassVar from typing and change the annotation to
ClassVar[list["FakeCompressor"]] for the instances attribute in the
FakeCompressor class so the shared list is explicitly marked as a class
variable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 513a180b-0e0b-435b-9175-e18c48c7d2fd
📒 Files selected for processing (10)
docs/README.mddocs/prompt-compressor/v0.1/docs/prompt-compressor.mddocs/prompt-compressor/v0.1/metadata.jsonpolicies/prompt-compressor/README.mdpolicies/prompt-compressor/__init__.pypolicies/prompt-compressor/policy-definition.yamlpolicies/prompt-compressor/policy.pypolicies/prompt-compressor/pyproject.tomlpolicies/prompt-compressor/requirements.txtpolicies/prompt-compressor/test_policy.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Update pyproject.toml
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Document and enforce that the `rules` array must include at least one fallback rule with `upperTokenLimit: -1`. The docs were updated to clarify the fallback requirement and rule evaluation order, and the policy schema (policy-definition.yaml) now uses `contains`/`const`/`minContains` to validate presence of a catch-all rule.
Require fallback rule for prompt-compressor
Purpose
Fix wso2/api-platform#1714
Related PR: #173
Add the
prompt-compressorpolicy to reduce prompt size before upstream LLM calls and document how to include and configure it.Goals
<APIP-COMPRESS>tags.docs/prompt-compressor/v0.1.Approach
prompt-compressorpolicy package underpolicies/prompt-compressor.policy-definition.yaml, package metadata, requirements, and README.docs/prompt-compressor/v0.1.build.yamlentry:Documentation
Added documentation:
docs/prompt-compressor/v0.1/docs/prompt-compressor.mddocs/prompt-compressor/v0.1/metadata.jsonAutomation tests
Security checks
Samples
Included sample policy configurations in the Prompt Compressor documentation.
Related PRs
N/A
Test environment
Local development environment.