|
6 | 6 | import threading |
7 | 7 | import time |
8 | 8 | import warnings |
9 | | -from typing import Any, Callable, Iterator, Optional, Union, cast |
| 9 | +from typing import Any, Callable, Iterator, Mapping, Optional, Union, cast |
10 | 10 |
|
11 | 11 | from .errors import PageIndexAPIError |
12 | 12 |
|
@@ -78,7 +78,7 @@ def _env_cloud_key(spelling: str, inline: str = "api_key=...") -> str: |
78 | 78 | return key |
79 | 79 |
|
80 | 80 |
|
81 | | -# One argument vocabulary regardless of spelling: every value is shape- |
| 81 | +# One argument vocabulary regardless of spelling: these values are shape- |
82 | 82 | # checked in the constructor, so a wrong type or an empty value refuses |
83 | 83 | # there as a PageIndexAPIError — never later, never silently. |
84 | 84 | _ARG_TYPES: "dict[str, tuple[type, ...]]" = { |
@@ -338,15 +338,15 @@ def __init__( |
338 | 338 | self, |
339 | 339 | api_key: Optional[str] = None, |
340 | 340 | *, |
341 | | - index: Optional[Union[dict[str, Any], str]] = None, |
342 | | - chat: Optional[Union[dict[str, Any], str]] = None, |
| 341 | + index: Optional[Union[Mapping[str, Any], str]] = None, |
| 342 | + chat: Optional[Union[Mapping[str, Any], str]] = None, |
343 | 343 | mode: Optional[str] = None, |
344 | 344 | index_model: Optional[str] = None, |
345 | 345 | chat_model: Optional[str] = None, |
346 | 346 | model: Optional[str] = None, |
347 | 347 | summary_model: Optional[str] = None, |
348 | 348 | retrieve_model: Optional[str] = None, |
349 | | - storage_path: Optional[str] = None, |
| 349 | + storage_path: Optional[Union[str, os.PathLike[str]]] = None, |
350 | 350 | index_backend: Optional[dict[str, Any]] = None, |
351 | 351 | chat_backend: Optional[dict[str, Any]] = None, |
352 | 352 | ): |
@@ -915,6 +915,11 @@ def chat_completions( |
915 | 915 | reasoning_effort=reasoning_effort, extra_body=extra_body, |
916 | 916 | extra_headers=extra_headers, backend=backend, |
917 | 917 | ) |
| 918 | + if not getattr(self, "api_key", None): |
| 919 | + raise PageIndexAPIError( |
| 920 | + "chat_model is empty — it configures nothing, and a local " |
| 921 | + "client has no managed chat to fall back to. Set " |
| 922 | + "chat_model=... to run the agent with your own model.") |
918 | 923 | if (model is not None or max_turns is not None or top_p is not None |
919 | 924 | or max_tokens is not None or reasoning_effort is not None |
920 | 925 | or extra_body is not None or extra_headers is not None |
@@ -1249,8 +1254,9 @@ def as_openai_tools(self, include_management: bool = False, |
1249 | 1254 |
|
1250 | 1255 | def _local_doc_scope(self, doc_id): |
1251 | 1256 | """doc_id for the tool layer: passed through locally (structural |
1252 | | - allowlist), dropped on cloud where scoping is server-side and the |
1253 | | - config helpers keep prompt-level targeting.""" |
| 1257 | + allowlist), dropped on cloud — its tools take no allowlist, so |
| 1258 | + own-model chat and the config helpers target at the prompt level |
| 1259 | + only.""" |
1254 | 1260 | from .agent_tools import _require_doc_selection |
1255 | 1261 | _require_doc_selection(doc_id) |
1256 | 1262 | if not getattr(self, "api_key", None): |
@@ -1612,8 +1618,8 @@ def __init__( |
1612 | 1618 | self, |
1613 | 1619 | api_key: Optional[str] = None, |
1614 | 1620 | *, |
1615 | | - index: Optional[Union[dict[str, Any], str]] = None, |
1616 | | - chat: Optional[Union[dict[str, Any], str]] = None, |
| 1621 | + index: Optional[Union[Mapping[str, Any], str]] = None, |
| 1622 | + chat: Optional[Union[Mapping[str, Any], str]] = None, |
1617 | 1623 | chat_model: Optional[str] = None, |
1618 | 1624 | retrieve_model: Optional[str] = None, |
1619 | 1625 | chat_backend: Optional[dict[str, Any]] = None, |
@@ -1642,14 +1648,14 @@ class PageIndexLocalClient(PageIndexClient): |
1642 | 1648 | def __init__( |
1643 | 1649 | self, |
1644 | 1650 | *, |
1645 | | - index: Optional[Union[dict[str, Any], str]] = None, |
1646 | | - chat: Optional[Union[dict[str, Any], str]] = None, |
| 1651 | + index: Optional[Union[Mapping[str, Any], str]] = None, |
| 1652 | + chat: Optional[Union[Mapping[str, Any], str]] = None, |
1647 | 1653 | index_model: Optional[str] = None, |
1648 | 1654 | chat_model: Optional[str] = None, |
1649 | 1655 | model: Optional[str] = None, |
1650 | 1656 | summary_model: Optional[str] = None, |
1651 | 1657 | retrieve_model: Optional[str] = None, |
1652 | | - storage_path: Optional[str] = None, |
| 1658 | + storage_path: Optional[Union[str, os.PathLike[str]]] = None, |
1653 | 1659 | index_backend: Optional[dict[str, Any]] = None, |
1654 | 1660 | chat_backend: Optional[dict[str, Any]] = None, |
1655 | 1661 | ): |
|
0 commit comments