Add RAG basic implementation
This commit is contained in:
@@ -160,3 +160,38 @@ def test_vat_can_be_reconfigured_for_another_regime(monkeypatch):
|
||||
_env(monkeypatch, EST_PRICING__VAT__DEFAULT_RATES='{"ru": 0.0, "eu": 0.0}')
|
||||
assert Settings().pricing.vat.default_rates["ru"] == 0.0
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------- RAG
|
||||
|
||||
|
||||
def test_rag_defaults_are_off_and_conservative(monkeypatch):
|
||||
_env(monkeypatch)
|
||||
r = Settings().rag
|
||||
assert (r.enabled, r.provider, r.model, r.top_k, r.min_similarity) == (False, "openai", "text-embedding-3-small", 3, 0.55)
|
||||
|
||||
|
||||
def test_enabled_rag_with_openai_needs_a_key(monkeypatch):
|
||||
_env(monkeypatch, EST_RAG__ENABLED="true")
|
||||
with pytest.raises(ValidationError, match="no API key"):
|
||||
Settings()
|
||||
|
||||
|
||||
def test_the_rag_key_falls_back_to_the_llm_openai_key(monkeypatch):
|
||||
_env(monkeypatch, EST_RAG__ENABLED="true", EST_LLM__OPENAI__API_KEY="sk-from-llm")
|
||||
s = Settings()
|
||||
assert s.rag_api_key() == "sk-from-llm" and "sk-from-llm" not in repr(s)
|
||||
_env(monkeypatch, EST_RAG__API_KEY="sk-own")
|
||||
assert Settings().rag_api_key() == "sk-own"
|
||||
|
||||
|
||||
def test_the_hash_provider_needs_no_key(monkeypatch):
|
||||
_env(monkeypatch, EST_RAG__ENABLED="true", EST_RAG__PROVIDER="hash")
|
||||
assert Settings().rag.provider == "hash"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key,value", [("TOP_K", "0"), ("TOP_K", "99"), ("MIN_SIMILARITY", "1.5"), ("BATCH_SIZE", "0"), ("PROVIDER", "cohere")])
|
||||
def test_rag_values_are_validated(monkeypatch, key, value):
|
||||
_env(monkeypatch, **{f"EST_RAG__{key}": value})
|
||||
with pytest.raises(ValidationError):
|
||||
Settings()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user