File size: 4,704 Bytes
d60dac5
2006c2b
 
8b18fd0
 
 
 
2006c2b
 
d60dac5
 
 
 
6c6516f
2006c2b
 
8b18fd0
2006c2b
 
99ff44d
6c6516f
99ff44d
 
6c6516f
8b18fd0
 
 
 
 
 
 
 
 
 
 
 
 
 
2006c2b
6c6516f
2006c2b
 
8b18fd0
 
2006c2b
 
8b18fd0
2006c2b
6c6516f
8b18fd0
6c6516f
 
8b18fd0
 
2006c2b
8b18fd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d60dac5
8b18fd0
2006c2b
6c6516f
 
8b18fd0
2006c2b
 
 
 
 
d60dac5
2006c2b
 
 
 
d60dac5
 
 
 
 
 
 
8b18fd0
d60dac5
 
6c6516f
8b18fd0
2006c2b
8b18fd0
 
 
2006c2b
d60dac5
2006c2b
8b18fd0
2006c2b
 
 
6c6516f
 
 
 
d60dac5
2006c2b
6c6516f
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import streamlit as st
from mistral7b import mistral

st.set_page_config(
        page_title="Ikigai Chat",
)

import time


if "messages" not in st.session_state:
    st.session_state.messages = []

if "tokens_used" not in st.session_state:
    st.session_state.tokens_used = 0

if "inference_time" not in st.session_state:
    st.session_state.inference_time = [0.00]


if "temp" not in st.session_state:
    st.session_state.temp = 0.8

if "history" not in st.session_state:
    st.session_state.history = [["""
                                  You are not mistral AI, but rather a chat bot trained at Ikigai Labs, when ever asked you need to answer as ikigai Labs' assistant. 
                                  Ikigai helps modern analysts and operations teams automate data-intensive business, finance, analytics, and supply-chain operations. 
                                  The company's Inventory Ops automates inventory tracking and monitoring by creating a single, real-time view of inventory across all locations and channels.""", 
                                  """
                                Yes, you are correct. Ikigai Labs is a company that specializes in helping 
                                modern analysts and operations teams automate data-intensive business, finance, analytics, 
                                and supply chain operations. One of their products is Inventory Ops, which automates inventory 
                                tracking and monitoring by creating a single, real-time view of inventory across all locations and channels.
                                This helps businesses optimize their inventory levels and reduce costs. 
                                Is there anything else you would like to know about Ikigai Labs or their products?


"""]]

if "top_k" not in st.session_state:
    st.session_state.top_k = 5

if "repetion_penalty" not in st.session_state :
    st.session_state.repetion_penalty = 1
with st.sidebar:
    st.markdown("# Model Analytics")
    
    st.write("Tokens used :", st.session_state['tokens_used'])
    st.write("Average Inference Time: ", round(sum(
        st.session_state["inference_time"]) / len(st.session_state["inference_time"]), 3), "Secs")
    st.write("Cost Incured :", round(
        0.033 * st.session_state['tokens_used'] / 1000, 3), "INR")
    
    st.markdown("---")

    st.markdown("# Model Settings")
    
    selected_model = st.sidebar.radio(
        'Select one:', ["Mistral 7B","Llama 7B" ,"GPT 3.5 Turbo", "GPT 4" ])
    st.session_state.temp = st.slider(
        label="Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.9)
    
    st.session_state.max_tokens = st.slider(
        label="New tokens to generate", min_value = 64, max_value=1048, step= 123, value=256
    )

    st.session_state.repetion_penalty = st.slider(
        label="Repetion Penalty", min_value=0., max_value=1., step=0.1, value=1. 
    )
    
    st.markdown("---")
    
    st.markdown("# Retrieval Settings")
    st.slider(label="Documents to retrieve",
              min_value=1, max_value=10, value=3)
    
    st.info("**2023 ©️ Pragnesh Barik**")


st.image("ikigai.svg")
st.title("Ikigai Chat")

with st.expander("What is Ikigai Chat ?"):
    st.info("""Ikigai Chat is a vector database powered chat agent, it works on the principle of 
                of Retrieval Augmented Generation (RAG), Its primary function revolves around maintaining an extensive repository of Ikigai Docs and providing users with answers that align with their queries. 
                This approach ensures a more refined and tailored response to user inquiries.""")


for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])


if prompt := st.chat_input("Chat with Ikigai Docs..."):
    st.chat_message("user").markdown(prompt)
    st.session_state.messages.append({"role": "user", "content": prompt})

    # st.write("ing")
    tick = time.time()
    with st.spinner("Generating response...") :
        response = mistral(prompt, st.session_state.history,
                       temperature=st.session_state.temp, max_new_tokens=st.session_state.max_tokens)
    tock = time.time()

    st.session_state.inference_time.append(tock - tick)
    
    response = response.replace("</s>", "")
    len_response = len(response.split())

    st.session_state["tokens_used"] = len_response + \
        st.session_state["tokens_used"]

    with st.chat_message("assistant"):
        st.markdown(response)
    st.session_state.history.append([prompt, response])
    st.session_state.messages.append(
        {"role": "assistant", "content": response})