[docs]defget_runner(yaml_path:Optional[str],project_dir:Optional[str],trial_path:Optional[str]):ifnotyaml_pathandnottrial_path:raiseValueError("yaml_path or trial_path must be given.")elifyaml_pathandtrial_path:raiseValueError("yaml_path and trial_path cannot be given at the same time.")elifyaml_path:returnRunner.from_yaml(yaml_path,project_dir=project_dir)eliftrial_path:returnRunner.from_trial_folder(trial_path)
[docs]defset_page_config():st.set_page_config(page_title="AutoRAG",page_icon="🤖",layout="wide",initial_sidebar_state="expanded",menu_items={"Get help":"https://github.com/Marker-Inc-Korea/AutoRAG/discussions","Report a bug":"https://github.com/Marker-Inc-Korea/AutoRAG/issues",},)
[docs]defset_page_header():st.header("📚 AutoRAG",anchor=False)st.caption("Input a question and get an answer from the given documents. ")
[docs]defchat_box(runner:Runner):ifquery:=st.chat_input("How can I help?"):# Add the user input to messages statest.session_state["messages"].append({"role":"user","content":query})withst.chat_message("user"):st.markdown(query)# Generate llama-index stream with user inputwithst.chat_message("assistant"):withst.spinner("Processing..."):response=st.write(runner.run(query))# Add the final response to messages statest.session_state["messages"].append({"role":"assistant","content":response})
@click.command()@click.option("--yaml_path",type=str,help="Path to the YAML file.")@click.option("--project_dir",type=str,help="Path to the project directory.")@click.option("--trial_path",type=str,help="Path to the trial directory.")defrun_web_server(yaml_path:Optional[str],project_dir:Optional[str],trial_path:Optional[str]):runner=get_runner(yaml_path,project_dir,trial_path)set_initial_state()set_page_config()set_page_header()chat_box(runner)if__name__=="__main__":run_web_server()