(
user_id: str,
question: str,
limit: int = 8,
scope: str = "all",
mentions: Any = None,
session_id: str = "",
persist_chat: bool = False,
response_language: str = "zh",
)
| 4683 | |
| 4684 | |
| 4685 | def _comparison_selection_required_message(response_language: str) -> str: |
| 4686 | if _normalize_response_language(response_language) == "en": |
| 4687 | return ( |
| 4688 | "Please use @ in the input box to select two specific papers first, " |
| 4689 | "or open a reference from the right panel before comparing them. " |
| 4690 | "Otherwise the local Wiki cannot know which two papers you mean." |
| 4691 | ) |
| 4692 | return "请先在输入框用 @ 选择两篇具体论文,或从右侧参考文献点“查看来源”后再对比。否则本地 Wiki 无法判断你说的“这两篇”是哪两篇。" |
| 4693 | |
| 4694 | |
| 4695 | def wiki_ask( |
| 4696 | user_id: str, |
| 4697 | question: str, |
| 4698 | limit: int = 8, |
| 4699 | scope: str = "all", |
| 4700 | mentions: Any = None, |
| 4701 | session_id: str = "", |
| 4702 | persist_chat: bool = False, |
| 4703 | response_language: str = "zh", |
| 4704 | ) -> Dict[str, Any]: |
| 4705 | if not user_id: |
| 4706 | raise ValueError("user_id is required") |
| 4707 | cleaned_question = str(question or "").strip() |
| 4708 | if not cleaned_question: |
| 4709 | raise ValueError("question is required") |
| 4710 | language = _normalize_response_language(response_language) |
| 4711 | safe_limit = max(1, min(12, int(limit or 8))) |
| 4712 | normalized_scope = str(scope or "all").strip().lower() |
| 4713 | scope_hint = _wiki_scope_hint(normalized_scope, language) |
| 4714 | resolved_nodes, resolved_mentions, unresolved_mentions = _resolve_wiki_mentions( |
| 4715 | user_id, |
| 4716 | cleaned_question, |
| 4717 | mentions, |
| 4718 | limit=6, |
| 4719 | ) |
| 4720 | mode, routing_reason = _question_route(cleaned_question, normalized_scope, resolved_mentions) |
| 4721 | if _comparison_needs_mentions(cleaned_question, resolved_nodes): |
| 4722 | result = _selection_required_answer( |
| 4723 | _comparison_selection_required_message(language), |
| 4724 | response_language=language, |
| 4725 | ) |
| 4726 | _apply_chat_metadata( |
| 4727 | result, |
| 4728 | mode="wiki", |
| 4729 | retrieval_required=True, |
| 4730 | routing_reason="mention_required", |
| 4731 | mentions=resolved_mentions, |
| 4732 | unresolved_mentions=unresolved_mentions, |
| 4733 | scope=normalized_scope, |
| 4734 | response_language=language, |
| 4735 | ) |
| 4736 | _attach_chat_session( |
| 4737 | result, |
| 4738 | user_id=user_id, |
| 4739 | session_id=session_id, |
| 4740 | question=cleaned_question, |
| 4741 | persist_chat=persist_chat, |
| 4742 | ) |
nothing calls this directly
no test coverage detected