pydantic-ai-contextfetch 0.1.0__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.
- pydantic_ai_contextfetch-0.1.0/.gitignore +7 -0
- pydantic_ai_contextfetch-0.1.0/LICENSE +21 -0
- pydantic_ai_contextfetch-0.1.0/PKG-INFO +68 -0
- pydantic_ai_contextfetch-0.1.0/README.md +49 -0
- pydantic_ai_contextfetch-0.1.0/pydantic_ai_contextfetch/__init__.py +102 -0
- pydantic_ai_contextfetch-0.1.0/pyproject.toml +33 -0
- pydantic_ai_contextfetch-0.1.0/tests/test_live.py +19 -0
- pydantic_ai_contextfetch-0.1.0/tests/test_toolset.py +109 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ContextFetch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pydantic-ai-contextfetch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ContextFetch web search and page reading tools for Pydantic AI
|
|
5
|
+
Project-URL: Homepage, https://contextfetch.dev
|
|
6
|
+
Project-URL: Documentation, https://contextfetch.dev/docs/reference
|
|
7
|
+
Project-URL: Repository, https://github.com/lachy3433/pydantic-ai-contextfetch
|
|
8
|
+
Author: ContextFetch
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Framework :: Pydantic
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: contextfetch<1.0.0,>=0.1.0
|
|
17
|
+
Requires-Dist: pydantic-ai-slim>=1.0.0
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# pydantic-ai-contextfetch
|
|
21
|
+
|
|
22
|
+
[ContextFetch](https://contextfetch.dev) web search and page reading tools for [Pydantic AI](https://ai.pydantic.dev), as a toolset.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pydantic-ai-contextfetch
|
|
26
|
+
export CONTEXTFETCH_API_KEY="your-api-key" # optional: without a key, requests use the keyless tier
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from pydantic_ai import Agent
|
|
31
|
+
|
|
32
|
+
from pydantic_ai_contextfetch import ContextFetchToolset
|
|
33
|
+
|
|
34
|
+
agent = Agent('openai:gpt-5.2', toolsets=[ContextFetchToolset()])
|
|
35
|
+
result = agent.run_sync('What changed in the latest Python release?')
|
|
36
|
+
print(result.output)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Tools
|
|
40
|
+
|
|
41
|
+
- `contextfetch_search(query, include_domains?, exclude_domains?, start_published_date?)`: web search. Returns a list
|
|
42
|
+
of `{title, url, published_date, content}`, where `content` is the page as Markdown: by default only the parts
|
|
43
|
+
relevant to the query.
|
|
44
|
+
- `contextfetch_read(url, query?)`: one page as Markdown. With `query`, only the parts relevant to it. A bad or
|
|
45
|
+
unreachable URL raises `ModelRetry`, so the model can correct it.
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
ContextFetchToolset(
|
|
51
|
+
api_key=None, # defaults to CONTEXTFETCH_API_KEY
|
|
52
|
+
num_results=5, # results per search, 1 to 25
|
|
53
|
+
content='pruned_context', # or 'text' for whole pages
|
|
54
|
+
id=None, # toolset id for durable execution
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To expose only one tool, use Pydantic AI's toolset filtering:
|
|
59
|
+
`ContextFetchToolset().filtered(lambda ctx, tool: tool.name == 'contextfetch_search')`.
|
|
60
|
+
|
|
61
|
+
## Tests
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
uv run --group test pytest tests # unit tests, no network
|
|
65
|
+
CONTEXTFETCH_API_KEY=... uv run --group test pytest tests/test_live.py # live, 2 credits
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
MIT licensed.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# pydantic-ai-contextfetch
|
|
2
|
+
|
|
3
|
+
[ContextFetch](https://contextfetch.dev) web search and page reading tools for [Pydantic AI](https://ai.pydantic.dev), as a toolset.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install pydantic-ai-contextfetch
|
|
7
|
+
export CONTEXTFETCH_API_KEY="your-api-key" # optional: without a key, requests use the keyless tier
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from pydantic_ai import Agent
|
|
12
|
+
|
|
13
|
+
from pydantic_ai_contextfetch import ContextFetchToolset
|
|
14
|
+
|
|
15
|
+
agent = Agent('openai:gpt-5.2', toolsets=[ContextFetchToolset()])
|
|
16
|
+
result = agent.run_sync('What changed in the latest Python release?')
|
|
17
|
+
print(result.output)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Tools
|
|
21
|
+
|
|
22
|
+
- `contextfetch_search(query, include_domains?, exclude_domains?, start_published_date?)`: web search. Returns a list
|
|
23
|
+
of `{title, url, published_date, content}`, where `content` is the page as Markdown: by default only the parts
|
|
24
|
+
relevant to the query.
|
|
25
|
+
- `contextfetch_read(url, query?)`: one page as Markdown. With `query`, only the parts relevant to it. A bad or
|
|
26
|
+
unreachable URL raises `ModelRetry`, so the model can correct it.
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
ContextFetchToolset(
|
|
32
|
+
api_key=None, # defaults to CONTEXTFETCH_API_KEY
|
|
33
|
+
num_results=5, # results per search, 1 to 25
|
|
34
|
+
content='pruned_context', # or 'text' for whole pages
|
|
35
|
+
id=None, # toolset id for durable execution
|
|
36
|
+
)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To expose only one tool, use Pydantic AI's toolset filtering:
|
|
40
|
+
`ContextFetchToolset().filtered(lambda ctx, tool: tool.name == 'contextfetch_search')`.
|
|
41
|
+
|
|
42
|
+
## Tests
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
uv run --group test pytest tests # unit tests, no network
|
|
46
|
+
CONTEXTFETCH_API_KEY=... uv run --group test pytest tests/test_live.py # live, 2 credits
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
MIT licensed.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""ContextFetch web search and page reading tools for Pydantic AI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Literal
|
|
6
|
+
|
|
7
|
+
from contextfetch import ContextFetch, ContextFetchError
|
|
8
|
+
from pydantic_ai import ModelRetry
|
|
9
|
+
from pydantic_ai.toolsets import FunctionToolset
|
|
10
|
+
|
|
11
|
+
__all__ = ("ContextFetchToolset",)
|
|
12
|
+
|
|
13
|
+
Content = Literal["pruned_context", "text"]
|
|
14
|
+
"""`"pruned_context"`: only the parts of each page relevant to the query. `"text"`: the whole page as Markdown."""
|
|
15
|
+
|
|
16
|
+
_RESULT_KEY = {"pruned_context": "prunedContext", "text": "text"}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ContextFetchToolset(FunctionToolset[Any]):
|
|
20
|
+
"""A toolset with two tools that share one ContextFetch client.
|
|
21
|
+
|
|
22
|
+
- `contextfetch_search`: web search; each result carries the page content as Markdown.
|
|
23
|
+
- `contextfetch_read`: one URL as Markdown, optionally only the parts relevant to a question.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pydantic_ai import Agent
|
|
27
|
+
|
|
28
|
+
from pydantic_ai_contextfetch import ContextFetchToolset
|
|
29
|
+
|
|
30
|
+
agent = Agent('openai:gpt-5.2', toolsets=[ContextFetchToolset()])
|
|
31
|
+
```
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
api_key: str | None = None,
|
|
37
|
+
*,
|
|
38
|
+
num_results: int = 5,
|
|
39
|
+
content: Content = "pruned_context",
|
|
40
|
+
id: str | None = None,
|
|
41
|
+
):
|
|
42
|
+
"""Creates the toolset.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
api_key: The ContextFetch API key. Defaults to the `CONTEXTFETCH_API_KEY` environment variable;
|
|
46
|
+
without either, requests use the keyless tier.
|
|
47
|
+
num_results: Results per search (1 to 25). Defaults to 5.
|
|
48
|
+
content: Which page content search results carry. Defaults to `"pruned_context"`.
|
|
49
|
+
id: Optional ID for the toolset, used for durable execution environments.
|
|
50
|
+
"""
|
|
51
|
+
client = ContextFetch(api_key)
|
|
52
|
+
key = _RESULT_KEY[content]
|
|
53
|
+
|
|
54
|
+
def contextfetch_search(
|
|
55
|
+
query: str,
|
|
56
|
+
include_domains: list[str] | None = None,
|
|
57
|
+
exclude_domains: list[str] | None = None,
|
|
58
|
+
start_published_date: str | None = None,
|
|
59
|
+
) -> list[dict[str, Any]]:
|
|
60
|
+
"""Searches the web and returns the top results with their page content as Markdown.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
query: The web search query.
|
|
64
|
+
include_domains: Only return results from these domains.
|
|
65
|
+
exclude_domains: Never return results from these domains.
|
|
66
|
+
start_published_date: Only return pages published on or after this date (YYYY-MM-DD).
|
|
67
|
+
"""
|
|
68
|
+
response = client.search(
|
|
69
|
+
query,
|
|
70
|
+
num_results=num_results,
|
|
71
|
+
include_domains=include_domains,
|
|
72
|
+
exclude_domains=exclude_domains,
|
|
73
|
+
start_published_date=start_published_date,
|
|
74
|
+
text=content == "text",
|
|
75
|
+
pruned_context=content == "pruned_context",
|
|
76
|
+
)
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
79
|
+
"title": r.get("title"),
|
|
80
|
+
"url": r.get("url"),
|
|
81
|
+
"published_date": r.get("publishedDate"),
|
|
82
|
+
"content": r.get(key) or "",
|
|
83
|
+
}
|
|
84
|
+
for r in response.get("results", [])
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
def contextfetch_read(url: str, query: str | None = None) -> str:
|
|
88
|
+
"""Reads a web page and returns it as Markdown.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
url: The URL of the page.
|
|
92
|
+
query: If set, only the parts of the page relevant to this question are returned.
|
|
93
|
+
"""
|
|
94
|
+
try:
|
|
95
|
+
return client.read(url, query=query).markdown
|
|
96
|
+
except ContextFetchError as e:
|
|
97
|
+
# A bad or unreachable URL is something the model can fix; auth, credit and server errors are not.
|
|
98
|
+
if e.status in (400, 404, 422):
|
|
99
|
+
raise ModelRetry(str(e)) from e
|
|
100
|
+
raise
|
|
101
|
+
|
|
102
|
+
super().__init__([contextfetch_search, contextfetch_read], id=id)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pydantic-ai-contextfetch"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "ContextFetch web search and page reading tools for Pydantic AI"
|
|
9
|
+
authors = [{ name = "ContextFetch" }]
|
|
10
|
+
license = "MIT"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Framework :: Pydantic",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"pydantic-ai-slim>=1.0.0",
|
|
21
|
+
"contextfetch>=0.1.0,<1.0.0",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://contextfetch.dev"
|
|
26
|
+
Documentation = "https://contextfetch.dev/docs/reference"
|
|
27
|
+
Repository = "https://github.com/lachy3433/pydantic-ai-contextfetch"
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
test = ["pytest>=8"]
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.sdist]
|
|
33
|
+
only-include = ["pydantic_ai_contextfetch", "tests", "README.md", "LICENSE"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Live check against the real API (2 credits). Skipped unless CONTEXTFETCH_API_KEY is set."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from pydantic_ai_contextfetch import ContextFetchToolset
|
|
10
|
+
|
|
11
|
+
pytestmark = pytest.mark.skipif(not os.environ.get("CONTEXTFETCH_API_KEY"), reason="needs CONTEXTFETCH_API_KEY")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_live() -> None:
|
|
15
|
+
tools = ContextFetchToolset(num_results=2).tools
|
|
16
|
+
results = tools["contextfetch_search"].function("python asyncio TaskGroup")
|
|
17
|
+
assert results and results[0]["url"].startswith("http") and results[0]["content"]
|
|
18
|
+
page = tools["contextfetch_read"].function("https://docs.python.org/3/library/asyncio-task.html", query="TaskGroup")
|
|
19
|
+
assert "TaskGroup" in page
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Unit tests: the SDK's HTTP call is patched, so nothing touches the network."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from contextfetch import ContextFetch, ContextFetchError
|
|
10
|
+
from pydantic_ai import Agent, ModelRetry
|
|
11
|
+
from pydantic_ai.messages import ModelMessage, ModelResponse, TextPart, ToolCallPart, ToolReturnPart
|
|
12
|
+
from pydantic_ai.models.function import AgentInfo, FunctionModel
|
|
13
|
+
|
|
14
|
+
from pydantic_ai_contextfetch import ContextFetchToolset
|
|
15
|
+
|
|
16
|
+
RESULTS = [
|
|
17
|
+
{"url": "https://example.com/a", "title": "A", "publishedDate": "2026-01-02", "text": "# A", "prunedContext": "chunk A"},
|
|
18
|
+
{"url": "https://example.com/b", "title": None, "text": "# B", "prunedContext": "chunk B"},
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def calls(monkeypatch: pytest.MonkeyPatch) -> list[dict[str, Any]]:
|
|
24
|
+
calls: list[dict[str, Any]] = []
|
|
25
|
+
monkeypatch.delenv("CONTEXTFETCH_API_KEY", raising=False)
|
|
26
|
+
|
|
27
|
+
def request(self: ContextFetch, method: str, path: str, body: Any = None, **_: Any) -> tuple[bytes, dict]:
|
|
28
|
+
calls.append({"method": method, "path": path, "body": body, "api_key": self.api_key})
|
|
29
|
+
if path.startswith("/r/https://missing"):
|
|
30
|
+
raise ContextFetchError("not found", status=404)
|
|
31
|
+
if path.startswith("/r/"):
|
|
32
|
+
return b"# Page", {}
|
|
33
|
+
return json.dumps({"results": RESULTS[: body["numResults"]]}).encode(), {}
|
|
34
|
+
|
|
35
|
+
monkeypatch.setattr(ContextFetch, "_request", request)
|
|
36
|
+
return calls
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _call(toolset: ContextFetchToolset, tool: str, args: dict[str, Any]) -> Any:
|
|
40
|
+
"""Runs one tool call through a real Agent with a scripted model, returning the tool's return value."""
|
|
41
|
+
|
|
42
|
+
def model(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
|
|
43
|
+
if len(messages) == 1:
|
|
44
|
+
return ModelResponse(parts=[ToolCallPart(tool, args)])
|
|
45
|
+
return ModelResponse(parts=[TextPart("done")])
|
|
46
|
+
|
|
47
|
+
result = Agent(FunctionModel(model), toolsets=[toolset]).run_sync("go")
|
|
48
|
+
returns = [p for m in result.all_messages() for p in m.parts if isinstance(p, ToolReturnPart)]
|
|
49
|
+
return returns[0].content
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_tool_schemas() -> None:
|
|
53
|
+
def model(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
|
|
54
|
+
tools = {t.name: t for t in info.function_tools}
|
|
55
|
+
assert set(tools) == {"contextfetch_search", "contextfetch_read"}
|
|
56
|
+
search = tools["contextfetch_search"]
|
|
57
|
+
assert search.parameters_json_schema["required"] == ["query"]
|
|
58
|
+
assert "YYYY-MM-DD" in search.parameters_json_schema["properties"]["start_published_date"]["description"]
|
|
59
|
+
assert tools["contextfetch_read"].parameters_json_schema["required"] == ["url"]
|
|
60
|
+
return ModelResponse(parts=[TextPart("done")])
|
|
61
|
+
|
|
62
|
+
Agent(FunctionModel(model), toolsets=[ContextFetchToolset("k")]).run_sync("go")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_search(calls: list[dict[str, Any]]) -> None:
|
|
66
|
+
out = _call(ContextFetchToolset("k", num_results=2), "contextfetch_search", {"query": "q", "include_domains": ["example.com"]})
|
|
67
|
+
assert out == [
|
|
68
|
+
{"title": "A", "url": "https://example.com/a", "published_date": "2026-01-02", "content": "chunk A"},
|
|
69
|
+
{"title": None, "url": "https://example.com/b", "published_date": None, "content": "chunk B"},
|
|
70
|
+
]
|
|
71
|
+
assert calls == [
|
|
72
|
+
{
|
|
73
|
+
"method": "POST",
|
|
74
|
+
"path": "/v1/search",
|
|
75
|
+
"body": {"query": "q", "numResults": 2, "includeDomains": ["example.com"], "contents": {"pruned_context": True}},
|
|
76
|
+
"api_key": "k",
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_search_text_content_and_env_key(calls: list[dict[str, Any]], monkeypatch: pytest.MonkeyPatch) -> None:
|
|
82
|
+
monkeypatch.setenv("CONTEXTFETCH_API_KEY", "env-key")
|
|
83
|
+
out = _call(ContextFetchToolset(num_results=1, content="text"), "contextfetch_search", {"query": "q"})
|
|
84
|
+
assert out[0]["content"] == "# A"
|
|
85
|
+
assert calls[0]["body"]["contents"] == {"text": True}
|
|
86
|
+
assert calls[0]["api_key"] == "env-key"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_read(calls: list[dict[str, Any]]) -> None:
|
|
90
|
+
out = _call(ContextFetchToolset("k"), "contextfetch_read", {"url": "https://example.com/x", "query": "pricing"})
|
|
91
|
+
assert out == "# Page"
|
|
92
|
+
assert calls[0]["path"] == "/r/https://example.com/x?q=pricing"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_read_bad_url_is_retried(calls: list[dict[str, Any]]) -> None:
|
|
96
|
+
toolset = ContextFetchToolset("k")
|
|
97
|
+
read = toolset.tools["contextfetch_read"].function
|
|
98
|
+
with pytest.raises(ModelRetry, match="not found"):
|
|
99
|
+
read("https://missing.example")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_read_auth_error_propagates(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
103
|
+
def request(self: ContextFetch, *a: Any, **k: Any) -> Any:
|
|
104
|
+
raise ContextFetchError("bad key", status=401)
|
|
105
|
+
|
|
106
|
+
monkeypatch.setattr(ContextFetch, "_request", request)
|
|
107
|
+
read = ContextFetchToolset("k").tools["contextfetch_read"].function
|
|
108
|
+
with pytest.raises(ContextFetchError, match="bad key"):
|
|
109
|
+
read("https://example.com")
|