Spaces:
Running
Running
File size: 1,244 Bytes
831e906 a9fbba5 831e906 a9fbba5 831e906 a9fbba5 831e906 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import streamlit as st
from middlewares.utils import gen_augmented_prompt_via_websearch
from middlewares.chat_client import chat
def generate_chat_stream(session_state, query, config):
# 1. augments prompt according to the template
# 2. returns chat_stream and source links
# 3. chat_stream and source links are used by stream_handler and show_source
chat_bot_dict = config["CHAT_BOTS"]
links = []
if session_state.rag_enabled:
with st.spinner("Fetching relevent documents from Web...."):
query, links = gen_augmented_prompt_via_websearch(
prompt=query,
pre_context=session_state.pre_context,
post_context=session_state.post_context,
pre_prompt=session_state.pre_prompt,
post_prompt=session_state.post_prompt,
search_vendor=session_state.search_vendor,
top_k=session_state.top_k,
n_crawl=session_state.n_crawl,
pass_prev=session_state.pass_prev,
prev_output=session_state.history[-1][1],
)
with st.spinner("Generating response..."):
chat_stream = chat(session_state, query, config)
return chat_stream, links
|