File size: 1,535 Bytes
4bd9bad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

import httpx
import streamlit as st


API_BASE_URL = os.getenv("API_BASE_URL", "http://127.0.0.1:8000")


st.set_page_config(page_title="Shopify Support AI", page_icon="AI", layout="centered")

st.title("Shopify Support AI")

customer_id = st.text_input("Customer ID", value="cust_001")
order_id = st.text_input("Order ID", value="1234")
message = st.text_area(
    "Customer message",
    value="My order #1234 is delayed. Can I get a refund?",
    height=140,
)
show_debug = st.checkbox("Show agent debug details", value=False)

if st.button("Submit ticket", type="primary"):
    payload = {
        "customer_id": customer_id,
        "message": message,
        "order_id": order_id or None,
    }

    try:
        with httpx.Client(timeout=30) as client:
            response = client.post(f"{API_BASE_URL}/api/tickets", json=payload)
            response.raise_for_status()
            data = response.json()
    except httpx.HTTPError as exc:
        st.error(f"Backend request failed: {exc}")
    else:
        st.subheader("AI Response")
        st.write(data["response"])

        if show_debug:
            col1, col2, col3 = st.columns(3)
            col1.metric("Ticket", data["ticket_id"])
            col2.metric("Confidence", data["confidence"])
            col3.metric("Escalated", "Yes" if data["escalated"] else "No")

            if data.get("escalation_reason"):
                st.warning(data["escalation_reason"])

            with st.expander("Agent trace"):
                st.json(data["trace"])