SyedHutter commited on
Commit
6dc2e31
·
verified ·
1 Parent(s): 093a61b

app.py Beta 2 (push 6)

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -57,7 +57,7 @@ class CombinedResponse(BaseModel):
57
 
58
  # Helper Functions
59
  def extract_keywords(text: str) -> List[str]:
60
- doc = nlp(text) # Fixed syntax error here
61
  keywords = [token.text for token in doc if token.pos_ in ["NOUN", "PROPN"]]
62
  return list(set(keywords))
63
 
@@ -83,13 +83,15 @@ def get_product_context(products: List[Dict]) -> str:
83
  if not products:
84
  return ""
85
  product_str = "Here are some products: "
86
- product_str += ", ".join([f"'{p['name']}' (SKU: {p['skuNumber']}) - {p['description']}" for p in products[:2]])
 
87
  return product_str
88
 
89
  def format_response(response: str, products: List[Dict], intent: str) -> str:
90
  if intent in ["recommend_shirt", "recommend_shorts"] and products:
91
  product = products[0]
92
- return f"{response} For example, check out our '{product['name']}' (SKU: {product['skuNumber']})—it’s {product['description'].lower()}!"
 
93
  elif intent == "company_info":
94
  return f"{response} At Hutter Products GmbH, we specialize in sustainable product design and production!"
95
  return response
 
57
 
58
  # Helper Functions
59
  def extract_keywords(text: str) -> List[str]:
60
+ doc = nlp(text)
61
  keywords = [token.text for token in doc if token.pos_ in ["NOUN", "PROPN"]]
62
  return list(set(keywords))
63
 
 
83
  if not products:
84
  return ""
85
  product_str = "Here are some products: "
86
+ # Use .get() to handle missing 'skuNumber' with a fallback
87
+ product_str += ", ".join([f"'{p['name']}' (SKU: {p.get('skuNumber', 'N/A')}) - {p['description']}" for p in products[:2]])
88
  return product_str
89
 
90
  def format_response(response: str, products: List[Dict], intent: str) -> str:
91
  if intent in ["recommend_shirt", "recommend_shorts"] and products:
92
  product = products[0]
93
+ sku = product.get('skuNumber', 'N/A') # Handle missing skuNumber
94
+ return f"{response} For example, check out our '{product['name']}' (SKU: {sku})—it’s {product['description'].lower()}!"
95
  elif intent == "company_info":
96
  return f"{response} At Hutter Products GmbH, we specialize in sustainable product design and production!"
97
  return response