Spaces:
Sleeping
Sleeping
icon
Browse files- bill.py +17 -12
- data/user_data/user_data_0724077190.json +1 -1
- logs/conversation_logs.json +62 -0
bill.py
CHANGED
@@ -78,22 +78,22 @@ def parseBill(data):
|
|
78 |
|
79 |
|
80 |
return {
|
81 |
-
"Data
|
82 |
"Serie numar factura": billNo,
|
83 |
"De plata": amountDue,
|
84 |
"Costuri suplimentare": extraCharge,
|
85 |
"Total plata factura": totalBillCosts,
|
86 |
"Costuri utilizatori": subscriberCosts,
|
87 |
-
"
|
88 |
-
"
|
89 |
-
|
90 |
}
|
91 |
|
92 |
def check_related_keys(question, user_id):
|
93 |
user_data = load_user_data(user_id)
|
94 |
categories = set()
|
95 |
for bill in user_data.get("bills", []):
|
96 |
-
categories.update(bill.get("
|
|
|
97 |
return [category for category in categories if category.lower() in question.lower()]
|
98 |
|
99 |
def process_query(query, user_id, model_name):
|
@@ -155,7 +155,8 @@ def log_conversation(user_id, user_query, assistant_response, tokens, cost):
|
|
155 |
|
156 |
|
157 |
def main():
|
158 |
-
st.title("
|
|
|
159 |
|
160 |
# Create a sidebar menu to choose between models
|
161 |
model_name = st.sidebar.selectbox("Choose OpenAI Model", ["gpt-4o-mini", "gpt-4o"])
|
@@ -189,10 +190,10 @@ def main():
|
|
189 |
st.write("Facturi existente (extras):")
|
190 |
for bill in st.session_state.user_data.get("bills", []):
|
191 |
st.write({
|
192 |
-
"Data factura": bill.get("
|
193 |
-
"
|
194 |
-
"De plata": bill.get("
|
195 |
-
"Costuri suplimentare": bill.get("
|
196 |
})
|
197 |
if not st.session_state.user_data:
|
198 |
uploaded_file = st.file_uploader("Incarca factura", type="json")
|
@@ -202,8 +203,8 @@ def main():
|
|
202 |
existing_data = load_user_data(st.session_state.user_id)
|
203 |
|
204 |
# Check if the billNo already exists in the existing data
|
205 |
-
existing_bill_nos = [bill.get("
|
206 |
-
if parsed_bill.get("
|
207 |
st.warning("Factură existentă.")
|
208 |
else:
|
209 |
if "bills" not in existing_data:
|
@@ -248,6 +249,10 @@ def main():
|
|
248 |
# Display the latest user message in the chat
|
249 |
st.chat_message("user").write(st.session_state["messages"][-1]["content"])
|
250 |
|
|
|
|
|
|
|
|
|
251 |
# Now call GPT-4 with the entire conversation
|
252 |
completion = client.chat.completions.create(
|
253 |
model=model_name,
|
|
|
78 |
|
79 |
|
80 |
return {
|
81 |
+
"Data factura": billDate,
|
82 |
"Serie numar factura": billNo,
|
83 |
"De plata": amountDue,
|
84 |
"Costuri suplimentare": extraCharge,
|
85 |
"Total plata factura": totalBillCosts,
|
86 |
"Costuri utilizatori": subscriberCosts,
|
87 |
+
"Categorii": list(categories),
|
88 |
+
"Costuri": list(names)
|
|
|
89 |
}
|
90 |
|
91 |
def check_related_keys(question, user_id):
|
92 |
user_data = load_user_data(user_id)
|
93 |
categories = set()
|
94 |
for bill in user_data.get("bills", []):
|
95 |
+
categories.update(bill.get("Categorii", []))
|
96 |
+
st.write(f"Categorii: {categories}")
|
97 |
return [category for category in categories if category.lower() in question.lower()]
|
98 |
|
99 |
def process_query(query, user_id, model_name):
|
|
|
155 |
|
156 |
|
157 |
def main():
|
158 |
+
st.title("Bill info LLM Agent (OpenAI)")
|
159 |
+
st.image("https://miro.medium.com/v2/resize:fit:100/format:webp/1*NfE0G4nEj4xX7Z_8dSx83g.png")
|
160 |
|
161 |
# Create a sidebar menu to choose between models
|
162 |
model_name = st.sidebar.selectbox("Choose OpenAI Model", ["gpt-4o-mini", "gpt-4o"])
|
|
|
190 |
st.write("Facturi existente (extras):")
|
191 |
for bill in st.session_state.user_data.get("bills", []):
|
192 |
st.write({
|
193 |
+
"Data factura": bill.get("Data factura"),
|
194 |
+
"Serie numar factura": bill.get("Serie numar factura"),
|
195 |
+
"De plata": bill.get("De plata"),
|
196 |
+
"Costuri suplimentare": bill.get("Costuri suplimentare")
|
197 |
})
|
198 |
if not st.session_state.user_data:
|
199 |
uploaded_file = st.file_uploader("Incarca factura", type="json")
|
|
|
203 |
existing_data = load_user_data(st.session_state.user_id)
|
204 |
|
205 |
# Check if the billNo already exists in the existing data
|
206 |
+
existing_bill_nos = [bill.get("Data factura") for bill in existing_data.get("bills", [])]
|
207 |
+
if parsed_bill.get("Data factura") in existing_bill_nos:
|
208 |
st.warning("Factură existentă.")
|
209 |
else:
|
210 |
if "bills" not in existing_data:
|
|
|
249 |
# Display the latest user message in the chat
|
250 |
st.chat_message("user").write(st.session_state["messages"][-1]["content"])
|
251 |
|
252 |
+
# Display the related keys
|
253 |
+
related_keys = check_related_keys(prompt, st.session_state["user_id"])
|
254 |
+
st.write("Focus pe entitatile:", related_keys)
|
255 |
+
|
256 |
# Now call GPT-4 with the entire conversation
|
257 |
completion = client.chat.completions.create(
|
258 |
model=model_name,
|
data/user_data/user_data_0724077190.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"bills": [{"
|
|
|
1 |
+
{"bills": [{"Data factura": "2025-01-06", "Serie numar factura": "VDF685952701", "De plata": 5550.46, "Costuri suplimentare": 5445.53, "Total plata factura": [{"categorie": "Total factura curenta", "amount": 104.93}, {"categorie": "TVA 19%", "amount": 16.75}, {"categorie": "Total rate terminal", "amount": 5445.53}, {"categorie": "Abonamente si extraoptiuni", "amount": 91.17}, {"categorie": "Reduceri", "amount": -2.99}, {"categorie": "Rest plata", "amount": -5073.74}, {"categorie": "Sold precedent", "amount": -5073.74}, {"categorie": "Total de plata", "amount": 476.72}], "Costuri utilizatori": [{"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Red 11", "Valoare": 34.08}, {"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Reducere promo", "Valoare": -8.52}, {"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Secure Net", "Valoare": 2.99}, {"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Reducere promotionala 12 luni", "Valoare": -4.26}, {"Numar telefon": "724015962", "Categorie cost": "Rate terminal", "Cost": "Promotie Vodafone Smartphone cu plata in rate 12/36", "Valoare": 70.99}, {"Numar telefon": "373920691", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Abonament Vodafone WiFi Instant Nelimitat+", "Valoare": 29.82}, {"Numar telefon": "724077190", "Categorie cost": "Reduceri", "Cost": "Reducere Secure Net", "Valoare": -2.99}, {"Numar telefon": "724077190", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "RED Start", "Valoare": 38.33}, {"Numar telefon": "724077190", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Secure Net", "Valoare": 2.99}, {"Numar telefon": "724077190", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Reducere promotionala 12 luni", "Valoare": -4.26}, {"Numar telefon": "724077190", "Categorie cost": "Rate terminal", "Cost": "Valoare rate ramase pana la expirare contract", "Valoare": 5374.54}], "Categorii": ["Reduceri", "Abonamente si extraoptiuni", "Rate terminal", "Total sume datorate rate terminal"], "Costuri": ["Valoare rate ramase pana la expirare contract", "Secure Net", "Promotie Vodafone Smartphone cu plata in rate 12/36", "Abonament Vodafone WiFi Instant Nelimitat+", "Reducere promotionala 12 luni", "RED Start", "Reducere promo", "Red 11", "Reducere Secure Net"]}]}
|
logs/conversation_logs.json
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"timestamp": "2025-01-15T11:16:50.217450",
|
4 |
+
"user_id": "0727723568",
|
5 |
+
"user_query": "Data factura?",
|
6 |
+
"assistant_response": "Data factur\u0103: 2024-12-20",
|
7 |
+
"tokens": {
|
8 |
+
"prompt_tokens": 599,
|
9 |
+
"completion_tokens": 12,
|
10 |
+
"total_tokens": 611
|
11 |
+
},
|
12 |
+
"cost": 0.009165
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"timestamp": "2025-01-15T11:24:49.439585",
|
16 |
+
"user_id": "0724077190",
|
17 |
+
"user_query": "de ce asa mult",
|
18 |
+
"assistant_response": "Factura \u00eenregistrat\u0103 la data de 6 ianuarie 2025, cu seria \u0219i num\u0103rul VDF685952701, eviden\u021biaz\u0103 costuri totale semnificative. \n\nTotalul de plat\u0103 pentru aceasta factur\u0103 este de 476.72 lei, care include:\n\n- Total factura curent\u0103: 104.93 lei\n- TVA (19%): 16.75 lei\n- Total rate terminal: 5445.53 lei\n- Abonamente \u0219i extraop\u021biuni: 91.17 lei\n- Reduceri: -2.99 lei (care a redus suma total\u0103)\n- Rest plata: -5073.74 lei\n- Sold precedent: -5073.74 lei\n\nDintre acestea, suma cea mai mare provine din totalul ratei terminale, care reprezint\u0103 o cheltuial\u0103 major\u0103. Pe l\u00e2ng\u0103 aceasta, abonamentele \u0219i extraop\u021biunile contribuie la costuri, dar \u0219i reducerile aplicate au un impact asupra sumei finale de plat\u0103.\n\nAceste costuri sunt probabil generate de servicii \u0219i produse ad\u0103ugate, cum ar fi terminale \u0219i abonamente, care \u00ee\u0219i fac sim\u021bite efectele \u00eentr-un mod considerabil asupra facturii.",
|
19 |
+
"tokens": {
|
20 |
+
"prompt_tokens": 835,
|
21 |
+
"completion_tokens": 269,
|
22 |
+
"total_tokens": 1104
|
23 |
+
},
|
24 |
+
"cost": 0.01656
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"timestamp": "2025-01-15T11:25:31.435444",
|
28 |
+
"user_id": "0724077190",
|
29 |
+
"user_query": "Totusi, de ce Total rate terminal costa cat un elicopter",
|
30 |
+
"assistant_response": "Costul total al ratei terminal, adic\u0103 5445.53 lei, poate p\u0103rea exagerat \u0219i comparabil cu pre\u021bul unui elicopter mic din cauza mai multor factori:\n\n1. **Tipul dispozitivului**: Dac\u0103 terminalul achizi\u021bionat este un dispozitiv avansat sau recent lansat (de exemplu, un smartphone de ultim\u0103 genera\u021bie), pre\u021bul acestuia poate contribui semnificativ la totalul ratei.\n\n2. **Durata contractului**: Rata terminal poate fi distribuit\u0103 pe o perioad\u0103 extins\u0103 (12 sau 36 de luni), iar suma total\u0103 se acumuleaz\u0103, ceea ce face ca achizi\u021bia s\u0103 par\u0103 mai costisitoare pe termen lung.\n\n3. **Costuri adi\u021bionale**: \u00cen majoritatea cazurilor, ratele include \u0219i taxe sau costuri adi\u021bionale asociate cu contractul de servicii, cum ar fi asigurarea sau protec\u021biile suplimentare, care pot cre\u0219te semnificativ pre\u021bul final.\n\n4. **Pachete promo\u021bionale**: Unele oferte includ beneficii adi\u021bionale sau combina\u021bii de produse, care pot influen\u021ba suma total\u0103.\n\n5. **Reduceri \u0219i promo\u021bii**: Reducerile aplicate pe parcursul perioadei de contract pot masca pre\u021bul total pe care clientul ar trebui s\u0103-l pl\u0103teasc\u0103 la final; astfel, rata terminal poate p\u0103rea mai mare \u00een compara\u021bie cu alte oferte disponibile.\n\n\u00cen concluzie, pre\u021bul total al ratei terminal depinde de combina\u021bia dintre tipul de terminal, costurile adi\u021bionale, durata contractului \u0219i ofertele disponibile.",
|
31 |
+
"tokens": {
|
32 |
+
"prompt_tokens": 1124,
|
33 |
+
"completion_tokens": 362,
|
34 |
+
"total_tokens": 1486
|
35 |
+
},
|
36 |
+
"cost": 0.022289999999999997
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"timestamp": "2025-01-15T11:27:26.921762",
|
40 |
+
"user_id": "0724077190",
|
41 |
+
"user_query": "pe bune? asa mult?",
|
42 |
+
"assistant_response": "Pe baza informa\u021biilor din factura citat\u0103, iat\u0103 un rezumat al costurilor:\n\n- **De plat\u0103**: 5550.46 lei\n- **Costuri suplimentare**: 5445.53 lei\n- **Total de plata**: 476.72 lei\n\n\u00cen detaliu, costurile incluse \u00een totalul facturii sunt:\n\n1. **Total factura curent\u0103**: 104.93 lei\n2. **TVA 19%**: 16.75 lei\n3. **Total rate terminal**: 5445.53 lei\n4. **Abonamente \u0219i extraop\u021biuni**: 91.17 lei\n5. **Reduceri**: -2.99 lei\n6. **Rest plata**: -5073.74 lei\n7. **Sold precedent**: -5073.74 lei\n\nAv\u00e2nd \u00een vedere costurile \u0219i sumele men\u021bionate, da, se poate considera c\u0103 suma total\u0103 este semnificativ\u0103.",
|
43 |
+
"tokens": {
|
44 |
+
"prompt_tokens": 836,
|
45 |
+
"completion_tokens": 215,
|
46 |
+
"total_tokens": 1051
|
47 |
+
},
|
48 |
+
"cost": 0.015764999999999998
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"timestamp": "2025-01-15T11:27:47.818303",
|
52 |
+
"user_id": "0724077190",
|
53 |
+
"user_query": "Rate terminal costa cat un elefant",
|
54 |
+
"assistant_response": "Costul total pentru ratele terminale este de 5445.53 lei, ceea ce, comparativ cu pre\u021bul unui elefant (care poate varia semnificativ, dar este adesea de ordinul zecilor de mii de lei sau chiar mai mult), poate p\u0103rea un salariu pe o lun\u0103 sau mai mult, dar nu se poate compara direct f\u0103r\u0103 a avea o referin\u021b\u0103 specific\u0103 pentru pre\u021bul unui elefant. \n\nEste o sum\u0103 considerabil\u0103 \u00een contextul facturii, dar pentru a face o compara\u021bie cu un elefant, ar trebui s\u0103 cuno\u0219ti pre\u021bul exact al acestuia \u00een pia\u021b\u0103. Totu\u0219i, se poate \u00een\u021belege ironia ta \u00een leg\u0103tur\u0103 cu costurile mari!",
|
55 |
+
"tokens": {
|
56 |
+
"prompt_tokens": 1066,
|
57 |
+
"completion_tokens": 163,
|
58 |
+
"total_tokens": 1229
|
59 |
+
},
|
60 |
+
"cost": 0.018435
|
61 |
+
}
|
62 |
+
]
|