Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ GEMINI_API_KEY=
# - Moonshot 官方模型卡(评测默认 temperature = 1.0):https://huggingface.co/moonshotai/Kimi-K2.6
# - OpenAI Chat Completions 规范:https://platform.openai.com/docs/api-reference/chat/create
# - LiteLLM OpenAI-Compatible 规范:https://docs.litellm.ai/docs/providers/openai_compatible
# 当前仓库运行时依赖约束:litellm>=1.80.10,!=1.82.7,!=1.82.8,<2.0.0(显式排除 PyPI 事故版本,见 requirements.txt)。
# 当前仓库运行时依赖约束:litellm>=1.80.10,!=1.82.7,!=1.82.8,<1.99.0(显式排除 PyPI 事故版本并将上界收敛到已验证版本,见 requirements.txt)。
# 因此 kimi-k2.6 会自动改用 1.0/0.6;GPT-5 / o 系列等默认温度模型会省略 temperature,避免 API 拒绝请求。
# 若兼容平台返回明确的参数不支持错误,运行时会在当前请求内修正参数并重试一次;成功策略只做进程内缓存。
# top_p、presence_penalty、frequency_penalty、seed 若返回“不支持参数”,同样会触发本次请求级别的修正与重试(不改写 LLM_TEMPERATURE)。
Expand Down
200 changes: 168 additions & 32 deletions api/v1/endpoints/analysis.py

Large diffs are not rendered by default.

