Spaces:
Runtime error
Runtime error
| from routerchain import PromptFactory, destination_chain, destinations_str, router_template, router_prompt, multipromptchain, chat_openai | |
| from langchain.chains.router.llm_router import LLMRouterChain | |
| from events_loader import faiss_db | |
| from streaming import StreamHandler | |
| from routerchain import retrieve_events | |
| import streamlit as st | |
| import textwrap | |
| import markdown | |
| import utils | |
| def to_markdown(text): | |
| text = text.replace('•', ' *') | |
| return markdown.markdown(textwrap.indent(text, '> ', predicate=lambda _: True)) | |
| def answer_question(question, st_cb): | |
| events = retrieve_events(question=question) | |
| prompt_factory = PromptFactory(events) | |
| destination_chains = destination_chain(prompt_factory) | |
| destinations_str_ = destinations_str(prompt_factory) | |
| router_template_ = router_template(destinations_str_) | |
| router_prompt_ = router_prompt(router_template=router_template_) | |
| router_chain = LLMRouterChain.from_llm(chat_openai, router_prompt_) | |
| chain = multipromptchain(router_chain, destination_chains) | |
| result = chain.invoke({"input": question}, {"callbacks":[st_cb]}) | |
| return result | |