Files
X-Financial/server/tests/test_knowledge_rag_runtime.py

36 lines
1005 B
Python
Raw Permalink Normal View History

from __future__ import annotations
import pytest
from app.services.knowledge_rag_runtime import (
KnowledgeRagError,
RuntimeModelConfig,
_LightRagRuntime,
)
def test_embedding_probe_error_includes_model_context(monkeypatch) -> None:
runtime = _LightRagRuntime.__new__(_LightRagRuntime)
config = RuntimeModelConfig(
slot="embedding",
provider="GLM",
model="Embedding-3",
endpoint="https://open.bigmodel.cn/api/paas/v4/",
api_key="token",
capability="embedding",
)
def fail_embeddings(*_args, **_kwargs):
raise KnowledgeRagError("token expired")
monkeypatch.setattr(runtime, "_request_embeddings", fail_embeddings)
with pytest.raises(KnowledgeRagError) as exc_info:
runtime._probe_embedding_dimension(config)
message = str(exc_info.value)
assert "slot=embedding" in message
assert "provider=GLM" in message
assert "model=Embedding-3" in message
assert "token expired" in message