34 changes: 28 additions & 6 deletions api/v1/endpoints/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
normalize_report_language,
)
from src.services.history_service import HistoryService, MarkdownReportGenerationError
from src.services.analysis_service import asset_type_from_canonical_code
from src.schemas.decision_action import build_action_fields
from src.utils.data_processing import (
normalize_model_used,
Expand Down Expand Up @@ -129,14 +130,30 @@ def _history_share_image_branding(config: object) -> ShareImageBranding:
return share_image_branding_from_config(config)


def _normalize_code_for_grouping(code: str) -> str:
"""Normalize stock code for deduplication grouping.
def _stock_bar_group_key(record_code: str, display_code: str) -> str:
"""Build the stock-bar grouping key from the *persisted* code.

Delegates to data_provider.base.normalize_stock_code which handles
SH600519, 600519.SH, HK00700, 00700.HK, BJ920748, etc.
PR #2312: registered indices are typed by the persisted ``record.code``
(never guessed from the display code) and group by the parser canonical
(lowercase ``sh000016`` / ``csi930955``), so every explicit index form
(uppercase legacy / dotted alias) converges to one row and never folds
with the bare same-code stock. Stocks keep the legacy display-based
normalization (``SH600519``/``600519.SH`` -> ``600519``, JP/KR legacy bare
``005930`` merging with ``005930.KS`` etc.), preserving existing semantics.
"""
from data_provider.base import normalize_stock_code
return normalize_stock_code(code or "")
from src.services.stock_list_parser import ParseStatus, parse_analysis_target

code = str(record_code or "").strip()
if not code:
return normalize_stock_code(display_code or "")
try:
target = parse_analysis_target(code)
except Exception:
return normalize_stock_code(display_code or "")
if target.asset_type == ParseStatus.INDEX:
return target.canonical_id
return normalize_stock_code(display_code or "")


def _raw_result_value(raw_result: Any, key: str) -> Any:
Expand Down Expand Up @@ -274,6 +291,7 @@ def get_history_list(
model_used=item.get("model_used"),
created_at=item.get("created_at"),
market_phase_summary=item.get("market_phase_summary"),
asset_type=item.get("asset_type"),
)
for item in result.get("items", [])
]
Expand Down Expand Up @@ -431,7 +449,7 @@ def get_stock_bar(
seen: dict = {}
for record in records:
display_code = service._display_stock_code(record.code or "")
norm_code = _normalize_code_for_grouping(display_code)
norm_code = _stock_bar_group_key(record.code or "", display_code)
if norm_code not in seen or record.id > seen[norm_code].id:
seen[norm_code] = record

Expand Down Expand Up @@ -482,6 +500,7 @@ def get_stock_bar(
record.code,
getattr(record, "context_snapshot", None),
),
asset_type=asset_type_from_canonical_code(record.code),
)
)

Expand Down Expand Up @@ -589,6 +608,9 @@ def get_history_detail(
change_pct=change_pct,
model_used=normalize_model_used(result.get("model_used")),
market_phase_summary=market_phase_summary,
asset_type=asset_type_from_canonical_code(
result.get("storage_stock_code") or result.get("stock_code")
),
)

summary = ReportSummary(
Expand Down
2 changes: 2 additions & 0 deletions api/v1/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
AnalysisResultResponse,
TaskAccepted,
BatchTaskAcceptedResponse,
RejectedTaskItem,
TaskStatus,
)
from api.v1.schemas.history import (
Expand Down Expand Up @@ -168,6 +169,7 @@
"AnalysisResultResponse",
"TaskAccepted",
"BatchTaskAcceptedResponse",
"RejectedTaskItem",
"TaskStatus",
# history
"HistoryItem",
Expand Down
26 changes: 26 additions & 0 deletions api/v1/schemas/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ class BatchTaskAcceptedItem(BaseModel):
)
message: Optional[str] = Field(None, description="提示信息")
analysis_phase: AnalysisPhase = Field("auto", description="请求的分析阶段")
asset_type: Optional[Literal["stock", "index"]] = Field(
None,
description="parser 来源的可选资产类型(stock/index);由已提交的 analysis_target 透传,旧客户端可缺省",
)

model_config = ConfigDict(json_schema_extra={
"example": {
Expand Down Expand Up @@ -259,11 +263,29 @@ class BatchDuplicateTaskItem(BaseModel):
})


class RejectedTaskItem(BaseModel):
"""批量异步任务中被明确拒绝的单个目标项(如未登记 CSI 指数)。"""

stock_code: str = Field(..., description="被拒绝的目标代码")
message: str = Field(..., description="拒绝原因")

model_config = ConfigDict(json_schema_extra={
"example": {
"stock_code": "930956.CSI",
"message": "unregistered CSI index: '930956.CSI' is not in the index registry",
}
})


class BatchTaskAcceptedResponse(BaseModel):
"""批量异步任务接受响应。"""

accepted: List[BatchTaskAcceptedItem] = Field(default_factory=list, description="成功提交的任务列表")
duplicates: List[BatchDuplicateTaskItem] = Field(default_factory=list, description="重复而跳过的任务列表")
rejected: Optional[List[RejectedTaskItem]] = Field(
None,
description="批量中被明确拒绝的目标列表(如未登记 CSI 指数),仅在异步批量请求中返回",
)
message: str = Field(..., description="汇总信息")

model_config = ConfigDict(json_schema_extra={
Expand Down Expand Up @@ -385,6 +407,10 @@ class TaskInfo(BaseModel):
None,
description="大盘复盘任务实际执行的 canonical 市场范围",
)
asset_type: Optional[Literal["stock", "index"]] = Field(
None,
description="parser 来源的可选资产类型(stock/index);由已提交的 analysis_target 透传,旧客户端可缺省",
)

model_config = ConfigDict(json_schema_extra={
"example": {
Expand Down
12 changes: 12 additions & 0 deletions api/v1/schemas/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class HistoryItem(BaseModel):
description="本次分析市场阶段低敏摘要",
)
created_at: Optional[str] = Field(None, description="创建时间")
asset_type: Optional[Literal["stock", "index"]] = Field(
None,
description="后端权威资产类型(stock/index);由持久化代码经 parser 生成。旧客户端与 market review 可缺省。",
)

model_config = ConfigDict(json_schema_extra={
"example": {
Expand Down Expand Up @@ -149,6 +153,10 @@ class ReportMeta(BaseModel):
None,
description="本次分析市场阶段低敏摘要",
)
asset_type: Optional[Literal["stock", "index"]] = Field(
None,
description="后端权威资产类型(stock/index);指数报告用于隐藏 stock-only 自选操作。market review 与旧客户端可缺省。",
)


class ReportSummary(BaseModel):
Expand Down Expand Up @@ -371,6 +379,10 @@ class StockBarItem(BaseModel):
None,
description="最新分析市场阶段低敏摘要",
)
asset_type: Optional[Literal["stock", "index"]] = Field(
None,
description="后端权威资产类型(stock/index);由持久化代码经 parser 生成。旧客户端可缺省。",
)
model_config = ConfigDict(json_schema_extra={
"example": {
"id": 1234,
Expand Down
2 changes: 1 addition & 1 deletion apps/dsa-web/src/components/report/ReportOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export const ReportOverview: React.FC<ReportOverviewProps> = ({

{/* 右侧:情绪指标 / 自选操作 */}
<div className="flex flex-col space-y-4">
{watchlist && meta.reportType !== 'market_review' && (
{watchlist && meta.reportType !== 'market_review' && meta.assetType !== 'index' && (
<Card variant="bordered" padding="sm" className="home-panel-card">
<div className="text-center space-y-3">
<span className="label-uppercase">{t('report.watchlist')}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,57 @@ describe('ReportOverview', () => {
expect(screen.getByText('领跌')).toBeInTheDocument();
expect(screen.getByText('-2.50%')).toBeInTheDocument();
});

it('hides the stock-only watchlist card for index reports', () => {
render(
<ReportOverview
meta={{ ...baseMeta, stockCode: 'sh000016', assetType: 'index' }}
summary={baseSummary}
watchlist={{
isInWatchlist: () => false,
onToggle: () => {},
isActioning: false,
actionMessage: null,
}}
/>,
);

expect(screen.queryByText('自选')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: /自选/ })).not.toBeInTheDocument();
});

it('keeps the stock-only watchlist card for stock reports', () => {
render(
<ReportOverview
meta={{ ...baseMeta, stockCode: '600519', assetType: 'stock' }}
summary={baseSummary}
watchlist={{
isInWatchlist: () => false,
onToggle: () => {},
isActioning: false,
actionMessage: null,
}}
/>,
);

expect(screen.getByText('自选')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '加入自选' })).toBeInTheDocument();
});

it('keeps the stock-only watchlist card when assetType is absent (legacy)', () => {
render(
<ReportOverview
meta={{ ...baseMeta, stockCode: '600519' }}
summary={baseSummary}
watchlist={{
isInWatchlist: () => false,
onToggle: () => {},
isActioning: false,
actionMessage: null,
}}
/>,
);

expect(screen.getByText('自选')).toBeInTheDocument();
});
});
Loading
Loading