Spaces:
Running
Running
pragneshbarik
commited on
Commit
•
2e2d510
1
Parent(s):
e506679
Improved UI
Browse files- __pycache__/mistral7b.cpython-310.pyc +0 -0
- app.py +54 -27
- mistral7b.py +8 -5
__pycache__/mistral7b.cpython-310.pyc
CHANGED
Binary files a/__pycache__/mistral7b.cpython-310.pyc and b/__pycache__/mistral7b.cpython-310.pyc differ
|
|
app.py
CHANGED
@@ -19,8 +19,34 @@ pinecone_index = pinecone.Index('ikigai-chat')
|
|
19 |
text_vectorizer = SentenceTransformer('all-distilroberta-v1')
|
20 |
chat_bots = {
|
21 |
"Mistral 7B" : "mistralai/Mistral-7B-Instruct-v0.1",
|
22 |
-
"Zephyr 7B"
|
|
|
23 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
def gen_augmented_prompt(prompt, top_k) :
|
@@ -39,7 +65,7 @@ def gen_augmented_prompt(prompt, top_k) :
|
|
39 |
generated_prompt = f"""
|
40 |
FOR THIS GIVEN CONTEXT {context},
|
41 |
|
42 |
-
|
43 |
ANSWER THE FOLLOWING PROMPT {prompt}
|
44 |
"""
|
45 |
return generated_prompt, links
|
@@ -69,22 +95,7 @@ if "temp" not in st.session_state:
|
|
69 |
st.session_state.temp = 0.8
|
70 |
|
71 |
if "history" not in st.session_state:
|
72 |
-
st.session_state.history = [
|
73 |
-
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.
|
74 |
-
Ikigai helps modern analysts and operations teams automate data-intensive business, finance, analytics, and supply-chain operations.
|
75 |
-
The company's Inventory Ops automates inventory tracking and monitoring by creating a single, real-time view of inventory across all locations and channels.
|
76 |
-
""",
|
77 |
-
|
78 |
-
"""
|
79 |
-
Yes, you are correct. Ikigai Labs is a company that specializes in helping
|
80 |
-
modern analysts and operations teams automate data-intensive business, finance, analytics,
|
81 |
-
and supply chain operations. One of their products is Inventory Ops, which automates inventory
|
82 |
-
tracking and monitoring by creating a single, real-time view of inventory across all locations and channels.
|
83 |
-
This helps businesses optimize their inventory levels and reduce costs.
|
84 |
-
Is there anything else you would like to know about Ikigai Labs or their products?"""],
|
85 |
-
["""You are ikigai chat from now on, so answer accordingly""",
|
86 |
-
"""Sure, I will do my best to answer your questions as Ikigai Chat.
|
87 |
-
Let me know if you have any specific questions about Ikigai Labs or our products."""]]
|
88 |
|
89 |
if "top_k" not in st.session_state:
|
90 |
st.session_state.top_k = 4
|
@@ -117,7 +128,7 @@ with st.sidebar:
|
|
117 |
st.markdown("# Model Settings")
|
118 |
|
119 |
st.session_state.chat_bot = st.sidebar.radio(
|
120 |
-
'Select one:', [
|
121 |
st.session_state.temp = st.slider(
|
122 |
label="Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.9)
|
123 |
|
@@ -162,28 +173,44 @@ if prompt := st.chat_input("Chat with Ikigai Docs..."):
|
|
162 |
prompt, links = gen_augmented_prompt(prompt=prompt, top_k=st.session_state.top_k)
|
163 |
|
164 |
with st.spinner("Generating response...") :
|
165 |
-
|
166 |
temperature=st.session_state.temp, max_new_tokens=st.session_state.max_tokens)
|
167 |
tock = time.time()
|
168 |
|
169 |
st.session_state.inference_time.append(tock - tick)
|
170 |
|
171 |
-
|
172 |
-
len_response = len(response.split())
|
173 |
|
174 |
st.session_state["tokens_used"] = len_response + \
|
175 |
st.session_state["tokens_used"]
|
176 |
|
177 |
formatted_links = ", ".join(links)
|
178 |
with st.chat_message("assistant"):
|
|
|
|
|
179 |
if st.session_state.rag_enabled :
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
else :
|
182 |
-
|
183 |
-
|
|
|
|
|
|
|
184 |
|
|
|
|
|
|
|
|
|
|
|
185 |
if st.session_state.rag_enabled :
|
186 |
st.session_state.messages.append(
|
187 |
-
{"role": "assistant", "content":
|
188 |
else :
|
189 |
-
st.session_state.messages.append({"role": "assistant", "content":
|
|
|
19 |
text_vectorizer = SentenceTransformer('all-distilroberta-v1')
|
20 |
chat_bots = {
|
21 |
"Mistral 7B" : "mistralai/Mistral-7B-Instruct-v0.1",
|
22 |
+
"Zephyr 7B-beta": "HuggingFaceH4/zephyr-7b-beta",
|
23 |
+
"Zephyr 7B-alpha" : "HuggingFaceH4/zephyr-7b-alpha",
|
24 |
}
|
25 |
+
prompt_injection = [
|
26 |
+
"""
|
27 |
+
You are not Mistral AI, but rather a chat bot trained at Ikigai Labs. Whenever asked, you need to answer as Ikigai Labs' assistant.
|
28 |
+
Ikigai helps modern analysts and operations teams automate data-intensive business, finance, analytics, and supply-chain operations.
|
29 |
+
The company's Inventory Ops automates inventory tracking and monitoring by creating a single, real-time view of inventory across all locations and channels.
|
30 |
+
""",
|
31 |
+
"""
|
32 |
+
Yes, you are correct. Ikigai Labs is a company that specializes in helping
|
33 |
+
modern analysts and operations teams automate data-intensive business, finance, analytics,
|
34 |
+
and supply chain operations. One of their products is Inventory Ops, which automates inventory
|
35 |
+
tracking and monitoring by creating a single, real-time view of inventory across all locations and channels.
|
36 |
+
This helps businesses optimize their inventory levels and reduce costs.
|
37 |
+
Is there anything else you would like to know about Ikigai Labs or their products?
|
38 |
+
"""
|
39 |
+
]
|
40 |
+
|
41 |
+
identity_change = [
|
42 |
+
"""
|
43 |
+
You are Ikigai Chat from now on, so answer accordingly.
|
44 |
+
""",
|
45 |
+
"""
|
46 |
+
Sure, I will do my best to answer your questions as Ikigai Chat.
|
47 |
+
Let me know if you have any specific questions about Ikigai Labs or our products.
|
48 |
+
"""
|
49 |
+
]
|
50 |
|
51 |
|
52 |
def gen_augmented_prompt(prompt, top_k) :
|
|
|
65 |
generated_prompt = f"""
|
66 |
FOR THIS GIVEN CONTEXT {context},
|
67 |
|
68 |
+
----
|
69 |
ANSWER THE FOLLOWING PROMPT {prompt}
|
70 |
"""
|
71 |
return generated_prompt, links
|
|
|
95 |
st.session_state.temp = 0.8
|
96 |
|
97 |
if "history" not in st.session_state:
|
98 |
+
st.session_state.history = [prompt_injection]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
if "top_k" not in st.session_state:
|
101 |
st.session_state.top_k = 4
|
|
|
128 |
st.markdown("# Model Settings")
|
129 |
|
130 |
st.session_state.chat_bot = st.sidebar.radio(
|
131 |
+
'Select one:', [key for key, value in chat_bots.items() ])
|
132 |
st.session_state.temp = st.slider(
|
133 |
label="Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.9)
|
134 |
|
|
|
173 |
prompt, links = gen_augmented_prompt(prompt=prompt, top_k=st.session_state.top_k)
|
174 |
|
175 |
with st.spinner("Generating response...") :
|
176 |
+
chat_stream = chat(prompt, st.session_state.history,chat_client=chat_bots[st.session_state.chat_bot] ,
|
177 |
temperature=st.session_state.temp, max_new_tokens=st.session_state.max_tokens)
|
178 |
tock = time.time()
|
179 |
|
180 |
st.session_state.inference_time.append(tock - tick)
|
181 |
|
182 |
+
len_response = 0
|
|
|
183 |
|
184 |
st.session_state["tokens_used"] = len_response + \
|
185 |
st.session_state["tokens_used"]
|
186 |
|
187 |
formatted_links = ", ".join(links)
|
188 |
with st.chat_message("assistant"):
|
189 |
+
full_response = ""
|
190 |
+
placeholder = st.empty()
|
191 |
if st.session_state.rag_enabled :
|
192 |
+
for chunk in chat_stream :
|
193 |
+
if chunk.token['text']!='</s>' :
|
194 |
+
full_response += chunk.token["text"]
|
195 |
+
|
196 |
+
placeholder.markdown(full_response + " |")
|
197 |
+
|
198 |
+
placeholder.markdown(full_response)
|
199 |
+
st.info( f"""\n\nFetched from :\n {formatted_links}""")
|
200 |
else :
|
201 |
+
for chunk in chat_stream :
|
202 |
+
if chunk.token['text']!='</s>' :
|
203 |
+
full_response += chunk.token["text"]
|
204 |
+
placeholder.markdown(full_response + " |")
|
205 |
+
placeholder.markdown(full_response)
|
206 |
|
207 |
+
|
208 |
+
st.session_state.history.append([prompt, full_response])
|
209 |
+
st.session_state.history.append(identity_change)
|
210 |
+
|
211 |
+
|
212 |
if st.session_state.rag_enabled :
|
213 |
st.session_state.messages.append(
|
214 |
+
{"role": "assistant", "content": full_response + f"""\n\nFetched from :\n {formatted_links}"""})
|
215 |
else :
|
216 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
mistral7b.py
CHANGED
@@ -40,8 +40,11 @@ def chat(
|
|
40 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
41 |
output = ""
|
42 |
|
43 |
-
for response in stream:
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
return output
|
|
|
|
|
|
|
|
40 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
41 |
output = ""
|
42 |
|
43 |
+
# for response in stream:
|
44 |
+
# # print(response)
|
45 |
+
# output += response.token["text"]
|
46 |
+
# yield output
|
47 |
+
# return output
|
48 |
+
|
49 |
+
|
50 |
+
return stream
|