Download tests/test_v2.py from gregrsea/HumpBack: direct link, hf CLI and curl.
- Browser
- Download file 2.76 kB
-
https://huggingface.co/gregrsea/HumpBack/resolve/main/tests/test_v2.py
- Command line
-
hf download hf://gregrsea/HumpBack/tests/test_v2.py
-
curl -L -o test_v2.py https://huggingface.co/gregrsea/HumpBack/resolve/main/tests/test_v2.py
2.76 kB
| """Tests for HumpBack v2 belief memory.""" | |
| import sys | |
| import time | |
| import unittest | |
| sys.path.insert(0, 'C:/Users/BRAVO/Documents/webdev/HumpBack') | |
| from humpback2.belief_store import BeliefStore | |
| from humpback2.evaluate import changing_facts_report, calibration_observations | |
| from humpback2.memory import Memory | |
| class TestBeliefStore(unittest.TestCase): | |
| def setUp(self): | |
| self.s = BeliefStore(":memory:") | |
| def test_learn_and_retrieve(self): | |
| sid = self.s.learn("python is a programming language", source_type="user", confidence=0.9) | |
| self.assertIsInstance(sid, int) | |
| res = self.s.retrieve("what is python", k=3) | |
| self.assertGreater(len(res), 0) | |
| self.assertIn("python", res[0]["claim"].lower()) | |
| def test_expiry_sweep_retracts_fast(self): | |
| self.s.learn("price of apple is 10", source_type="user", volatility="fast") | |
| later = time.time() + 10 * 86400 | |
| retracted = self.s.expiry_sweep(now=later) | |
| self.assertGreaterEqual(len(retracted), 1) | |
| self.assertEqual(self.s.count_active(), 0) | |
| class TestChangingFacts(unittest.TestCase): | |
| def test_signature(self): | |
| m = Memory(":memory:") | |
| rep = changing_facts_report(m) | |
| self.assertEqual(rep["retracted_count"], 1) | |
| self.assertEqual(rep["stale_answer_rate"], 0) | |
| self.assertEqual(rep["retention"], 1) | |
| def test_signature_steps(self): | |
| m = Memory(":memory:") | |
| m.learn("price of apple is 10", source_type="user", confidence=0.9, volatility="fast") | |
| m.learn("apple is a fruit", source_type="user", confidence=0.9, volatility="static") | |
| m.learn("paris is a city", source_type="official", confidence=0.95, volatility="static") | |
| before = m.size() | |
| later = time.time() + 10 * 86400 | |
| retracted = m.store.expiry_sweep(now=later) | |
| self.assertGreaterEqual(len(retracted), 1) | |
| self.assertEqual(m.size(), before - 1) | |
| res = m.ask("the price of apple") | |
| self.assertNotIn("10", res["answer"]) | |
| Paris = m.ask("what is paris").get("answer", "") | |
| self.assertIn("paris", Paris.lower()) | |
| self.assertIn("city", Paris.lower()) | |
| class TestCalibration(unittest.TestCase): | |
| def test_calibration_on_known_set(self): | |
| m = Memory(":memory:") | |
| m.store.learn("python is a programming language", confidence=0.9) | |
| m.store.learn("apple is a fruit", confidence=0.9) | |
| obs = calibration_observations(m, [ | |
| ("what is python", "python is a programming language"), | |
| ("what is an apple", "apple is a fruit"), | |
| ]) | |
| self.assertTrue(all(o["correct"] for o in obs)) | |
| self.assertEqual(obs[0]["confidence"], 0.9) | |
| if __name__ == "__main__": | |
| unittest.main() | |