File size: 3,251 Bytes
2a51e7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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)

    # Display assistant response and SQL query
    st.chat_message("assistant").markdown(output_text)  # Kenapa ini tidak muncul di UI?
    

    # Append assistant response to session state
    st.session_state.messages.append(
        {
            "role": "assistant",
            "output": output_text,
        }
    )