Update stale API endpoints and model chains
- Instagram: migrate /v1/ to /v2/ ScrapeCreators endpoint (v1 deprecated Feb 2026) - OpenAI: switch fallback chain to [gpt-5-mini, gpt-4.1-mini, gpt-4.1] (8x cheaper, gpt-5-mini is the first mini model supporting web_search with filters.allowed_domains) - xAI: use explicit grok-4-1-fast-non-reasoning (bare name aliases to reasoning variant) - xAI: pass from_date/to_date natively to x_search tool config instead of prompt-only - Polymarket: correct rate limit comment (15K/10s, not 350/10s)
This commit is contained in:
@@ -217,7 +217,7 @@ def search_instagram(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
resp = _requests.get(
|
resp = _requests.get(
|
||||||
f"{SCRAPECREATORS_BASE}/v1/instagram/reels/search",
|
f"{SCRAPECREATORS_BASE}/v2/instagram/reels/search",
|
||||||
params={"query": core_topic},
|
params={"query": core_topic},
|
||||||
headers=_sc_headers(token),
|
headers=_sc_headers(token),
|
||||||
timeout=30,
|
timeout=30,
|
||||||
@@ -228,7 +228,7 @@ def search_instagram(
|
|||||||
_log(f"ScrapeCreators error: {e}")
|
_log(f"ScrapeCreators error: {e}")
|
||||||
return {"items": [], "error": f"{type(e).__name__}: {e}"}
|
return {"items": [], "error": f"{type(e).__name__}: {e}"}
|
||||||
|
|
||||||
# Items are in the 'reels' array (ScrapeCreators v1 response)
|
# Items are in the 'reels' array (ScrapeCreators v2 response)
|
||||||
raw_items = data.get("reels") or data.get("items") or data.get("data") or []
|
raw_items = data.get("reels") or data.get("items") or data.get("data") or []
|
||||||
|
|
||||||
# Limit to configured count
|
# Limit to configured count
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ CODEX_FALLBACK_MODELS = ["gpt-5.1-codex-mini", "gpt-5.2"]
|
|||||||
# xAI API - Agent Tools API requires grok-4 family
|
# xAI API - Agent Tools API requires grok-4 family
|
||||||
XAI_MODELS_URL = "https://api.x.ai/v1/models"
|
XAI_MODELS_URL = "https://api.x.ai/v1/models"
|
||||||
XAI_ALIASES = {
|
XAI_ALIASES = {
|
||||||
"latest": "grok-4-1-fast", # Required for x_search tool
|
"latest": "grok-4-1-fast-non-reasoning", # Explicit: bare grok-4-1-fast aliases to reasoning variant
|
||||||
"stable": "grok-4-1-fast",
|
"stable": "grok-4-1-fast-non-reasoning",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ from typing import Any, Dict, List, Optional
|
|||||||
from . import http, env
|
from . import http, env
|
||||||
|
|
||||||
# Fallback models when the selected model isn't accessible (e.g., org not verified for GPT-5)
|
# Fallback models when the selected model isn't accessible (e.g., org not verified for GPT-5)
|
||||||
# Note: gpt-4o-mini does NOT support web_search with filters param, so exclude it
|
# gpt-5-mini: $0.25/1M input (8x cheaper than gpt-4.1), supports web_search with filters
|
||||||
MODEL_FALLBACK_ORDER = ["gpt-4.1", "gpt-4o"]
|
# gpt-4o-mini does NOT support web_search with filters param, so exclude it
|
||||||
|
MODEL_FALLBACK_ORDER = ["gpt-5-mini", "gpt-4.1-mini", "gpt-4.1"]
|
||||||
|
|
||||||
|
|
||||||
def _log_error(msg: str):
|
def _log_error(msg: str):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""Polymarket prediction market search via Gamma API (free, no auth required).
|
"""Polymarket prediction market search via Gamma API (free, no auth required).
|
||||||
|
|
||||||
Uses gamma-api.polymarket.com for event/market discovery.
|
Uses gamma-api.polymarket.com for event/market discovery.
|
||||||
No API key needed - public read-only API with generous rate limits (350 req/10s).
|
No API key needed - public read-only API with generous rate limits (15K req/10s).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|||||||
@@ -91,11 +91,11 @@ def search_x(
|
|||||||
# Adjust timeout based on depth (generous for API response time)
|
# Adjust timeout based on depth (generous for API response time)
|
||||||
timeout = 90 if depth == "quick" else 120 if depth == "default" else 180
|
timeout = 90 if depth == "quick" else 120 if depth == "default" else 180
|
||||||
|
|
||||||
# Use Agent Tools API with x_search tool
|
# Use Agent Tools API with x_search tool (native date filtering)
|
||||||
payload = {
|
payload = {
|
||||||
"model": model,
|
"model": model,
|
||||||
"tools": [
|
"tools": [
|
||||||
{"type": "x_search"}
|
{"type": "x_search", "from_date": from_date, "to_date": to_date}
|
||||||
],
|
],
|
||||||
"input": [
|
"input": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class TestSelectXAIModel(unittest.TestCase):
|
|||||||
"fake-key",
|
"fake-key",
|
||||||
policy="latest"
|
policy="latest"
|
||||||
)
|
)
|
||||||
self.assertEqual(result, "grok-4-1-fast")
|
self.assertEqual(result, "grok-4-1-fast-non-reasoning")
|
||||||
|
|
||||||
def test_stable_policy(self):
|
def test_stable_policy(self):
|
||||||
# Clear cache first to avoid interference
|
# Clear cache first to avoid interference
|
||||||
@@ -94,7 +94,7 @@ class TestSelectXAIModel(unittest.TestCase):
|
|||||||
"fake-key",
|
"fake-key",
|
||||||
policy="stable"
|
policy="stable"
|
||||||
)
|
)
|
||||||
self.assertEqual(result, "grok-4-1-fast")
|
self.assertEqual(result, "grok-4-1-fast-non-reasoning")
|
||||||
|
|
||||||
def test_pinned_policy(self):
|
def test_pinned_policy(self):
|
||||||
result = models.select_xai_model(
|
result = models.select_xai_model(
|
||||||
@@ -125,10 +125,10 @@ class TestGetModels(unittest.TestCase):
|
|||||||
"XAI_API_KEY": "xai-test",
|
"XAI_API_KEY": "xai-test",
|
||||||
}
|
}
|
||||||
mock_openai = [{"id": "gpt-5.2", "created": 1704067200}]
|
mock_openai = [{"id": "gpt-5.2", "created": 1704067200}]
|
||||||
mock_xai = [{"id": "grok-4-1-fast", "created": 1704067200}]
|
mock_xai = [{"id": "grok-4-1-fast-non-reasoning", "created": 1704067200}]
|
||||||
result = models.get_models(config, mock_openai, mock_xai)
|
result = models.get_models(config, mock_openai, mock_xai)
|
||||||
self.assertEqual(result["openai"], "gpt-5.2")
|
self.assertEqual(result["openai"], "gpt-5.2")
|
||||||
self.assertEqual(result["xai"], "grok-4-1-fast")
|
self.assertEqual(result["xai"], "grok-4-1-fast-non-reasoning")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ class TestIsModelAccessError(unittest.TestCase):
|
|||||||
class TestModelFallbackOrder(unittest.TestCase):
|
class TestModelFallbackOrder(unittest.TestCase):
|
||||||
"""Tests for MODEL_FALLBACK_ORDER constant."""
|
"""Tests for MODEL_FALLBACK_ORDER constant."""
|
||||||
|
|
||||||
def test_contains_gpt4o(self):
|
def test_contains_gpt41(self):
|
||||||
"""Fallback list should include gpt-4o."""
|
"""Fallback list should include gpt-4.1 as last resort."""
|
||||||
self.assertIn("gpt-4o", MODEL_FALLBACK_ORDER)
|
self.assertIn("gpt-4.1", MODEL_FALLBACK_ORDER)
|
||||||
|
|
||||||
def test_gpt41_is_first(self):
|
def test_gpt5_mini_is_first(self):
|
||||||
"""gpt-4.1 should be the first fallback option."""
|
"""gpt-5-mini should be the first fallback option (cheapest with web_search support)."""
|
||||||
self.assertEqual(MODEL_FALLBACK_ORDER[0], "gpt-4.1")
|
self.assertEqual(MODEL_FALLBACK_ORDER[0], "gpt-5-mini")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user