Bladeren bron

update con imagenes, logs de llm

latapp 10 maanden geleden
bovenliggende
commit
577976b230
4 gewijzigde bestanden met toevoegingen van 48 en 116 verwijderingen
  1. 7 0
      main.py
  2. 35 110
      products.json
  3. 4 4
      public/js/app.js
  4. 2 2
      public/js/service.js

+ 7 - 0
main.py

@@ -157,6 +157,7 @@ class Message(BaseModel):
 
 class ChatCompletionRequest(BaseModel):
     messages: List[Message]
+    user: str
 
 class ItemWeb(BaseModel):
     id: int
@@ -308,6 +309,12 @@ async def chat_completions(request_data: ChatCompletionRequest, request: Request
 
     try:
         openai_response = await generate_completion(request_data.messages, session_identifier)
+        if os.path.exists("llm_logs.txt"):
+            with open("llm_logs.txt", "a") as f:
+                f.write(f"{request_data.user}: {openai_response}\n")
+        else:
+            with open("llm_logs.txt", "w") as f:
+                f.write(f"{request_data.user}: {openai_response}\n")
         return JSONResponse({"response": openai_response})
     except HTTPException as e: # Re-raise HTTPExceptions from called functions
         raise e

+ 35 - 110
products.json

@@ -1,130 +1,55 @@
 [
-  {
-    "id": 3,
-    "name": "Burlesque",
-    "category": "Cervezas Artesanales",
-    "description": "5.0º - IBU 12 - SRM 16 - Cerveza Ale ámbar maltosa con notas a caramelo y galleta.",
-    "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Burlesque"
-  },  {
-    "id": 15,
-    "name": "Black Mamba",
-    "category": "Cervezas Artesanales",
-    "description": "Porter - 6.0º - IBU 15 - SRM 35 - Cerveza Ale negra con carácter. Notas a toffee y chocolate.",
-    "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Black+Mamba"
-  },
   {
     "id": 1,
-    "name": "Witbier",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveza estilo belga, con un 50% de trigo en su receta, además de cascara de naranja dulce y semillas de cilantro. Es una cerveza refrescante con solo 4,5° de alcohol. De aspecto turbio y de color claro.",
+    "name": "Burlesque",
+    "type": "Cerveza",
+    "description": "Cerveza Ale ámbar, 5.0º - IBU 12",
     "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Witbier"
+    "image": "https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/6"
   },
   {
     "id": 2,
-    "name": "24K Gold",
-    "category": "Cervezas Artesanales",
-    "description": "Golden Ale - 4,5º - IBU 20 - SRM 4 - Cerveza Ale dorada. En boca sedosa y suave con notas cítricas.",
-    "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+24K+Gold"
-  },
-  {
-    "id": 4,
-    "name": "Hoppy Mosh",
-    "category": "Cervezas Artesanales",
-    "description": "IPA - 6.0º - IBU 38 - SRM 33 - Cerveza Ale cobriza con intensas notas a frutas tropicales.",
+    "name": "Bendicion Gitana",
+    "type": "Cerveza",
+    "description": "Pale Ale - 5,0º - IBU 15",
+    "price": 5000,
+    "image": "https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/15"
+  },{
+    "id":3,
+    "name":"Hoppy Mosh",
+    "type":"Cerveza",
+    "description":"IPA - 6.0º - IBU 38",
     "price": 6500,
-    "image": "https://placehold.co/300x200?text=Cerveza+Hoppy+Mosh"
+    "image":"https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/163"
   },
   {
+    "id": 4,
+    "name": "Black Mamba",
+    "type": "Cerveza",
+    "description": "Porter - 6.0º - IBU 15",
+    "price": 5000,
+    "image": "https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/12"
+  },{
     "id": 5,
-    "name": "Bendicion Gitana",
-    "category": "Cervezas Artesanales",
-    "description": "Blonde Ale - 5,0º - IBU 15 - SRM 3 - Lager ligera",
+    "name": "Marzen",
+    "type": "Cerveza",
+    "description": " Estilo Märzenbier, 5.0º - IBU 22",
     "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Bendicion+Gitana"
-  },
-  {
+    "image": "https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/665"
+  },{
     "id": 6,
-    "name": "Marzen",
-    "category": "Cervezas Artesanales",
-    "description": "Abv: 5,8 Ibu: 22. Estilo Märzenbier, es una cerveza lager típica alemana donde prevalecen las notas a pan tostado y corteza,. Color ámbar brillante.",
+    "name": "24k Gold",
+    "type": "Cerveza",
+    "description": "Golden Ale - 4,5º - IBU 20",
     "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Marzen"
+    "image": "https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/1"
   },
   {
     "id": 7,
-    "name": "Tropical Stout",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveza oscura y cremosa (7,5º - IBU 40), con tonos a cacao, café y ron. Dulce, con aromas a frutas como durazno y piña, ideal para días fríos.",
-    "price": 5500,
-    "image": "https://placehold.co/300x200?text=Cerveza+Tropical+Stout"
-  },
-  {
-    "id": 8,
-    "name": "Mexican Lager",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveceza muy ligera, chispeante y refrescante. De color dorado claro. Fácil de beber y de baja graduación alcohólica. Abv: 4,5% Ibu 15",
-    "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Mexican+Lager"
-  },
-  {
-    "id": 9,
-    "name": "Klein Alkoholfrei",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveza de solo 0.4º - IBU 15- SRM 10 Cerveza de cuerpo medio con sabores y aromas a pan y galleta dulce, amargor medio bajo, con un final balanceado.",
-    "price": 5000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Klein+Alkoholfrei"
-  },
-  {
-    "id": 10,
-    "name": "Rye IPA",
-    "category": "Cervezas Artesanales",
-    "description": "IPA con 15% de centeno (6.5º - IBU 40), textura intensa y notas a lúpulo americano. Marida perfecto con nuestra Pizza de pollo BBQ y la Rodeo Burger",
-    "price": 6400,
-    "image": "https://placehold.co/300x200?text=Cerveza+Rye+IPA"
-  },
-  {
-    "id": 11,
-    "name": "Queen Burlesque",
-    "category": "Cervezas Artesanales",
-    "description": "Ibu : 25 Abv: 8 grados Estilo: American Strong Ale Cerveza ale fuerte, de color cobrizo oscuro, destaca su maltosidad y Lupulos americanos; sabores a caramelo, toffe y pasas negras.",
-    "price": 6000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Queen+Burlesque"
-  },
-  {
-    "id": 12,
-    "name": "Soviet Riot",
-    "category": "Cervezas Artesanales",
-    "description": "Russian Imperial Stout - 8.8º - IBU 60 - SRM 40 - Cerveza Ale negra, intensa y compleja que a pesar de su graduación alcohólica, es balanceada. Notas a caramelo y café.",
+    "name": "Summer Klein 🌟",
+    "type": "Coctel",
+    "description": "Base Gin Juno, jugo de naranja, jugo de maracuya, jugo de limon y Ginger Beer de la casa",
     "price": 6500,
-    "image": "https://placehold.co/300x200?text=Cerveza+Soviet+Riot"
-  },
-  {
-    "id": 13,
-    "name": "Heller Doppelbock Barrica",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveza dorada colaborativa (9º - IBU 23), con notas a pan y flores. Dulzor suave por la miel, ligera pese a su graduación.",
-    "price": 6200,
-    "image": "https://placehold.co/300x200?text=Cerveza+Heller+Doppelbock+Barrica"
-  },
-  {
-    "id": 14,
-    "name": "Cyber Candy",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveza cobriza y turbia (6.9º - IBU 19), de cuerpo medio y final dulce. Notas tropicales marcadas por el lúpulo Sabro, como mango y avena.",
-    "price": 6500,
-    "image": "https://placehold.co/300x200?text=Cerveza+Cyber+Candy"
-  },
-
-  {
-    "id": 16,
-    "name": "Rauchbock",
-    "category": "Cervezas Artesanales",
-    "description": "Cerveza estilo Rauchbier (6.8º ABV), con carácter ahumado gracias a maltas y merkén de la Araucanía. Evoca jamón serrano con un final especiado.",
-    "price": 6000,
-    "image": "https://placehold.co/300x200?text=Cerveza+Rauchbock"
+    "image": "https://fudo-apps-storage.s3.sa-east-1.amazonaws.com/production/113378/common/products/655"
   }
 ]

+ 4 - 4
public/js/app.js

@@ -137,13 +137,13 @@ window.addToCart = async (productId, buttonElement = null) => {
     }
 
     if (buttonElement) {
-        const originalText = buttonElement.textContent;
+        const originalHTML = buttonElement.innerHTML;
         buttonElement.textContent = "✔ Agregado!";
         buttonElement.classList.replace('bg-accent-red', 'bg-green-500');
         buttonElement.classList.remove("hover:bg-red-700");
         buttonElement.disabled = true;
         setTimeout(() => {
-            buttonElement.textContent = originalText;
+            buttonElement.innerHTML = originalHTML;
             buttonElement.classList.replace('bg-green-500', 'bg-accent-red');
             buttonElement.classList.add("hover:bg-red-700");
             buttonElement.disabled = false;
@@ -170,7 +170,7 @@ window.removeFromCart = (productId, removeAll = false) => {
 function updateCartDisplay() {
     if (!cartItemsElement || !emptyCartTextElement || !checkoutButton || !cartCountElement) return;
     cartItemsElement.innerHTML = "";
-    cartCountElement.textContent = cart.length;
+    cartCountElement.textContent = cart.reduce((sum, item) => sum + item.quantity, 0);
     if (cart.length === 0) {
         cartCountElement.classList.add("hidden");
         emptyCartTextElement.classList.remove("hidden");
@@ -256,7 +256,7 @@ async function sendMessageToAI() {
             displayChatMessage("ai", "Hubo un problema al conectar con el Chef IA.");
         } else if (response === "not_init") {
             if (await serviceInitializeChat()) {
-                const response = await serviceSendMessage(userInput, chatHistory);
+                const response = await serviceSendMessage(userInput, chatHistory, userName);
                 if (response) {
                     chatHistory = response.messageList;
                     displayChatMessage("ai", response.assistantResponse);

+ 2 - 2
public/js/service.js

@@ -18,7 +18,7 @@ async function initializeChat() {
     console.error("Error al inicializar el chat:", error);
   }
 }
-async function sendMessage(message, messageList) {
+async function sendMessage(message, messageList, userName) {
   if (!chatToken) {
     return "not_init";
     return;
@@ -30,7 +30,7 @@ async function sendMessage(message, messageList) {
       "Content-Type": "application/json",
       "X-App-Token": chatToken
     },
-    body: JSON.stringify({ messages: messageList })
+    body: JSON.stringify({ messages: messageList, user: userName })
   });
   if (!response.ok) {
     const errorData = await response.json().catch(() => ({ message: "Respuesta no válida del servidor." }));