48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""#720: the notebooks container installs the workspace without the
|
|
``llm`` extra (no langchain, no sqlalchemy). ``llm.config``,
|
|
``llm.links`` and ``llm.lineage`` must import there anyway — the pool
|
|
exports are resolved lazily, and ``llm.evidence`` only touches
|
|
sqlalchemy when a pgvector query actually runs.
|
|
|
|
#573: ``llm.client`` (the notebook-side ``LlmClient``) is httpx-only and
|
|
must import there too — it's the one module notebooks are expected to
|
|
import directly."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
_PROBE = """
|
|
import sys, builtins
|
|
_real = builtins.__import__
|
|
def _fake(name, *a, **k):
|
|
if name.split('.')[0] in {'langchain_core', 'langchain_postgres', 'langchain_ollama', 'sqlalchemy'}:
|
|
raise ModuleNotFoundError(name)
|
|
return _real(name, *a, **k)
|
|
builtins.__import__ = _fake
|
|
import llm.config, llm.links, llm.lineage, llm.evidence # must not need langchain/sqlalchemy
|
|
import llm.client # #573: notebook-side LlmClient — httpx only
|
|
import llm
|
|
print('ok', llm.LlmConfig.__name__, llm.client.LlmClient.__name__)
|
|
"""
|
|
|
|
|
|
def test_config_links_lineage_evidence_import_without_langchain_or_sqlalchemy():
|
|
r = subprocess.run(
|
|
[sys.executable, "-c", _PROBE], capture_output=True, text=True, check=False
|
|
)
|
|
assert r.returncode == 0, r.stderr[-800:]
|
|
assert "ok LlmConfig LlmClient" in r.stdout
|
|
|
|
|
|
def test_pool_exports_resolve_lazily():
|
|
llm = importlib.import_module("llm")
|
|
assert llm.HostPool.__name__ == "HostPool"
|
|
assert llm.PoolEmbeddings.__name__ == "PoolEmbeddings"
|
|
with pytest.raises(AttributeError):
|
|
_ = llm.NoSuchName
|