Add ReputationRadar community contribution (demo replaced by link)

This commit is contained in:
Parth Verma
2025-10-22 15:30:00 +05:30
parent 9b84cc62c0
commit a3ee215468
22 changed files with 1794 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import pathlib
import sys
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))

View File

@@ -0,0 +1,19 @@
import pytest
from services import llm
from services.utils import ServiceWarning
def test_llm_fallback_uses_vader():
service = llm.LLMService(api_key=None)
results = service.classify_sentiment_batch(
["I absolutely love this product!", "This is the worst experience ever."]
)
assert results[0].label == "positive"
assert results[1].label == "negative"
def test_summary_requires_openai_key():
service = llm.LLMService(api_key=None)
with pytest.raises(ServiceWarning):
service.summarize_overall([{"label": "positive", "text": "Example"}])

View File

@@ -0,0 +1,35 @@
import datetime as dt
from services import utils
def test_normalize_items_deduplicates():
ts = dt.datetime(2025, 1, 1, tzinfo=dt.timezone.utc)
items = [
utils.NormalizedItem(
source="reddit",
id="1",
url="https://example.com/a",
author="alice",
timestamp=ts,
text="ReputationRadar is great!",
meta={},
),
utils.NormalizedItem(
source="reddit",
id="2",
url="https://example.com/a",
author="bob",
timestamp=ts,
text="ReputationRadar is great!",
meta={},
),
]
cleaned = utils.normalize_items(items)
assert len(cleaned) == 1
def test_sanitize_text_removes_html():
raw = "<p>Hello <strong>world</strong> &nbsp; <a href='https://example.com'>link</a></p>"
cleaned = utils.sanitize_text(raw)
assert cleaned == "Hello world link"