Navinor's picture
Upload folder using huggingface_hub
2c8b9ee verified
Raw
History Blame Contribute Delete
1.2 kB
from modules.routerchain import PromptFactory, destination_chain, destinations_str, router_template, router_prompt, multipromptchain, chat_openai
from langchain.chains.router.llm_router import LLMRouterChain
from modules.routerchain import retrieve_events
import streamlit as st
import textwrap
import markdown
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)
print(events)
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]})
result = chain.astream_events({"input": question}, {"callbacks":[st_cb]}, version="v2")
return result