feat(main): dispatch X search to Bird or xAI
This commit is contained in:
+40
-12
@@ -168,20 +168,48 @@ def _search_x(
|
|||||||
to_date: str,
|
to_date: str,
|
||||||
depth: str,
|
depth: str,
|
||||||
mock: bool,
|
mock: bool,
|
||||||
|
x_source: str = "xai",
|
||||||
) -> tuple:
|
) -> tuple:
|
||||||
"""Search X via xAI (runs in thread).
|
"""Search X via Bird CLI or xAI (runs in thread).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x_source: 'bird' or 'xai' - which backend to use
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple of (x_items, raw_xai, error)
|
Tuple of (x_items, raw_response, error)
|
||||||
"""
|
"""
|
||||||
raw_xai = None
|
raw_response = None
|
||||||
x_error = None
|
x_error = None
|
||||||
|
|
||||||
if mock:
|
if mock:
|
||||||
raw_xai = load_fixture("xai_sample.json")
|
raw_response = load_fixture("xai_sample.json")
|
||||||
else:
|
x_items = xai_x.parse_x_response(raw_response or {})
|
||||||
|
return x_items, raw_response, x_error
|
||||||
|
|
||||||
|
# Use Bird if specified
|
||||||
|
if x_source == "bird":
|
||||||
try:
|
try:
|
||||||
raw_xai = xai_x.search_x(
|
raw_response = bird_x.search_x(
|
||||||
|
topic,
|
||||||
|
from_date,
|
||||||
|
to_date,
|
||||||
|
depth=depth,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raw_response = {"error": str(e)}
|
||||||
|
x_error = f"{type(e).__name__}: {e}"
|
||||||
|
|
||||||
|
x_items = bird_x.parse_bird_response(raw_response or {})
|
||||||
|
|
||||||
|
# Check for error in response
|
||||||
|
if raw_response and raw_response.get("error") and not x_error:
|
||||||
|
x_error = raw_response["error"]
|
||||||
|
|
||||||
|
return x_items, raw_response, x_error
|
||||||
|
|
||||||
|
# Use xAI (original behavior)
|
||||||
|
try:
|
||||||
|
raw_response = xai_x.search_x(
|
||||||
config["XAI_API_KEY"],
|
config["XAI_API_KEY"],
|
||||||
selected_models["xai"],
|
selected_models["xai"],
|
||||||
topic,
|
topic,
|
||||||
@@ -190,16 +218,15 @@ def _search_x(
|
|||||||
depth=depth,
|
depth=depth,
|
||||||
)
|
)
|
||||||
except http.HTTPError as e:
|
except http.HTTPError as e:
|
||||||
raw_xai = {"error": str(e)}
|
raw_response = {"error": str(e)}
|
||||||
x_error = f"API error: {e}"
|
x_error = f"API error: {e}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raw_xai = {"error": str(e)}
|
raw_response = {"error": str(e)}
|
||||||
x_error = f"{type(e).__name__}: {e}"
|
x_error = f"{type(e).__name__}: {e}"
|
||||||
|
|
||||||
# Parse response
|
x_items = xai_x.parse_x_response(raw_response or {})
|
||||||
x_items = xai_x.parse_x_response(raw_xai or {})
|
|
||||||
|
|
||||||
return x_items, raw_xai, x_error
|
return x_items, raw_response, x_error
|
||||||
|
|
||||||
|
|
||||||
def run_research(
|
def run_research(
|
||||||
@@ -212,6 +239,7 @@ def run_research(
|
|||||||
depth: str = "default",
|
depth: str = "default",
|
||||||
mock: bool = False,
|
mock: bool = False,
|
||||||
progress: ui.ProgressDisplay = None,
|
progress: ui.ProgressDisplay = None,
|
||||||
|
x_source: str = "xai",
|
||||||
) -> tuple:
|
) -> tuple:
|
||||||
"""Run the research pipeline.
|
"""Run the research pipeline.
|
||||||
|
|
||||||
@@ -262,7 +290,7 @@ def run_research(
|
|||||||
progress.start_x()
|
progress.start_x()
|
||||||
x_future = executor.submit(
|
x_future = executor.submit(
|
||||||
_search_x, topic, config, selected_models,
|
_search_x, topic, config, selected_models,
|
||||||
from_date, to_date, depth, mock
|
from_date, to_date, depth, mock, x_source
|
||||||
)
|
)
|
||||||
|
|
||||||
# Collect results
|
# Collect results
|
||||||
|
|||||||
Reference in New Issue
Block a user