Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /AmberLee2427_nancy-brain /tests /test_summarization_llm.py
| import os | |
| import pytest | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| from nancy_brain.summarization import SummaryGenerator | |
| def test_llm_summary_json_and_weight(monkeypatch): | |
| """ | |
| Integration test: Assert that SummaryGenerator returns valid JSON and float weight from real LLM call. | |
| """ | |
| # Load environment variables | |
| load_dotenv("config/.env") | |
| api_key = os.environ.get("ANTHROPIC_API_KEY") | |
| if not api_key: | |
| pytest.skip("ANTHROPIC_API_KEY not configured") | |
| monkeypatch.setenv("NB_USE_LOCAL_SUMMARY", "false") | |
| cache_dir = Path("./test_llm_cache") | |
| summary_gen = SummaryGenerator(cache_dir=cache_dir, enabled=True) | |
| assert summary_gen.use_local is False | |
| # Use a small, representative file for speed | |
| test_file = Path("nancy_brain/summarization.py") | |
| assert test_file.exists(), f"Test file {test_file} does not exist" | |
| content = test_file.read_text(encoding="utf-8") | |
| result = summary_gen.summarize( | |
| doc_id="nancy-brain/nancy_brain/summarization.py", | |
| content=content, | |
| repo_name="nancy-brain", | |
| metadata={"file_type": ".py"}, | |
| ) | |
| if result is None and summary_gen.last_error_type == "connection": | |
| pytest.skip("Anthropic connection unavailable") | |
| assert result is not None, "LLM did not return a result" | |
| # Assert JSON structure | |
| assert hasattr(result, "summary"), "Result missing 'summary' field" | |
| assert hasattr(result, "weight"), "Result missing 'weight' field" | |
| assert isinstance(result.summary, str), "Summary is not a string" | |
| assert isinstance(result.weight, float), "Weight is not a float" | |
| assert 0.5 <= result.weight <= 2.0, f"Weight {result.weight} out of expected range [0.5, 2.0]" | |
| assert len(result.summary) > 50, "Summary too short to be meaningful" | |
| print(f"LLM summary: {result.summary[:100]}...") | |
| print(f"LLM weight: {result.weight}") | |
Xet Storage Details
- Size:
- 1.93 kB
- Xet hash:
- cd12df28ad9daf92196fc04fadf2e304b1cf0b772624a50b112b0124bbef3608
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.