MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / wiki_ask_stream

Function wiki_ask_stream

deployments/desktop/shared/agents.py:4784–4900  ·  view source on GitHub ↗
(
    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",
)

Source from the content-addressed store, hash-verified

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
4800def _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
4815def _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"

Callers

nothing calls this directly

Calls 12

_wiki_scope_hintFunction · 0.85
_resolve_wiki_mentionsFunction · 0.85
_question_routeFunction · 0.85
_apply_chat_metadataFunction · 0.85
_attach_chat_sessionFunction · 0.85
_direct_answer_streamFunction · 0.85
_chat_pinned_nodesFunction · 0.85
_visible_wiki_node_idsFunction · 0.85

Tested by

no test coverage detected