Spaces:
Sleeping
Sleeping
Commit ·
2e2d510
1
Parent(s): e506679
Improved UI
Browse filesFiles changed (3)
18 unmodified lines192021222223242526272829303132333435363738394041424344454647484950515212 unmodified lines656667426869707123 unmodified lines95969772737475767778798081828384858687989910010126 unmodified lines12812913012013113213313438 unmodified lines17317417516517617717817918018117117218218318418518618718818919019119219319419519619719818019920018218320120220320420520620720820921021121221318721421518921618 unmodified linestext_vectorizer = SentenceTransformer('all-distilroberta-v1')chat_bots = { "Mistral 7B" : "mistralai/Mistral-7B-Instruct-v0.1", "Zephyr 7B-beta": "HuggingFaceH4/zephyr-7b-beta", "Zephyr 7B" : "HuggingFaceH4/zephyr-7b-alpha", "Zephyr 7B-alpha" : "HuggingFaceH4/zephyr-7b-alpha",}prompt_injection = [ """ You are not Mistral AI, but rather a chat bot trained at Ikigai Labs. Whenever 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? """]
identity_change = [ """ You are Ikigai Chat from now on, so answer accordingly. """, """ Sure, I will do my best to answer your questions as Ikigai Chat. Let me know if you have any specific questions about Ikigai Labs or our products. """]
def gen_augmented_prompt(prompt, top_k) :12 unmodified lines generated_prompt = f""" FOR THIS GIVEN CONTEXT {context},
---- ANSWER THE FOLLOWING PROMPT {prompt} """ return generated_prompt, links23 unmodified lines 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?"""], ["""You are ikigai chat from now on, so answer accordingly""", """Sure, I will do my best to answer your questions as Ikigai Chat. Let me know if you have any specific questions about Ikigai Labs or our products."""]] st.session_state.history = [prompt_injection]
if "top_k" not in st.session_state: st.session_state.top_k = 426 unmodified lines st.markdown("# Model Settings") st.session_state.chat_bot = st.sidebar.radio( 'Select one:', ["Mistral 7B","Zephyr 7B"]) 'Select one:', [key for key, value in chat_bots.items() ]) st.session_state.temp = st.slider( label="Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.9) 38 unmodified lines prompt, links = gen_augmented_prompt(prompt=prompt, top_k=st.session_state.top_k) with st.spinner("Generating response...") : response = chat(prompt, st.session_state.history,chat_client=chat_bots[st.session_state.chat_bot] , chat_stream = chat(prompt, st.session_state.history,chat_client=chat_bots[st.session_state.chat_bot] , 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()) len_response = 0
st.session_state["tokens_used"] = len_response + \ st.session_state["tokens_used"]
formatted_links = ", ".join(links) with st.chat_message("assistant"): full_response = "" placeholder = st.empty() if st.session_state.rag_enabled : for chunk in chat_stream : if chunk.token['text']!='</s>' : full_response += chunk.token["text"]
placeholder.markdown(full_response + " |") placeholder.markdown(full_response) st.markdown(response + f"""\n\nFetched from :\n {formatted_links}""") st.info( f"""\n\nFetched from :\n {formatted_links}""") else : st.markdown(response) st.session_state.history.append([prompt, response]) for chunk in chat_stream : if chunk.token['text']!='</s>' : full_response += chunk.token["text"] placeholder.markdown(full_response + " |") placeholder.markdown(full_response)
st.session_state.history.append([prompt, full_response]) st.session_state.history.append(identity_change)
if st.session_state.rag_enabled : st.session_state.messages.append( {"role": "assistant", "content": response + f"""\n\nFetched from :\n {formatted_links}"""}) {"role": "assistant", "content": full_response + f"""\n\nFetched from :\n {formatted_links}"""}) else : st.session_state.messages.append({"role": "assistant", "content": response}) st.session_state.messages.append({"role": "assistant", "content": full_response})39 unmodified lines4041424344454647434445464748495039 unmodified lines stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False) output = ""
for response in stream: # print(response) output += response.token.text # yield output return output # for response in stream: # # print(response) # output += response.token["text"] # yield output # return output
return stream__pycache__/mistral7b.cpython-310.pyc
app.py+54-27
mistral7b.py+8-5