Spaces:
Sleeping
Sleeping
Commit ·
cebfd3c
1
Parent(s): 8b18fd0
implemented RAG
Browse filesFiles changed (6)
- .gitignore+4-1
- __pycache__/mistral7b.cpython-310.pycAdded
- app.py+86-23
- chat_log.txtDeleted
- id_log.txtDeleted
- requirements.txt+2
1.env1234.env*.ipynb*.csv*.json
123456789101112133 unmodified lines171819202122231 unmodified line25262728293031323334353637383940414243444546474819 unmodified lines68697071727374757677787980818283848586878889904 unmodified lines95969798991001011027 unmodified lines110111112113114115116117import streamlit as stfrom mistral7b import mistralst.set_page_config(page_title="Ikigai Chat",)import timeif "messages" not in st.session_state:st.session_state.messages = []3 unmodified linesif "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.81 unmodified linest.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?"""]]if "top_k" not in st.session_state:st.session_state.top_k = 5if "repetion_penalty" not in st.session_state :st.session_state.repetion_penalty = 1with st.sidebar:st.markdown("# Model Analytics")st.write("Tokens used :", st.session_state['tokens_used'])19 unmodified lineslabel="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 ofof 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"]):4 unmodified linesst.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)7 unmodified linesst.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})12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455563 unmodified lines6061626364651 unmodified line67686970717273747576777879808182838485868788899091929394959697989910019 unmodified lines1201211221231241251261271281291301311321331341351361371381394 unmodified lines1441451461471481491501511521531541551561577 unmodified lines165166167168169170171172173174175176177178179180import streamlit as stfrom mistral7b import mistralimport timeimport pandas as pdimport pineconeimport osfrom dotenv import load_dotenvfrom sentence_transformers import SentenceTransformerload_dotenv()PINECONE_TOKEN = os.getenv('PINECONE_TOKEN')pinecone.init(api_key=PINECONE_TOKEN,environment='gcp-starter')pinecone_index = pinecone.Index('ikigai-chat')text_vectorizer = SentenceTransformer('all-distilroberta-v1')def gen_augmented_prompt(prompt, top_k) :query_vector = text_vectorizer.encode(prompt).tolist()res = pinecone_index.query(vector=query_vector, top_k=top_k, include_metadata=True)matches = res['matches']context = ""links = []for match in matches :context+=match["metadata"]["chunk"] + "\n\n"links.append(match["metadata"]["link"])generated_prompt = f"""FOR THIS GIVEN CONTEXT {context},ANSWER THE FOLLOWING PROMPT {prompt}"""return generated_prompt, linksdata = {"Attribute": ["LLM", "Text Vectorizer", "Vector Database","CPU", "System RAM"],"Information": ["Mistral-7B-Instruct-v0.1 (more models soon)","all-distilroberta-v1", "Hosted Pinecone" ,"2 vCPU", "16 GB"]}df = pd.DataFrame(data)st.set_page_config(page_title="Ikigai Chat",page_icon="🤖",)if "messages" not in st.session_state:st.session_state.messages = []3 unmodified linesif "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.81 unmodified linest.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 = 3if "repetion_penalty" not in st.session_state :st.session_state.repetion_penalty = 1if "rag_enabled" not in st.session_state :st.session_state.rag_enabled = Truewith st.sidebar:st.markdown("# Retrieval Settings")st.session_state.rag_enabled = st.toggle("Activate RAG")st.session_state.top_k = st.slider(label="Documents to retrieve",min_value=1, max_value=10, value=3, disabled=not st.session_state.rag_enabled)st.markdown("---")st.markdown("# Model Analytics")st.write("Tokens used :", st.session_state['tokens_used'])19 unmodified lineslabel="Repetion Penalty", min_value=0., max_value=1., step=0.1, value=1.)st.markdown("""> **2023 ©️ Pragnesh Barik**""")st.image("ikigai.svg")st.title("Ikigai Chat")st.caption("Maintained and developed by Pragnesh Barik.")with st.expander("What is Ikigai Chat ?"):st.info("""Ikigai Chat is a vector database powered chat agent, it works on the principle ofof 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.""")st.table(df)for message in st.session_state.messages:with st.chat_message(message["role"]):4 unmodified linesst.chat_message("user").markdown(prompt)st.session_state.messages.append({"role": "user", "content": prompt})tick = time.time()links = []if st.session_state.rag_enabled :with st.spinner("Fetching relevent documents from Ikigai Docs...."):prompt, links = gen_augmented_prompt(prompt=prompt, top_k=st.session_state.top_k)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)7 unmodified linesst.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})
72 unmodified lines73747572 unmodified lineswatchdog==3.0.0wcwidth==0.2.6zipp==3.17.072 unmodified lines737475767772 unmodified lineswatchdog==3.0.0wcwidth==0.2.6zipp==3.17.0sentence-transformers==2.2.2pinecone-client==2.2.4
.gitignore+4-1
__pycache__/mistral7b.cpython-310.pycAdded
app.py+86-23
chat_log.txtDeleted
id_log.txtDeleted
requirements.txt+2