| import streamlit as st |
| from langchain_groq import ChatGroq |
| from apps.agent.constant import GROQ_API_KEY, MODEL_GROQ, CONFIG |
| from apps.agent.graph import Agent |
|
|
|
|
| llm = ChatGroq(model=MODEL_GROQ, api_key=GROQ_API_KEY, temperature=0.1) |
|
|
|
|
| agent = Agent(llm=llm) |
|
|
|
|
| def get_response(query: str): |
| response = agent.graph.invoke({"messages": ("user", query)}, CONFIG) |
| return response["messages"][-1].content |
|
|
| with st.sidebar: |
| st.header("Prof of Concept") |
| st.markdown( |
| """ |
| This is just a prototype chatbot, the data taken is based on the following sites: |
| Xano Documentation |
| - https://docs.xano.com/about |
| - https://releases.xano.com/?_gl=1*sifgtw*_ga*MTI5NTY3MTk5NS4xNzMwNjMzNjY3*_ga_EJWDZRK3CG*MTczMDgwNjg3Mi43LjEuMTczMDgwNjkyMy45LjAuODUyNzA5OTA4 |
| - https://docs.xano.com/onboarding-tutorial-reference |
| - https://docs.xano.com/faq |
| - https://docs.xano.com/about |
| - https://docs.xano.com/what-xano-includes |
| - https://docs.xano.com/what-xano-includes/instance |
| - https://docs.xano.com/what-xano-includes/workspace |
| - https://docs.xano.com/database/triggers |
| - https://docs.xano.com/fundamentals/the-development-life-cycle |
| |
| WeWeb Documentation |
| - https://docs.weweb.io/start-here/welcome.html |
| - https://docs.weweb.io/start-here/frequently-asked-questions.html |
| - https://docs.weweb.io/editor/intro-to-the-editor.html |
| - https://docs.weweb.io/editor/intro-to-html-css.html |
| - https://docs.weweb.io/editor/how-to-use-the-add-panel.html |
| - https://docs.weweb.io/editor/logs.html |
| - https://docs.weweb.io/editor/copilot/import-figma-designs.html |
| - https://docs.weweb.io/editor/app-settings/app-settings.html |
| - https://docs.weweb.io/editor/app-settings/pwa.html |
| """ |
| ) |
|
|
| st.header("Example Question") |
| st.markdown( |
| """ |
| Note: When asking a question, always add the word **xeno** or **weweb** so that the agent can easily find an accurate answer. |
| |
| - What is PWA? and how enabling mobile app features in Weweb? |
| - How installing a PWA on a phone in WeWeb? |
| - Will the Marketplace have templates that I can use to start my backend with? |
| - Can I scale my backend with Xano? |
| """ |
| ) |
|
|
| st.title("AI Agent Assistance") |
|
|
| if "messages" not in st.session_state: |
| st.session_state.messages = [] |
|
|
| for message in st.session_state.messages: |
| role = message.get("role", "assistant") |
| with st.chat_message(role): |
| if "output" in message: |
| st.markdown(message["output"]) |
|
|
|
|
| if prompt := st.chat_input("What do you want to know?"): |
| st.chat_message("user").markdown(prompt) |
| st.session_state.messages.append({"role": "user", "output": prompt}) |
|
|
| with st.spinner("Searching for an answer..."): |
| output_text = get_response(prompt) |
| print("Output", output_text) |
|
|
| |
| st.chat_message("assistant").markdown(output_text) |
| |
|
|
| |
| st.session_state.messages.append( |
| { |
| "role": "assistant", |
| "output": output_text, |
| } |
| ) |
|
|
|
|