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:
@@ -80,6 +80,7 @@ def run_freshrss_pipeline(
|
||||
debug_artifacts: bool = False,
|
||||
prompt: Path | None = None,
|
||||
rules: Path | None = None,
|
||||
context: dict[str, Any] | None = None,
|
||||
context_path: Path | None = None,
|
||||
max_retries: int = 2,
|
||||
timeout_seconds: float = 60.0,
|
||||
@@ -137,7 +138,13 @@ def run_freshrss_pipeline(
|
||||
_save_json(items_list_output, [item.model_dump(mode="json") for item in items])
|
||||
|
||||
loaded_rules = load_filter_rules(resolved_rules_path)
|
||||
context = FilterContext.model_validate(_load_json(context_path)) if context_path else FilterContext()
|
||||
# context 优先使用直接传入的 dict,其次读取 context_path 文件,两者均缺失则使用空 context
|
||||
if context is not None:
|
||||
filter_context = FilterContext.model_validate(context)
|
||||
elif context_path is not None:
|
||||
filter_context = FilterContext.model_validate(_load_json(context_path))
|
||||
else:
|
||||
filter_context = FilterContext()
|
||||
|
||||
delivered_candidates: list[OpenClawCandidateInput] = []
|
||||
delivered_item_ids: list[str] = []
|
||||
@@ -204,7 +211,7 @@ def run_freshrss_pipeline(
|
||||
|
||||
summary = LlmSummaryResult.model_validate(summary_payload)
|
||||
decision = evaluate_filter_rules(
|
||||
FilterInput(item=item, article=extraction.article, summary=summary, context=context),
|
||||
FilterInput(item=item, article=extraction.article, summary=summary, context=filter_context),
|
||||
loaded_rules,
|
||||
)
|
||||
if filter_path is not None:
|
||||
|
||||
Reference in New Issue
Block a user