Spaces:
Sleeping
Sleeping
williamagyapong
commited on
Update utility.py
Browse files- utility.py +6 -6
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}.
|
138 |
{"role": "user", "content": prompt}
|
139 |
]
|
140 |
)
|
@@ -219,12 +219,12 @@ def parse_ai_response(response_text):
|
|
219 |
}
|
220 |
|
221 |
# Extract the intent
|
222 |
-
intent_match = re.search(r"
|
223 |
if intent_match:
|
224 |
data["intent"] = intent_match.group(1)
|
225 |
|
226 |
# Extract the transaction type
|
227 |
-
transaction_type_match = re.search(r"
|
228 |
if transaction_type_match:
|
229 |
data["transaction_type"] = transaction_type_match.group(1)
|
230 |
|
@@ -241,11 +241,11 @@ def parse_multiple_transactions(response_text):
|
|
241 |
# transaction_sections = re.split(r"(?i)(?<=\n)transaction\s+\d+:", response_text)
|
242 |
transaction_sections = [section.strip() for section in transaction_sections if section.strip()]
|
243 |
# Remove the first section if it's not a valid transaction
|
244 |
-
if not re.search(r"
|
245 |
transaction_sections.pop(0)
|
246 |
|
247 |
# Extract intent: with support for a single intent per user prompt
|
248 |
-
intent_match = re.search(r"
|
249 |
if intent_match:
|
250 |
intent = intent_match.group(1)
|
251 |
|
@@ -259,7 +259,7 @@ def parse_multiple_transactions(response_text):
|
|
259 |
}
|
260 |
|
261 |
# Extract transaction type
|
262 |
-
transaction_type_match = re.search(r"
|
263 |
if transaction_type_match:
|
264 |
transaction_data["transaction_type"] = transaction_type_match.group(1)
|
265 |
|
|
|
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 |
)
|
|
|
219 |
}
|
220 |
|
221 |
# Extract the intent
|
222 |
+
intent_match = re.search(r"\*Intent\*:\s*(\w+)", response_text)
|
223 |
if intent_match:
|
224 |
data["intent"] = intent_match.group(1)
|
225 |
|
226 |
# Extract the transaction type
|
227 |
+
transaction_type_match = re.search(r"\*Transaction Type\*:\s*(\w+)", response_text)
|
228 |
if transaction_type_match:
|
229 |
data["transaction_type"] = transaction_type_match.group(1)
|
230 |
|
|
|
241 |
# transaction_sections = re.split(r"(?i)(?<=\n)transaction\s+\d+:", response_text)
|
242 |
transaction_sections = [section.strip() for section in transaction_sections if section.strip()]
|
243 |
# Remove the first section if it's not a valid transaction
|
244 |
+
if not re.search(r"\*Transaction Type\*", transaction_sections[0], re.IGNORECASE):
|
245 |
transaction_sections.pop(0)
|
246 |
|
247 |
# Extract intent: with support for a single intent per user prompt
|
248 |
+
intent_match = re.search(r"\*Intent\*:\s*(\w+)", response_text)
|
249 |
if intent_match:
|
250 |
intent = intent_match.group(1)
|
251 |
|
|
|
259 |
}
|
260 |
|
261 |
# Extract transaction type
|
262 |
+
transaction_type_match = re.search(r"\*Transaction Type\*:\s*(\w+)", section)
|
263 |
if transaction_type_match:
|
264 |
transaction_data["transaction_type"] = transaction_type_match.group(1)
|
265 |
|