repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: '🚀 Streamlit' |
| #3 | description: 'Integrate with Streamlit to plug and play with any LLM' |
| #4 | --- |
| #5 | |
| #6 | In this example, we will learn how to use `mistralai/Mixtral-8x7B-Instruct-v0.1` and Embedchain together with Streamlit to build a simple RAG chatbot. |
| #7 | |
| #8 |  |
| #9 | |
| #10 | ## Setup |
| #11 | |
| #12 | Install Embedchain and Streamlit. |
| #13 | ```bash |
| #14 | pip install embedchain streamlit |
| #15 | ``` |
| #16 | <Tabs> |
| #17 | <Tab title="app.py"> |
| #18 | ```python |
| #19 | import os |
| #20 | from embedchain import App |
| #21 | import streamlit as st |
| #22 | |
| #23 | with st.sidebar: |
| #24 | huggingface_access_token = st.text_input("Hugging face Token", key="chatbot_api_key", type="password") |
| #25 | "[Get Hugging Face Access Token](https://huggingface.co/settings/tokens)" |
| #26 | "[View the source code](https://github.com/embedchain/examples/mistral-streamlit)" |
| #27 | |
| #28 | |
| #29 | st.title("💬 Chatbot") |
| #30 | st.caption("🚀 An Embedchain app powered by Mistral!") |
| #31 | if "messages" not in st.session_state: |
| #32 | st.session_state.messages = [ |
| #33 | { |
| #34 | "role": "assistant", |
| #35 | "content": """ |
| #36 | Hi! I'm a chatbot. I can answer questions and learn new things!\n |
| #37 | Ask me anything and if you want me to learn something do `/add <source>`.\n |
| #38 | I can learn mostly everything. :) |
| #39 | """, |
| #40 | } |
| #41 | ] |
| #42 | |
| #43 | for message in st.session_state.messages: |
| #44 | with st.chat_message(message["role"]): |
| #45 | st.markdown(message["content"]) |
| #46 | |
| #47 | if prompt := st.chat_input("Ask me anything!"): |
| #48 | if not st.session_state.chatbot_api_key: |
| #49 | st.error("Please enter your Hugging Face Access Token") |
| #50 | st.stop() |
| #51 | |
| #52 | os.environ["HUGGINGFACE_ACCESS_TOKEN"] = st.session_state.chatbot_api_key |
| #53 | app = App.from_config(config_path="config.yaml") |
| #54 | |
| #55 | if prompt.startswith("/add"): |
| #56 | with st.chat_message("user"): |
| #57 | st.markdown(prompt) |
| #58 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #59 | prompt = prompt.replace("/add", "").strip() |
| #60 | with st.chat_message("assistant"): |
| #61 | message_placeholder = st.empty() |
| #62 | message_placeholder.markdown("Adding to knowledge base...") |
| #63 | app.add(prompt) |
| #64 | message_placeholder.markdown(f"Added {prompt} to knowledge base!") |
| #65 | st.session_state.messages.append({"role": "assistant", "content": f"Added {prompt} to knowledge base!"}) |
| #66 | st.stop() |
| #67 | |
| #68 | with st.chat_message("user"): |
| #69 | st.markdown(prompt) |
| #70 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #71 | |
| #72 | with st.chat_message("assistant"): |
| #73 | msg_placeholder = st.empty() |
| #74 | msg_placeholder.markdown("Thinking...") |
| #75 | full_response = "" |
| #76 | |
| #77 | for response in app.chat(prompt): |
| #78 | msg_placeholder.empty() |
| #79 | full_response += response |
| #80 | |
| #81 | msg_placeholder.markdown(full_response) |
| #82 | st.session_state.messages.append({"role": "assistant", "content": full_response}) |
| #83 | ``` |
| #84 | </Tab> |
| #85 | <Tab title="config.yaml"> |
| #86 | ```yaml |
| #87 | app: |
| #88 | config: |
| #89 | name: 'mistral-streamlit-app' |
| #90 | |
| #91 | llm: |
| #92 | provider: huggingface |
| #93 | config: |
| #94 | model: 'mistralai/Mixtral-8x7B-Instruct-v0.1' |
| #95 | temperature: 0.1 |
| #96 | max_tokens: 250 |
| #97 | top_p: 0.1 |
| #98 | stream: true |
| #99 | |
| #100 | embedder: |
| #101 | provider: huggingface |
| #102 | config: |
| #103 | model: 'sentence-transformers/all-mpnet-base-v2' |
| #104 | ``` |
| #105 | </Tab> |
| #106 | </Tabs> |
| #107 | |
| #108 | ## To run it locally, |
| #109 | |
| #110 | ```bash |
| #111 | streamlit run app.py |
| #112 | ``` |
| #113 |