@@ -223,11 +223,15 @@ def get_completions(self, document: Document, complete_event: Any) -> Any:
223223 yield Completion (cmd , start_position = - len (text ))
224224
225225
226- def _make_prompt_session (session : ChatSession , style : Style , use_color : bool ) -> PromptSession :
226+ def _make_prompt_session (session : ChatSession , style : Style , use_color : bool , kb_dir : Path ) -> PromptSession :
227+ from prompt_toolkit .history import FileHistory
228+
229+ history_path = kb_dir / ".openkb" / "chat_history"
227230 return PromptSession (
228231 message = FormattedText ([("class:prompt" , ">>> " )]),
229232 style = style ,
230233 completer = _ChatCompleter (),
234+ history = FileHistory (str (history_path )),
231235 bottom_toolbar = (lambda : _bottom_toolbar (session )) if use_color else None ,
232236 )
233237
@@ -436,7 +440,7 @@ async def run_chat(
436440 if session .turn_count > 0 :
437441 _print_resume_view (session , style )
438442
439- prompt_session = _make_prompt_session (session , style , use_color )
443+ prompt_session = _make_prompt_session (session , style , use_color , kb_dir )
440444
441445 last_sigint = 0.0
442446
@@ -467,7 +471,7 @@ async def run_chat(
467471 if action == "new_session" :
468472 session = ChatSession .new (kb_dir , session .model , session .language )
469473 agent = build_query_agent (wiki_root , session .model , language = language )
470- prompt_session = _make_prompt_session (session , style , use_color )
474+ prompt_session = _make_prompt_session (session , style , use_color , kb_dir )
471475 continue
472476
473477 append_log (kb_dir / "wiki" , "query" , user_input )
0 commit comments