contextpress 0.5.1__tar.gz → 0.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {contextpress-0.5.1 → contextpress-0.5.2}/CHANGELOG.md +4 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/PKG-INFO +2 -3
- {contextpress-0.5.1 → contextpress-0.5.2}/README.md +1 -2
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/__init__.py +1 -1
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/llm/adapters.py +34 -9
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/llm_tier_openai.py +1 -3
- {contextpress-0.5.1 → contextpress-0.5.2}/pyproject.toml +1 -1
- contextpress-0.5.2/tests/test_v052.py +32 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/.gitignore +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/CITATION.cff +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/CONTRIBUTING.md +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/LICENSE +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/NOTICE +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/_bootstrap.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/compression.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/core.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/llm/__init__.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/llm/_helpers.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/llm/base.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/models.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/normalizer.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/pipeline.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/profiles.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/py.typed +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/registry.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/stats.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/__init__.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/base.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/budget.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/filler.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/recency.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/repetition.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/strategies/resolution.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/contextpress/warnings_capture.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/benchmark_presets.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/dry_run_preview.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/estimate_and_stats.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/llm_tier_claude.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/llm_tier_gemini.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/examples/llm_tier_ollama.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/__init__.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_budget.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_filler.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_llm_helpers.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_models.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_normalizer.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_pipeline.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_recency.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_repetition.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_resolution.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_stats.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_v03.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_v04.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_v05.py +0 -0
- {contextpress-0.5.1 → contextpress-0.5.2}/tests/test_v051.py +0 -0
|
@@ -4,6 +4,10 @@ All notable changes to `contextpress` are recorded here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.5.2] - 2026-07-22
|
|
8
|
+
|
|
9
|
+
- **`OpenAIBackend`** — optional `api_key` / env (`OPENAI_API_KEY`); no manual client required.
|
|
10
|
+
|
|
7
11
|
## [0.5.1] - 2026-07-22
|
|
8
12
|
|
|
9
13
|
- **`ClaudeBackend`** — shortcut for Anthropic Claude (`ANTHROPIC_API_KEY` or `api_key=`).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: contextpress
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: Deterministic context compression for LLM chat, RAG, and agent pipelines
|
|
5
5
|
Project-URL: Homepage, https://github.com/Taha-azizi/contextpress
|
|
6
6
|
Project-URL: Documentation, https://github.com/Taha-azizi/contextpress#readme
|
|
@@ -459,11 +459,10 @@ Optional constructor knobs: **`llm_min_input_chars`**, **`llm_max_summary_tokens
|
|
|
459
459
|
**Install SDKs** (not bundled): `pip install openai`, `anthropic`, and/or **`ollama`** (for local Ollama), or `pip install "contextpress[llm]"` from this repo’s `pyproject.toml` to pull all optional LLM clients.
|
|
460
460
|
|
|
461
461
|
```python
|
|
462
|
-
from openai import OpenAI
|
|
463
462
|
from contextpress import ContextManager
|
|
464
463
|
from contextpress.llm.adapters import OpenAIBackend
|
|
465
464
|
|
|
466
|
-
backend = OpenAIBackend(
|
|
465
|
+
backend = OpenAIBackend(model="gpt-4o-mini") # uses OPENAI_API_KEY
|
|
467
466
|
cm = ContextManager(
|
|
468
467
|
type="chat",
|
|
469
468
|
llm_backend=backend,
|
|
@@ -218,11 +218,10 @@ Optional constructor knobs: **`llm_min_input_chars`**, **`llm_max_summary_tokens
|
|
|
218
218
|
**Install SDKs** (not bundled): `pip install openai`, `anthropic`, and/or **`ollama`** (for local Ollama), or `pip install "contextpress[llm]"` from this repo’s `pyproject.toml` to pull all optional LLM clients.
|
|
219
219
|
|
|
220
220
|
```python
|
|
221
|
-
from openai import OpenAI
|
|
222
221
|
from contextpress import ContextManager
|
|
223
222
|
from contextpress.llm.adapters import OpenAIBackend
|
|
224
223
|
|
|
225
|
-
backend = OpenAIBackend(
|
|
224
|
+
backend = OpenAIBackend(model="gpt-4o-mini") # uses OPENAI_API_KEY
|
|
226
225
|
cm = ContextManager(
|
|
227
226
|
type="chat",
|
|
228
227
|
llm_backend=backend,
|
|
@@ -27,20 +27,45 @@ def _ollama_response_text(resp: Any) -> str:
|
|
|
27
27
|
|
|
28
28
|
class OpenAIBackend(LLMBackend):
|
|
29
29
|
"""
|
|
30
|
-
Adapter for OpenAI
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
Adapter for **OpenAI** chat APIs.
|
|
31
|
+
|
|
32
|
+
Requires: ``pip install openai``
|
|
33
|
+
|
|
34
|
+
Usage (API key from env ``OPENAI_API_KEY`` or ``api_key=``)::
|
|
33
35
|
|
|
34
|
-
Usage:
|
|
35
|
-
from openai import OpenAI
|
|
36
36
|
from contextpress.llm.adapters import OpenAIBackend
|
|
37
37
|
|
|
38
|
-
backend = OpenAIBackend(
|
|
39
|
-
cm = ContextManager(type
|
|
38
|
+
backend = OpenAIBackend(model=\"gpt-4o-mini\")
|
|
39
|
+
cm = ContextManager(type=\"chat\", llm_backend=backend)
|
|
40
|
+
|
|
41
|
+
Or pass your own client::
|
|
42
|
+
|
|
43
|
+
from openai import OpenAI
|
|
44
|
+
|
|
45
|
+
backend = OpenAIBackend(client=OpenAI(), model=\"gpt-4o-mini\")
|
|
40
46
|
"""
|
|
41
47
|
|
|
42
|
-
def __init__(
|
|
43
|
-
self
|
|
48
|
+
def __init__(
|
|
49
|
+
self,
|
|
50
|
+
client: Any | None = None,
|
|
51
|
+
model: str = "gpt-4o-mini",
|
|
52
|
+
*,
|
|
53
|
+
api_key: str | None = None,
|
|
54
|
+
):
|
|
55
|
+
if client is not None:
|
|
56
|
+
self.client = client
|
|
57
|
+
self.model = model
|
|
58
|
+
return
|
|
59
|
+
try:
|
|
60
|
+
from openai import OpenAI
|
|
61
|
+
except ImportError as exc:
|
|
62
|
+
raise ImportError(
|
|
63
|
+
"OpenAIBackend requires the 'openai' package. " "Install with: pip install openai"
|
|
64
|
+
) from exc
|
|
65
|
+
key = api_key or os.environ.get("OPENAI_API_KEY")
|
|
66
|
+
if not key:
|
|
67
|
+
raise ValueError("Set OPENAI_API_KEY or pass api_key= for OpenAIBackend")
|
|
68
|
+
self.client = OpenAI(api_key=key)
|
|
44
69
|
self.model = model
|
|
45
70
|
|
|
46
71
|
def summarize(self, text: str, max_tokens: int) -> str:
|
|
@@ -17,8 +17,6 @@ from __future__ import annotations
|
|
|
17
17
|
import os
|
|
18
18
|
import sys
|
|
19
19
|
|
|
20
|
-
from openai import OpenAI
|
|
21
|
-
|
|
22
20
|
from contextpress import ContextManager
|
|
23
21
|
from contextpress.llm.adapters import OpenAIBackend
|
|
24
22
|
|
|
@@ -35,7 +33,7 @@ def main() -> None:
|
|
|
35
33
|
{"role": "user", "content": "And numpy? " * 80},
|
|
36
34
|
]
|
|
37
35
|
|
|
38
|
-
backend = OpenAIBackend(
|
|
36
|
+
backend = OpenAIBackend(model="gpt-4o-mini")
|
|
39
37
|
cm = ContextManager(
|
|
40
38
|
type="chat",
|
|
41
39
|
llm_backend=backend,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from unittest.mock import MagicMock, patch
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from contextpress.llm.adapters import OpenAIBackend
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_openai_backend_with_client():
|
|
10
|
+
client = MagicMock()
|
|
11
|
+
backend = OpenAIBackend(client=client, model="gpt-4o-mini")
|
|
12
|
+
assert backend.client is client
|
|
13
|
+
assert backend.model == "gpt-4o-mini"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_openai_backend_requires_api_key():
|
|
17
|
+
mock_openai = MagicMock()
|
|
18
|
+
with patch.dict(os.environ, {}, clear=True):
|
|
19
|
+
with patch.dict("sys.modules", {"openai": mock_openai}):
|
|
20
|
+
with pytest.raises(ValueError, match="OPENAI_API_KEY"):
|
|
21
|
+
OpenAIBackend()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_openai_backend_from_api_key():
|
|
25
|
+
mock_module = MagicMock()
|
|
26
|
+
mock_client = MagicMock()
|
|
27
|
+
mock_module.OpenAI.return_value = mock_client
|
|
28
|
+
with patch.dict(os.environ, {"OPENAI_API_KEY": "sk-test"}):
|
|
29
|
+
with patch.dict("sys.modules", {"openai": mock_module}):
|
|
30
|
+
backend = OpenAIBackend(model="gpt-4o-mini")
|
|
31
|
+
assert backend.client is mock_client
|
|
32
|
+
mock_module.OpenAI.assert_called_once_with(api_key="sk-test")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|