确认PokieTicker新闻库数据源
This commit is contained in:
@@ -7,6 +7,7 @@ Returns human-readable text format for easy LLM consumption.
|
||||
"""
|
||||
# flake8: noqa: E501
|
||||
# pylint: disable=C0301,W0613
|
||||
import ast
|
||||
import json
|
||||
import logging
|
||||
import traceback
|
||||
@@ -20,6 +21,7 @@ import pandas as pd
|
||||
from agentscope.message import TextBlock
|
||||
from agentscope.tool import ToolResponse
|
||||
|
||||
from backend.data.provider_utils import normalize_symbol
|
||||
from backend.tools.data_tools import (
|
||||
get_company_news,
|
||||
get_financial_metrics,
|
||||
@@ -53,6 +55,16 @@ def _parse_tickers(tickers: Union[str, List[str], None]) -> List[str]:
|
||||
Returns:
|
||||
List of stock tickers.
|
||||
"""
|
||||
def _sanitize(values: List[object]) -> List[str]:
|
||||
cleaned: List[str] = []
|
||||
for value in values:
|
||||
if value is None:
|
||||
continue
|
||||
symbol = normalize_symbol(str(value).strip().strip("\"'"))
|
||||
if symbol and symbol not in cleaned:
|
||||
cleaned.append(symbol)
|
||||
return cleaned
|
||||
|
||||
if tickers is None:
|
||||
return []
|
||||
|
||||
@@ -60,17 +72,22 @@ def _parse_tickers(tickers: Union[str, List[str], None]) -> List[str]:
|
||||
try:
|
||||
parsed = json.loads(tickers)
|
||||
if isinstance(parsed, list):
|
||||
return parsed
|
||||
# If it's a single string, wrap in list
|
||||
return [parsed]
|
||||
return _sanitize(parsed)
|
||||
return _sanitize([parsed])
|
||||
except json.JSONDecodeError:
|
||||
# If not valid JSON, treat as comma-separated string
|
||||
return [t.strip() for t in tickers.split(",") if t.strip()]
|
||||
try:
|
||||
parsed = ast.literal_eval(tickers)
|
||||
if isinstance(parsed, list):
|
||||
return _sanitize(parsed)
|
||||
return _sanitize([parsed])
|
||||
except (SyntaxError, ValueError):
|
||||
pass
|
||||
return _sanitize(tickers.split(","))
|
||||
|
||||
if isinstance(tickers, list):
|
||||
return tickers
|
||||
return _sanitize(tickers)
|
||||
|
||||
return []
|
||||
return _sanitize([tickers])
|
||||
|
||||
|
||||
def _safe_float(value, default=0.0) -> float:
|
||||
@@ -350,6 +367,7 @@ def get_financial_metrics_tool(
|
||||
"""
|
||||
|
||||
current_date = _resolved_date(current_date)
|
||||
tickers = _parse_tickers(tickers)
|
||||
lines = [
|
||||
f"=== Comprehensive Financial Metrics ({current_date}, {period}) ===\n",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user