fix: address review feedback

- Move json import to module level instead of inline
- Log content fetch errors instead of swallowing silently
- Use split-based vendor check for robustness with comma-separated configs
This commit is contained in:
Daniel Shashko 2026-03-23 14:57:30 +02:00
parent 99abdba844
commit 1bdbc7918f
2 changed files with 6 additions and 7 deletions

View File

@ -13,8 +13,9 @@ def create_social_media_analyst(llm):
# Check if bright_data vendor is configured for social sentiment
config = get_config()
news_vendor = config.get("data_vendors", {}).get("news_data", "")
news_vendors = [v.strip() for v in news_vendor.split(",")]
tools = [get_news]
if "bright_data" in news_vendor:
if "bright_data" in news_vendors:
tools.append(get_social_sentiment)
system_message = (

View File

@ -78,13 +78,11 @@ def _serp_search(query: str, num_results: int = 10) -> list[dict]:
# Parse organic results from SERP response
# The SERP API wraps results in a "body" key as a JSON string
import json as _json
body = data.get("body", data)
if isinstance(body, str):
try:
body = _json.loads(body)
except _json.JSONDecodeError:
body = json.loads(body)
except json.JSONDecodeError:
body = data
organic = body.get("organic", []) if isinstance(body, dict) else []
@ -170,8 +168,8 @@ def _search_and_fetch(
if len(content) > max_content_length:
content = content[:max_content_length] + "\n[... truncated ...]"
r["content"] = content
except Exception:
r["content"] = ""
except Exception as e:
r["content"] = f"[Content fetch failed: {e}]"
return results