~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
chore: delete dead pricing fetcher methods (#4176)
LearningCircuit6b45e1cb98f6
diff --git a/src/local_deep_research/metrics/pricing/pricing_fetcher.py b/src/local_deep_research/metrics/pricing/pricing_fetcher.pyindex f003e8e3fd..cd5ccd4f88 100644--- a/src/local_deep_research/metrics/pricing/pricing_fetcher.py+++ b/src/local_deep_research/metrics/pricing/pricing_fetcher.py@@ -5,7 +5,7 @@ Fetches real-time pricing data from various LLM providers.Supports multiple providers and fallback to static pricing."""-from typing import Any, Dict, Optional+from typing import Dict, Optionalimport aiohttpfrom loguru import logger@@ -60,61 +60,6 @@ class PricingFetcher:"llamacpp": {"prompt": 0.0, "completion": 0.0},}- async def fetch_openai_pricing(self) -> Optional[Dict[str, Any]]:- """Fetch OpenAI pricing from their API (if available)."""- try:- # Note: OpenAI doesn't have a public pricing API- # This would need to be web scraping or manual updates- logger.info("Using static OpenAI pricing (no public API available)")- return None- except Exception:- logger.warning("Failed to fetch OpenAI pricing")- return None-- async def fetch_anthropic_pricing(self) -> Optional[Dict[str, Any]]:- """Fetch Anthropic pricing."""- try:- # Note: Anthropic doesn't have a public pricing API- # This would need to be web scraping or manual updates- logger.info(- "Using static Anthropic pricing (no public API available)"- )- return None- except Exception:- logger.warning("Failed to fetch Anthropic pricing")- return None-- async def fetch_google_pricing(self) -> Optional[Dict[str, Any]]:- """Fetch Google/Gemini pricing."""- try:- # Note: Google doesn't have a dedicated pricing API for individual models- # This would need to be web scraping or manual updates- logger.info("Using static Google pricing (no public API available)")- return None- except Exception:- logger.warning("Failed to fetch Google pricing")- return None-- async def fetch_huggingface_pricing(self) -> Optional[Dict[str, Any]]:- """Fetch HuggingFace Inference API pricing."""- try:- if not self.session:- return None-- # HuggingFace has some pricing info but not a structured API- # This is more for hosted inference endpoints- url = "https://huggingface.co/pricing"- async with self.session.get(url) as response:- if response.status == 200:- # Would need to parse HTML for pricing info- logger.info(- "HuggingFace pricing would require HTML parsing"- )- return None- except Exception:- logger.warning("Failed to fetch HuggingFace pricing")- return None-async def get_model_pricing(self, model_name: str, provider: str = None) -> Optional[Dict[str, float]]:@@ -131,26 +76,6 @@ class PricingFetcher:)return {"prompt": 0.0, "completion": 0.0}- # Try to fetch live pricing first (most providers don't have APIs)- if (- provider == "openai"- or "gpt" in model_name- or "openai" in model_name- ):- await self.fetch_openai_pricing()- elif (- provider == "anthropic"- or "claude" in model_name- or "anthropic" in model_name- ):- await self.fetch_anthropic_pricing()- elif (- provider == "google"- or "gemini" in model_name- or "google" in model_name- ):- await self.fetch_google_pricing()-# Fallback to static pricing with provider priorityif provider:# First try provider-specific lookup with exact matching@@ -216,11 +141,6 @@ class PricingFetcher:return provider_models- async def get_all_pricing(self) -> Dict[str, Dict[str, float]]:- """Get pricing for all known models."""- # In the future, this could aggregate from multiple live sources- return self.static_pricing.copy()-def get_provider_from_model(self, model_name: str) -> str:"""Determine the provider from model name."""model_name = model_name.lower()diff --git a/tests/metrics/pricing/test_pricing_fetcher_coverage.py b/tests/metrics/pricing/test_pricing_fetcher_coverage.pyindex f64ab959ed..a363742a49 100644--- a/tests/metrics/pricing/test_pricing_fetcher_coverage.py+++ b/tests/metrics/pricing/test_pricing_fetcher_coverage.py@@ -3,12 +3,9 @@ Comprehensive coverage tests for PricingFetcher.Focuses on mocked HTTP interactions, edge cases, and all code paths:- __init__, __aenter__, __aexit__ (with and without session)-- fetch_huggingface_pricing: no session, 200 response, non-200, exception-- fetch_openai/anthropic/google_pricing: exception paths-- get_model_pricing: local providers, OpenAI/Anthropic/Google triggers,- provider-first match, slash model name, exact match, no match, None inputs+- get_model_pricing: local providers, provider-first match, slash model+ name, exact match, no match, None inputs- _get_models_by_provider: all provider branches-- get_all_pricing: returns independent copy- get_provider_from_model: all prefix branches including ollama-only path"""@@ -73,62 +70,7 @@ class TestAsyncContextManager:# ===================================================================-# 3. fetch_huggingface_pricing-# ===================================================================-class TestFetchHuggingFacePricing:- @pytest.mark.asyncio- async def test_returns_none_when_no_session(self):- fetcher = PricingFetcher()- assert fetcher.session is None- result = await fetcher.fetch_huggingface_pricing()- assert result is None-- @pytest.mark.asyncio- async def test_returns_none_on_200(self):- """Even with a 200 response the method returns None (no parser)."""- fetcher = PricingFetcher()- mock_response = AsyncMock()- mock_response.status = 200- mock_response.__aenter__ = AsyncMock(return_value=mock_response)- mock_response.__aexit__ = AsyncMock(return_value=False)-- mock_session = MagicMock()- mock_session.get = MagicMock(return_value=mock_response)- fetcher.session = mock_session-- result = await fetcher.fetch_huggingface_pricing()- assert result is None-- @pytest.mark.asyncio- async def test_returns_none_on_non_200(self):- """Non-200 status should fall through and return None implicitly."""- fetcher = PricingFetcher()- mock_response = AsyncMock()- mock_response.status = 503- mock_response.__aenter__ = AsyncMock(return_value=mock_response)- mock_response.__aexit__ = AsyncMock(return_value=False)-- mock_session = MagicMock()- mock_session.get = MagicMock(return_value=mock_response)- fetcher.session = mock_session-- result = await fetcher.fetch_huggingface_pricing()- assert result is None-- @pytest.mark.asyncio- async def test_returns_none_on_exception(self):- """Network errors should be caught and return None."""- fetcher = PricingFetcher()- mock_session = MagicMock()- mock_session.get = MagicMock(side_effect=Exception("connection error"))- fetcher.session = mock_session-- result = await fetcher.fetch_huggingface_pricing()- assert result is None---# ===================================================================-# 4. get_model_pricing -- local providers+# 3. get_model_pricing -- local providers# ===================================================================class TestGetModelPricingLocalProviders:@pytest.mark.asyncio@@ -151,66 +93,7 @@ class TestGetModelPricingLocalProviders:# ===================================================================-# 5. get_model_pricing -- provider triggers for live fetching-# ===================================================================-class TestGetModelPricingProviderTriggers:- @pytest.mark.asyncio- async def test_openai_provider_triggers_fetch(self):- fetcher = PricingFetcher()- with patch.object(- fetcher, "fetch_openai_pricing", new_callable=AsyncMock- ) as m:- await fetcher.get_model_pricing("gpt-4", "openai")- m.assert_awaited_once()-- @pytest.mark.asyncio- async def test_gpt_in_model_triggers_openai_fetch(self):- fetcher = PricingFetcher()- with patch.object(- fetcher, "fetch_openai_pricing", new_callable=AsyncMock- ) as m:- await fetcher.get_model_pricing("gpt-4o-mini")- m.assert_awaited_once()-- @pytest.mark.asyncio- async def test_anthropic_provider_triggers_fetch(self):- fetcher = PricingFetcher()- with patch.object(- fetcher, "fetch_anthropic_pricing", new_callable=AsyncMock- ) as m:- await fetcher.get_model_pricing("claude-3-opus", "anthropic")- m.assert_awaited_once()-- @pytest.mark.asyncio- async def test_claude_in_model_triggers_anthropic_fetch(self):- fetcher = PricingFetcher()- with patch.object(- fetcher, "fetch_anthropic_pricing", new_callable=AsyncMock- ) as m:- await fetcher.get_model_pricing("claude-3-haiku")- m.assert_awaited_once()-- @pytest.mark.asyncio- async def test_google_provider_triggers_fetch(self):- fetcher = PricingFetcher()- with patch.object(- fetcher, "fetch_google_pricing", new_callable=AsyncMock- ) as m:- await fetcher.get_model_pricing("gemini-pro", "google")- m.assert_awaited_once()-- @pytest.mark.asyncio- async def test_gemini_in_model_triggers_google_fetch(self):- fetcher = PricingFetcher()- with patch.object(- fetcher, "fetch_google_pricing", new_callable=AsyncMock- ) as m:- await fetcher.get_model_pricing("gemini-1.5-flash")- m.assert_awaited_once()---# ===================================================================-# 6. get_model_pricing -- provider-first match via _get_models_by_provider+# 4. get_model_pricing -- provider-first match via _get_models_by_provider# ===================================================================class TestGetModelPricingProviderFirstMatch:@pytest.mark.asyncio@@ -239,7 +122,7 @@ class TestGetModelPricingProviderFirstMatch:# ===================================================================-# 7. get_model_pricing -- exact match and no match+# 5. get_model_pricing -- exact match and no match# ===================================================================class TestGetModelPricingExactAndNoMatch:@pytest.mark.asyncio@@ -278,7 +161,7 @@ class TestGetModelPricingExactAndNoMatch:# ===================================================================-# 8. _get_models_by_provider+# 6. _get_models_by_provider# ===================================================================class TestGetModelsByProvider:def test_openai_returns_gpt_models(self):@@ -318,27 +201,7 @@ class TestGetModelsByProvider:# ===================================================================-# 9. get_all_pricing-# ===================================================================-class TestGetAllPricing:- @pytest.mark.asyncio- async def test_returns_dict(self):- fetcher = PricingFetcher()- result = await fetcher.get_all_pricing()- assert isinstance(result, dict)- assert len(result) == len(fetcher.static_pricing)-- @pytest.mark.asyncio- async def test_returns_independent_copy(self):- """Mutating the returned dict must not affect the original."""- fetcher = PricingFetcher()- result = await fetcher.get_all_pricing()- result["injected"] = {"prompt": 999}- assert "injected" not in fetcher.static_pricing---# ===================================================================-# 10. get_provider_from_model+# 7. get_provider_from_model# ===================================================================class TestGetProviderFromModel:def test_gpt_returns_openai(self):diff --git a/tests/metrics/test_pricing_fetcher.py b/tests/metrics/test_pricing_fetcher.pyindex d0d631d2b4..0c571d9e9d 100644--- a/tests/metrics/test_pricing_fetcher.py+++ b/tests/metrics/test_pricing_fetcher.py@@ -248,43 +248,3 @@ class TestPricingFetcherGetProviderFromModel:fetcher = PricingFetcher()assert fetcher.get_provider_from_model("random-model") == "unknown"---class TestPricingFetcherGetAllPricing:- """Tests for get_all_pricing method."""-- @pytest.mark.asyncio- async def test_returns_copy_of_static_pricing(self):- """Should return a copy of static pricing."""- async with PricingFetcher() as fetcher:- result = await fetcher.get_all_pricing()-- assert result == fetcher.static_pricing- # Verify it's a copy- result["new_key"] = "test"- assert "new_key" not in fetcher.static_pricing---class TestPricingFetcherFetchMethods:- """Tests for individual fetch methods."""-- @pytest.mark.asyncio- async def test_fetch_openai_pricing_returns_none(self):- """OpenAI pricing fetch returns None (no public API)."""- async with PricingFetcher() as fetcher:- result = await fetcher.fetch_openai_pricing()- assert result is None-- @pytest.mark.asyncio- async def test_fetch_anthropic_pricing_returns_none(self):- """Anthropic pricing fetch returns None (no public API)."""- async with PricingFetcher() as fetcher:- result = await fetcher.fetch_anthropic_pricing()- assert result is None-- @pytest.mark.asyncio- async def test_fetch_google_pricing_returns_none(self):- """Google pricing fetch returns None (no public API)."""- async with PricingFetcher() as fetcher:- result = await fetcher.fetch_google_pricing()- assert result is None