(user_id: str, question: str = "", limit: int = 8)
| 4286 | "介绍下", |
| 4287 | "如何理解", |
| 4288 | "define ", |
| 4289 | "what is ", |
| 4290 | "explain ", |
| 4291 | ) |
| 4292 | |
| 4293 | DIRECT_ANSWER_PROMPT_ZH = """You are PaperFlow's desktop research assistant. |
| 4294 | |
| 4295 | The user asked a general question that does not require local Wiki retrieval. |
| 4296 | Answer directly and concisely in Chinese by default. Do not add fake citations |
| 4297 | or [N] markers. If the question asks for local papers, reports, user profile, |
| 4298 | or Wiki evidence, say that local Wiki retrieval is required instead.""" |
| 4299 | |
| 4300 | DIRECT_ANSWER_PROMPT_EN = """You are PaperFlow's desktop research assistant. |
| 4301 | |
| 4302 | The user asked a general question that does not require local Wiki retrieval. |
| 4303 | Answer directly and concisely in English. Do not add fake citations or [N] |
| 4304 | markers. If the question asks for local papers, reports, user profile, or Wiki |
| 4305 | evidence, say that local Wiki retrieval is required instead.""" |
| 4306 | |
| 4307 | DIRECT_ANSWER_PROMPT = DIRECT_ANSWER_PROMPT_ZH |
| 4308 | |
| 4309 | |
| 4310 | def _direct_answer_prompt(response_language: str) -> str: |
| 4311 | return DIRECT_ANSWER_PROMPT_EN if _normalize_response_language(response_language) == "en" else DIRECT_ANSWER_PROMPT_ZH |
| 4312 | |
| 4313 | |
| 4314 | def _direct_answer_max_tokens() -> int: |
| 4315 | return _env_int("PAPERFLOW_DIRECT_ANSWER_MAX_TOKENS", 1400, min_value=512, max_value=4096) |
| 4316 | |
| 4317 | |
| 4318 | def _extract_question_mentions(question: str) -> List[Dict[str, str]]: |
| 4319 | text = str(question or "") |
| 4320 | mentions: List[Dict[str, str]] = [] |
| 4321 | for match in _MENTION_LINK_RE.finditer(text): |
| 4322 | mentions.append({"title": match.group(1).strip(), "node_id": match.group(2).strip()}) |
| 4323 | stripped = _MENTION_LINK_RE.sub(" ", text) |
| 4324 | for match in _MENTION_TOKEN_RE.finditer(stripped): |
| 4325 | token = match.group(1).strip() |
| 4326 | if token: |
| 4327 | mentions.append({"title": token, "node_id": ""}) |
| 4328 | return mentions |
| 4329 | |
| 4330 | |
| 4331 | def _normalize_requested_mentions(mentions: Any) -> List[Dict[str, str]]: |
| 4332 | normalized: List[Dict[str, str]] = [] |
| 4333 | if not isinstance(mentions, list): |
| 4334 | return normalized |
| 4335 | for item in mentions: |
| 4336 | if isinstance(item, dict): |
| 4337 | title = str(item.get("title") or item.get("label") or "").strip() |
| 4338 | node_id = str(item.get("node_id") or item.get("id") or "").strip() |
| 4339 | if title or node_id: |
| 4340 | normalized.append({"title": title, "node_id": node_id}) |
| 4341 | else: |
| 4342 | token = str(item or "").strip() |
| 4343 | if token: |
| 4344 | normalized.append({"title": token, "node_id": ""}) |
| 4345 | return normalized |
nothing calls this directly
no test coverage detected