Repository navigation
Issue #601: consolidate LLM client registry resolution #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| import types | ||
| from pathlib import Path | ||
|
|
||
| from scripts.langchain import _llm_client | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
|
|
||
|
|
||
| def _module_source(path: str) -> str: | ||
| return (REPO_ROOT / path).read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def test_langchain_client_uses_llm_registry_as_single_resolution_source() -> None: | ||
| source = _module_source("tools/langchain_client.py") | ||
| tree = ast.parse(source) | ||
|
|
||
| local_classes = { | ||
| node.name | ||
| for node in tree.body | ||
| if isinstance(node, ast.ClassDef) | ||
| } | ||
| local_function_names = { | ||
| node.name | ||
| for node in tree.body | ||
| if isinstance(node, ast.FunctionDef) | ||
| } | ||
|
|
||
| assert "ModelRegistryEntry" not in local_classes | ||
| assert "SlotDefinition" not in local_classes | ||
| assert "json.loads" not in source | ||
| assert "from tools.llm_registry import" in source | ||
|
|
||
| # Compatibility wrappers are allowed, but the resolver implementation must | ||
| # live in tools.llm_registry so scripts and providers share one source. | ||
| assert {"build_chat_client", "build_chat_clients"} <= local_function_names | ||
| assert "resolve_slots(" in source | ||
| assert "load_slot_config(" in source | ||
|
|
||
|
|
||
| def test_script_llm_client_adapter_delegates_to_langchain_client(monkeypatch) -> None: | ||
| calls: list[dict[str, object]] = [] | ||
| sentinel_client = object() | ||
|
|
||
| def fake_build_chat_client(**kwargs: object) -> object: | ||
| calls.append(kwargs) | ||
| return types.SimpleNamespace( | ||
| client=sentinel_client, | ||
| provider="openai", | ||
| model="gpt-configured", | ||
| provider_label="openai/gpt-configured", | ||
| ) | ||
|
|
||
| monkeypatch.setattr(_llm_client, "build_client", lambda **kwargs: fake_build_chat_client(**kwargs)) | ||
|
|
||
| client, label = _llm_client.get_llm_client( | ||
| provider="openai", | ||
| model="gpt-configured", | ||
| return_field="provider_label", | ||
| ) | ||
|
|
||
| assert client is sentinel_client | ||
| assert label == "openai/gpt-configured" | ||
| assert calls == [ | ||
| { | ||
| "model": "gpt-configured", | ||
| "provider": "openai", | ||
| "force_openai": False, | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.