Spaces:
Build error
Build error
Commit ·
2e2d510
1
Parent(s): e506679
Improved UI
Browse filesFiles changed (3)
18 unmodified lines192021222324252612 unmodified lines3940414243444523 unmodified lines6970717273747576777879808182838485868788899026 unmodified lines11711811912012112212338 unmodified lines16216316416516616716816917017117217317417517617717817918018118218318418518618718818918 unmodified linestext_vectorizer = SentenceTransformer('all-distilroberta-v1')chat_bots = {"Mistral 7B" : "mistralai/Mistral-7B-Instruct-v0.1","Zephyr 7B" : "HuggingFaceH4/zephyr-7b-alpha",}def gen_augmented_prompt(prompt, top_k) :12 unmodified linesgenerated_prompt = f"""FOR THIS GIVEN CONTEXT {context},ANSWER THE FOLLOWING PROMPT {prompt}"""return generated_prompt, links23 unmodified linesst.session_state.temp = 0.8if "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 helpingmodern analysts and operations teams automate data-intensive business, finance, analytics,and supply chain operations. One of their products is Inventory Ops, which automates inventorytracking 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."""]]if "top_k" not in st.session_state:st.session_state.top_k = 426 unmodified linesst.markdown("# Model Settings")st.session_state.chat_bot = st.sidebar.radio('Select one:', ["Mistral 7B","Zephyr 7B"])st.session_state.temp = st.slider(label="Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.9)38 unmodified linesprompt, 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] ,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"]formatted_links = ", ".join(links)with st.chat_message("assistant"):if st.session_state.rag_enabled :st.markdown(response + f"""\n\nFetched from :\n {formatted_links}""")else :st.markdown(response)st.session_state.history.append([prompt, response])if st.session_state.rag_enabled :st.session_state.messages.append({"role": "assistant", "content": response + f"""\n\nFetched from :\n {formatted_links}"""})else :st.session_state.messages.append({"role": "assistant", "content": response})18 unmodified lines1920212223242526272829303132333435363738394041424344454647484950515212 unmodified lines6566676869707123 unmodified lines959697989910010126 unmodified lines12812913013113213313438 unmodified lines17317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521618 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-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 helpingmodern analysts and operations teams automate data-intensive business, finance, analytics,and supply chain operations. One of their products is Inventory Ops, which automates inventorytracking 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 linesgenerated_prompt = f"""FOR THIS GIVEN CONTEXT {context},----ANSWER THE FOLLOWING PROMPT {prompt}"""return generated_prompt, links23 unmodified linesst.session_state.temp = 0.8if "history" not in st.session_state:st.session_state.history = [prompt_injection]if "top_k" not in st.session_state:st.session_state.top_k = 426 unmodified linesst.markdown("# Model Settings")st.session_state.chat_bot = st.sidebar.radio('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 linesprompt, links = gen_augmented_prompt(prompt=prompt, top_k=st.session_state.top_k)with st.spinner("Generating response...") :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)len_response = 0st.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.info( f"""\n\nFetched from :\n {formatted_links}""")else :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": full_response + f"""\n\nFetched from :\n {formatted_links}"""})else :st.session_state.messages.append({"role": "assistant", "content": full_response})
39 unmodified lines404142434445464739 unmodified linesstream = 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 outputreturn output39 unmodified lines404142434445464748495039 unmodified linesstream = 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 outputreturn stream
__pycache__/mistral7b.cpython-310.pyc
app.py+54-27
mistral7b.py+8-5