(
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",
)
| 4782 | content=question, |
| 4783 | metadata={ |
| 4784 | "scope": result.get("scope"), |
| 4785 | "mentions": result.get("mentions") or [], |
| 4786 | "unresolved_mentions": result.get("unresolved_mentions") or [], |
| 4787 | }, |
| 4788 | ) |
| 4789 | db_ops.save_chat_message( |
| 4790 | user_id=user_id, |
| 4791 | session_id=saved_session_id, |
| 4792 | role="assistant", |
| 4793 | content=str(result.get("text") or ""), |
| 4794 | metadata=_chat_turn_metadata(result), |
| 4795 | ) |
| 4796 | result["session_id"] = saved_session_id |
| 4797 | return saved_session_id |
| 4798 | |
| 4799 | |
| 4800 | def _attach_chat_session( |
| 4801 | result: Dict[str, Any], |
| 4802 | *, |
| 4803 | user_id: str, |
| 4804 | session_id: str, |
| 4805 | question: str, |
| 4806 | persist_chat: bool, |
| 4807 | ) -> Dict[str, Any]: |
| 4808 | if persist_chat: |
| 4809 | _persist_chat_turn(user_id, session_id, question, result) |
| 4810 | elif session_id: |
| 4811 | result["session_id"] = session_id |
| 4812 | return result |
| 4813 | |
| 4814 | |
| 4815 | def _direct_answer_stream(question: str, response_language: str = "zh") -> Iterator[Dict[str, Any]]: |
| 4816 | started = time.time() |
| 4817 | language = _normalize_response_language(response_language) |
| 4818 | llm = build_llm_provider() |
| 4819 | llm_error = None |
| 4820 | text_parts: List[str] = [] |
| 4821 | meta = { |
| 4822 | "citations": [], |
| 4823 | "sources": [], |
| 4824 | "elapsed_ms": 0, |
| 4825 | "response_language": language, |
| 4826 | "token_usage": { |
| 4827 | "provider": getattr(llm, "name", "unknown"), |
| 4828 | "model": getattr(llm, "model", "unknown"), |
| 4829 | "prompt_tokens": 0, |
| 4830 | "completion_tokens": 0, |
| 4831 | "llm_error": None, |
| 4832 | }, |
| 4833 | "streaming": {"provider": getattr(llm, "name", "") != "mock", "transport": "sse"}, |
| 4834 | } |
| 4835 | yield {"event": "meta", "data": meta} |
| 4836 | if getattr(llm, "name", "") == "mock": |
| 4837 | text = ( |
| 4838 | "This question does not require the local Wiki. No usable LLM is configured, " |
| 4839 | "so the offline desktop app cannot generate a general answer right now. " |
| 4840 | "Use @ to select papers or switch to a Wiki scope for local-paper answers." |
| 4841 | if language == "en" |
nothing calls this directly
no test coverage detected