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:
parent
99abdba844
commit
1bdbc7918f
|
|
@ -13,8 +13,9 @@ def create_social_media_analyst(llm):
|
||||||
# Check if bright_data vendor is configured for social sentiment
|
# Check if bright_data vendor is configured for social sentiment
|
||||||
config = get_config()
|
config = get_config()
|
||||||
news_vendor = config.get("data_vendors", {}).get("news_data", "")
|
news_vendor = config.get("data_vendors", {}).get("news_data", "")
|
||||||
|
news_vendors = [v.strip() for v in news_vendor.split(",")]
|
||||||
tools = [get_news]
|
tools = [get_news]
|
||||||
if "bright_data" in news_vendor:
|
if "bright_data" in news_vendors:
|
||||||
tools.append(get_social_sentiment)
|
tools.append(get_social_sentiment)
|
||||||
|
|
||||||
system_message = (
|
system_message = (
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,11 @@ def _serp_search(query: str, num_results: int = 10) -> list[dict]:
|
||||||
|
|
||||||
# Parse organic results from SERP response
|
# Parse organic results from SERP response
|
||||||
# The SERP API wraps results in a "body" key as a JSON string
|
# The SERP API wraps results in a "body" key as a JSON string
|
||||||
import json as _json
|
|
||||||
|
|
||||||
body = data.get("body", data)
|
body = data.get("body", data)
|
||||||
if isinstance(body, str):
|
if isinstance(body, str):
|
||||||
try:
|
try:
|
||||||
body = _json.loads(body)
|
body = json.loads(body)
|
||||||
except _json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
body = data
|
body = data
|
||||||
organic = body.get("organic", []) if isinstance(body, dict) else []
|
organic = body.get("organic", []) if isinstance(body, dict) else []
|
||||||
|
|
||||||
|
|
@ -170,8 +168,8 @@ def _search_and_fetch(
|
||||||
if len(content) > max_content_length:
|
if len(content) > max_content_length:
|
||||||
content = content[:max_content_length] + "\n[... truncated ...]"
|
content = content[:max_content_length] + "\n[... truncated ...]"
|
||||||
r["content"] = content
|
r["content"] = content
|
||||||
except Exception:
|
except Exception as e:
|
||||||
r["content"] = ""
|
r["content"] = f"[Content fetch failed: {e}]"
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue