Refactor context passing: pipeline now accepts dict directly
Eliminate the NamedTemporaryFile workaround in server.py by adding a `context` dict parameter to run_freshrss_pipeline. The pipeline resolves filter context from the dict first, falling back to context_path, then defaulting to an empty FilterContext. Remove unused json/tempfile imports.
This commit is contained in:
+20
-34
@@ -3,8 +3,6 @@ from __future__ import annotations
|
||||
# MCP 服务入口:将内容提取、过滤、FreshRSS 全链路管道暴露为 MCP 工具。
|
||||
# 生产主入口是 run_freshrss_openclaw_pipeline,其余工具供单步调试使用。
|
||||
|
||||
import json
|
||||
import tempfile
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
@@ -95,38 +93,26 @@ def run_freshrss_openclaw_pipeline(
|
||||
include_item_reports: bool = False,
|
||||
) -> dict:
|
||||
"""Run the full FreshRSS -> extract -> LLM -> filter -> OpenClaw payload pipeline."""
|
||||
# context 若传入则序列化为临时文件再传给 pipeline(TODO: pipeline 改为直接接受 dict)
|
||||
temp_context_path: Path | None = None
|
||||
|
||||
try:
|
||||
if context is not None:
|
||||
with tempfile.NamedTemporaryFile("w", encoding="utf-8", suffix=".json", delete=False) as handle:
|
||||
json.dump(context, handle, ensure_ascii=False, indent=2)
|
||||
temp_context_path = Path(handle.name)
|
||||
|
||||
result = run_freshrss_pipeline(
|
||||
api_base_url=api_base_url,
|
||||
username=username,
|
||||
api_password=api_password,
|
||||
stream_id=stream_id,
|
||||
limit=limit,
|
||||
continuation=continuation,
|
||||
include_read=include_read,
|
||||
mark_read=mark_read,
|
||||
debug_artifacts=debug_artifacts,
|
||||
context_path=temp_context_path,
|
||||
max_retries=max_retries,
|
||||
timeout_seconds=timeout_seconds,
|
||||
llm_api_key=llm_api_key,
|
||||
llm_model=llm_model,
|
||||
llm_api_url=llm_api_url,
|
||||
run_id=run_id,
|
||||
delivery_date=date.fromisoformat(date_value) if date_value else None,
|
||||
output_dir=Path(output_dir) if output_dir else None,
|
||||
)
|
||||
finally:
|
||||
if temp_context_path and temp_context_path.exists():
|
||||
temp_context_path.unlink()
|
||||
result = run_freshrss_pipeline(
|
||||
api_base_url=api_base_url,
|
||||
username=username,
|
||||
api_password=api_password,
|
||||
stream_id=stream_id,
|
||||
limit=limit,
|
||||
continuation=continuation,
|
||||
include_read=include_read,
|
||||
mark_read=mark_read,
|
||||
debug_artifacts=debug_artifacts,
|
||||
context=context,
|
||||
max_retries=max_retries,
|
||||
timeout_seconds=timeout_seconds,
|
||||
llm_api_key=llm_api_key,
|
||||
llm_model=llm_model,
|
||||
llm_api_url=llm_api_url,
|
||||
run_id=run_id,
|
||||
delivery_date=date.fromisoformat(date_value) if date_value else None,
|
||||
output_dir=Path(output_dir) if output_dir else None,
|
||||
)
|
||||
|
||||
if not include_item_reports:
|
||||
result = {key: value for key, value in result.items() if key != "items"}
|
||||
|
||||
Reference in New Issue
Block a user