/
YoungFreddy
/
NetologyPipeLineService
Обзор
Документация
Войти
/
YoungFreddy
/
NetologyPipeLineService
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/test_services.py
83 строки
3 KB
Igor
Initial commit: LLM сервис с FastAPI, pipeline, ретраями, fallback, кэшем
18 июл 2026, 17:01
18 июл 2026, 17:01
5b26a48
Код
Авторство
О чём код?
import pytest from cache.base import SimpleCache from llm.client import LLMClient from services.llm_service import LLMService def test_llm_service_generate(): client = LLMClient(config={"api_key": None}) service = LLMService(client=client, cache=SimpleCache()) result = service.process_message("Test prompt") assert "Test prompt" in result def test_llm_service_with_cache(): client = LLMClient(config={"api_key": None}) cache = SimpleCache() service = LLMService(client=client, cache=cache) result1 = service.process_message("Cache test") result2 = service.process_message("Cache test") assert result1 == result2 def test_llm_service_different_inputs(): client = LLMClient(config={"api_key": None}) cache = SimpleCache() service = LLMService(client=client, cache=cache) result1 = service.process_message("First message") result2 = service.process_message("Second message") assert result1 != result2 assert "First" in result1 assert "Second" in result2 def test_llm_service_empty_message(): client = LLMClient(config={"api_key": None}) service = LLMService(client=client, cache=SimpleCache()) with pytest.raises(ValueError, match="не может быть пустым"): service.process_message("") def test_llm_service_whitespace_message(): client = LLMClient(config={"api_key": None}) service = LLMService(client=client, cache=SimpleCache()) with pytest.raises(ValueError, match="не может быть пустым"): service.process_message(" ") def test_service_fallback_propagation(): fallback = "Сервис временно недоступен" client = LLMClient( config={ "api_key": "real-key", "api_base": "https://nonexistent.example.com", "api_timeout": 0.1, "max_retries": 1, "retry_delay_base": 0.1, "fallback_response": fallback, } ) service = LLMService(client=client, cache=SimpleCache()) result = service.process_message("Hello") assert fallback in result def test_service_different_system_prompt(): client = LLMClient(config={"api_key": None, "model": "gpt-3.5-turbo"}) cache = SimpleCache() service = LLMService(client=client, cache=cache) result = service.process_message("Hello") assert "Hello" in result def test_service_cache_hit_miss_logging(): client = LLMClient(config={"api_key": None}) cache = SimpleCache() service = LLMService(client=client, cache=cache) result1 = service.process_message("log test") result2 = service.process_message("log test") assert result1 == result2