File size: 1,994 Bytes
dbb0a0b
 
049ff35
7e9ffd9
b50f20a
132b796
049ff35
b50f20a
 
049ff35
 
 
 
 
 
 
dbb0a0b
c35885d
 
b50f20a
 
c35885d
b50f20a
 
 
7e9ffd9
 
 
 
 
049ff35
7e9ffd9
b50f20a
049ff35
7e9ffd9
 
b50f20a
c35885d
049ff35
 
 
 
c35885d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34ccb7c
 
 
c35885d
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os

os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["WANDB_API_KEY"] = os.getenv("WANDB_API_KEY")

import streamlit as st
import weave
from rag.rag import SimpleRAGPipeline

st.set_page_config(
    page_title="Chat with the Llama 3 paper!",
    page_icon="πŸ¦™",
    layout="centered",
    initial_sidebar_state="auto",
    menu_items=None,
)

st.session_state['session_id'] = '123abc'

WANDB_PROJECT = "paper_reader"

weave_client = weave.init(f"{WANDB_PROJECT}")

st.title("Chat with the Llama 3 paper πŸ’¬πŸ¦™")

with st.spinner('Loading the RAG pipeline...'):
    @st.cache_resource(show_spinner=False)
    def load_rag_pipeline():
        rag_pipeline = SimpleRAGPipeline()
        rag_pipeline.build_query_engine()

        return rag_pipeline


    if "rag_pipeline" not in st.session_state.keys():
        st.session_state.rag_pipeline = load_rag_pipeline()

    rag_pipeline = st.session_state["rag_pipeline"]    

with st.form("my_form"):
    query = st.text_area("Ask your question about the Llama 3 paper here:")
    submitted = st.form_submit_button("Submit")

if submitted:
    with st.spinner('Generating answer...'):
        output = rag_pipeline.predict(query)
        st.session_state["last_output"] = output
        text = ""
        for t in output["response"].response_gen:
            text += t
        st.session_state["last_text"] = text

    st.write_stream(output["response"].response_gen)


if "last_output" in st.session_state:
    output = st.session_state["last_output"]
    text = st.session_state["last_text"]
    st.write(text)

    url = output["url"]
    st.info(f"The weave trace url: {url}", icon="ℹ️")

    # use the weave client to retrieve the call and attach feedback
    st.button(":thumbsup:",   on_click=lambda: weave_client.call(output['call_id']).feedback.add_reaction("πŸ‘"), key='up')
    st.button(":thumbsdown:", on_click=lambda: weave_client.call(output['call_id']).feedback.add_reaction("πŸ‘Ž"), key='down')