e0a28abbcd
When model != DEFAULT_EMBEDDING_MODEL, generate_embedding now calls client.embed(text, model=model) and wraps the returned vector in an EmbeddingResult tagged with the requested model. On any exception (NotImplementedError from providers without an embeddings endpoint, transient network errors, etc.), the existing T107 warning fires and the function falls back to the zero-vector sentinel — callers detect model == 'fallback' and skip indexing. Adds: - MockLLMClient accepts a canned_embeddings queue mirroring the existing canned pattern. embed() pops from the front; empty queue raises IndexError so misconfigured tests fail loudly. - Settings.embedding_model defaults to "pseudo-sha256-384" so existing zero-config installs keep Phase 4 behavior. The app lifespan now passes this through to EmbeddingWorker.model. The public signature of generate_embedding is unchanged: (client, *, text, model=DEFAULT_EMBEDDING_MODEL, dim=..., timeout_s=...).
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
import os
|
|
from pathlib import Path
|
|
import pytest
|
|
from chat.config import load_settings
|
|
|
|
def test_load_settings_reads_toml(tmp_path, monkeypatch):
|
|
cfg = tmp_path / "config.toml"
|
|
cfg.write_text("""
|
|
featherless_api_key = "sk-test"
|
|
narrative_model = "dphn/Dolphin-Mistral-24B-Venice-Edition"
|
|
classifier_model = "NousResearch/Hermes-3-Llama-3.1-8B"
|
|
ooc_marker = "(("
|
|
retrieval_k = 4
|
|
""")
|
|
monkeypatch.setenv("CHAT_CONFIG_PATH", str(cfg))
|
|
s = load_settings()
|
|
assert s.featherless_api_key == "sk-test"
|
|
assert s.narrative_model.startswith("dphn/")
|
|
assert s.retrieval_k == 4
|
|
|
|
def test_chat_db_path_env_overrides_default(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("CHAT_DB_PATH", str(tmp_path / "alt.db"))
|
|
monkeypatch.setenv("CHAT_CONFIG_PATH", str(tmp_path / "config.toml"))
|
|
(tmp_path / "config.toml").write_text('featherless_api_key = "x"\n')
|
|
s = load_settings()
|
|
assert s.db_path == tmp_path / "alt.db"
|
|
|
|
|
|
def test_embedding_model_defaults_to_pseudo(tmp_path, monkeypatch):
|
|
"""T112: ``embedding_model`` defaults to the deterministic pseudo
|
|
so existing zero-config installs keep the Phase 4 behavior."""
|
|
monkeypatch.setenv("CHAT_CONFIG_PATH", str(tmp_path / "config.toml"))
|
|
(tmp_path / "config.toml").write_text('featherless_api_key = "x"\n')
|
|
s = load_settings()
|
|
assert s.embedding_model == "pseudo-sha256-384"
|
|
|
|
|
|
def test_embedding_model_overridable_via_toml(tmp_path, monkeypatch):
|
|
"""T112: operators swap the embedding model by editing config.toml.
|
|
The new value flows through to the embedding worker at startup."""
|
|
cfg = tmp_path / "config.toml"
|
|
cfg.write_text(
|
|
'featherless_api_key = "x"\n'
|
|
'embedding_model = "bge-small-en-v1.5"\n'
|
|
)
|
|
monkeypatch.setenv("CHAT_CONFIG_PATH", str(cfg))
|
|
s = load_settings()
|
|
assert s.embedding_model == "bge-small-en-v1.5"
|