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 | import streamlit as st |
| #2 | |
| #3 | from embedchain import App |
| #4 | |
| #5 | |
| #6 | @st.cache_resource |
| #7 | def embedchain_bot(): |
| #8 | return App() |
| #9 | |
| #10 | |
| #11 | st.title("💬 Chatbot") |
| #12 | st.caption("🚀 An Embedchain app powered by OpenAI!") |
| #13 | if "messages" not in st.session_state: |
| #14 | st.session_state.messages = [ |
| #15 | { |
| #16 | "role": "assistant", |
| #17 | "content": """ |
| #18 | Hi! I'm a chatbot. I can answer questions and learn new things!\n |
| #19 | Ask me anything and if you want me to learn something do `/add <source>`.\n |
| #20 | I can learn mostly everything. :) |
| #21 | """, |
| #22 | } |
| #23 | ] |
| #24 | |
| #25 | for message in st.session_state.messages: |
| #26 | with st.chat_message(message["role"]): |
| #27 | st.markdown(message["content"]) |
| #28 | |
| #29 | if prompt := st.chat_input("Ask me anything!"): |
| #30 | app = embedchain_bot() |
| #31 | |
| #32 | if prompt.startswith("/add"): |
| #33 | with st.chat_message("user"): |
| #34 | st.markdown(prompt) |
| #35 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #36 | prompt = prompt.replace("/add", "").strip() |
| #37 | with st.chat_message("assistant"): |
| #38 | message_placeholder = st.empty() |
| #39 | message_placeholder.markdown("Adding to knowledge base...") |
| #40 | app.add(prompt) |
| #41 | message_placeholder.markdown(f"Added {prompt} to knowledge base!") |
| #42 | st.session_state.messages.append({"role": "assistant", "content": f"Added {prompt} to knowledge base!"}) |
| #43 | st.stop() |
| #44 | |
| #45 | with st.chat_message("user"): |
| #46 | st.markdown(prompt) |
| #47 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #48 | |
| #49 | with st.chat_message("assistant"): |
| #50 | msg_placeholder = st.empty() |
| #51 | msg_placeholder.markdown("Thinking...") |
| #52 | full_response = "" |
| #53 | |
| #54 | for response in app.chat(prompt): |
| #55 | msg_placeholder.empty() |
| #56 | full_response += response |
| #57 | |
| #58 | msg_placeholder.markdown(full_response) |
| #59 | st.session_state.messages.append({"role": "assistant", "content": full_response}) |
| #60 |