williamagyapong commited on
Commit
f281e50
·
verified ·
1 Parent(s): 22f4c37

Update utility.py

Browse files
Files changed (1) hide show
  1. utility.py +13 -1
utility.py CHANGED
@@ -134,7 +134,7 @@ def generateResponse(prompt,model='Meta-Llama-3.1-70B-Instruct'):
134
  model = model,
135
  # model="gpt-4o",
136
  messages=[
137
- {"role": "system", "content": f"You are a helpful assistant that classifies transactions written in natural language into CRUD operations (Create, Read, Update, and Delete) and extracts relevant information. You should be able to recognize the currency being used and any quantity units into separate fields. Format the relevant information extracted from the transaction text in this format: {relevant_info_template}. A sample response for a single transaction could look like this: {sample_single_transaction_template}, while multiple transactions could look like this: {sample_multi_transaction_template}. There should be only one intent even in the case of multiple transactions."},
138
  {"role": "user", "content": prompt}
139
  ]
140
  )
@@ -356,6 +356,18 @@ def delete_transaction(user_phone, transaction_id):
356
  print("Transaction deleted successfully!")
357
 
358
 
 
 
 
 
 
 
 
 
 
 
 
 
359
 
360
 
361
  # Example usage
 
134
  model = model,
135
  # model="gpt-4o",
136
  messages=[
137
+ {"role": "system", "content": f"You are a helpful assistant that classifies transactions written in natural language into CRUD operations (Create, Read, Update, and Delete) and extracts relevant information. For update and delete queries, the transaction type should either be sales or inventory. You should be able to recognize the currency being used and any quantity units into separate fields. Format the relevant information extracted from the transaction text in this format: {relevant_info_template}. A sample response for a single transaction could look like this: {sample_single_transaction_template}, while multiple transactions could look like this: {sample_multi_transaction_template}. There should be only one intent even in the case of multiple transactions."},
138
  {"role": "user", "content": prompt}
139
  ]
140
  )
 
356
  print("Transaction deleted successfully!")
357
 
358
 
359
+ # Delete an entire transaction
360
+ def delete_transaction(user_phone, transaction_data):
361
+ # the transaction id currently defaults to the item name
362
+ transaction_id = transaction_data[0]['details']['item']
363
+ transaction_type = transaction_data[0]['transaction_type'].lower()
364
+ doc_ref = db.collection("users").document(user_phone).collection(transaction_type).document(transaction_id)
365
+ item_doc = doc_ref.get()
366
+ if item_doc.exists:
367
+ doc_ref.delete()
368
+ return True
369
+ else:
370
+ return False
371
 
372
 
373
  # Example usage