Spaces:
Runtime error
Runtime error
updated prompt text
Browse files
backend/app/api/endpoints.py
CHANGED
|
@@ -86,6 +86,7 @@ async def process_email_directory():
|
|
| 86 |
sub_request_type=email_result["sub_request_type"],
|
| 87 |
confidence_score=email_result["confidence_score"],
|
| 88 |
duplicate_flag=email_result["duplicate_flag"],
|
|
|
|
| 89 |
)
|
| 90 |
results.append(email_resp)
|
| 91 |
except Exception as e:
|
|
|
|
| 86 |
sub_request_type=email_result["sub_request_type"],
|
| 87 |
confidence_score=email_result["confidence_score"],
|
| 88 |
duplicate_flag=email_result["duplicate_flag"],
|
| 89 |
+
all_extracted_numbers=email_result["extracted_numbers_list"]
|
| 90 |
)
|
| 91 |
results.append(email_resp)
|
| 92 |
except Exception as e:
|
backend/app/services/gemeni_classification.py
CHANGED
|
@@ -100,16 +100,23 @@ def analyze_intent(text):
|
|
| 100 |
print(f"Gemini API error (Intent): {e}")
|
| 101 |
return ""
|
| 102 |
|
| 103 |
-
def classify_email_gemeni(subject, body):
|
| 104 |
"""Classifies an email based on request type and sub-request type."""
|
| 105 |
results = []
|
| 106 |
categories_string = str(classification_categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
PROMPT = f"""
|
| 108 |
Analyze the following email and classify it into the most appropriate Request Type and Sub Request Type based on its primary intent.
|
| 109 |
|
| 110 |
Classification Categories:
|
| 111 |
{categories_string}
|
| 112 |
|
|
|
|
|
|
|
|
|
|
| 113 |
Email Subject: {subject}
|
| 114 |
Email Content: {body}
|
| 115 |
|
|
|
|
| 100 |
print(f"Gemini API error (Intent): {e}")
|
| 101 |
return ""
|
| 102 |
|
| 103 |
+
def classify_email_gemeni(subject, body, considerationsrules: Optional[dict] = None):
|
| 104 |
"""Classifies an email based on request type and sub-request type."""
|
| 105 |
results = []
|
| 106 |
categories_string = str(classification_categories)
|
| 107 |
+
|
| 108 |
+
key_considerations = considerationsrules.get("priority_rules", {}).get("classification_key_considerations", [])
|
| 109 |
+
keys_str = ", ".join(key_considerations)
|
| 110 |
+
|
| 111 |
PROMPT = f"""
|
| 112 |
Analyze the following email and classify it into the most appropriate Request Type and Sub Request Type based on its primary intent.
|
| 113 |
|
| 114 |
Classification Categories:
|
| 115 |
{categories_string}
|
| 116 |
|
| 117 |
+
Key Considerations for Classification:
|
| 118 |
+
{keys_str}
|
| 119 |
+
|
| 120 |
Email Subject: {subject}
|
| 121 |
Email Content: {body}
|
| 122 |
|
backend/app/services/retrieve_email_process.py
CHANGED
|
@@ -59,12 +59,12 @@ async def process_single_email(file_content: bytes, filename: str) -> Optional[d
|
|
| 59 |
else:
|
| 60 |
classification_source = email_body_text # default fallback
|
| 61 |
|
| 62 |
-
primary_result = classify_email_gemeni(email_data["subject"], classification_source)
|
| 63 |
|
| 64 |
# special condition to check if priority is email content and email has multi thread then we
|
| 65 |
# have to compare confidence score with primary confidence score
|
| 66 |
if "email_content" in identification_order:
|
| 67 |
-
email_chain_result = classify_email_gemeni(email_data["subject"], email_chain_text) if email_chain_text else ("Unknown", "Unknown", "0")
|
| 68 |
email_chain_confidence = float(email_chain_result[2])
|
| 69 |
primary_email_confidence = float(primary_result[2])
|
| 70 |
if email_chain_confidence > primary_email_confidence and email_chain_confidence:
|
|
@@ -72,9 +72,9 @@ async def process_single_email(file_content: bytes, filename: str) -> Optional[d
|
|
| 72 |
|
| 73 |
else:
|
| 74 |
# 1. Separate Classification:
|
| 75 |
-
document_result = classify_email_gemeni(email_data["subject"], attachment_text) if attachment_text else ("Unknown", "Unknown", "0")
|
| 76 |
-
email_chain_result = classify_email_gemeni(email_data["subject"], email_chain_text) if email_chain_text else ("Unknown", "Unknown", "0")
|
| 77 |
-
primary_email_result = classify_email_gemeni(email_data["subject"], email_body_text)
|
| 78 |
|
| 79 |
# 2. Confidence Score Comparison:
|
| 80 |
document_confidence = float(document_result[2])
|
|
|
|
| 59 |
else:
|
| 60 |
classification_source = email_body_text # default fallback
|
| 61 |
|
| 62 |
+
primary_result = classify_email_gemeni(email_data["subject"], classification_source, rules)
|
| 63 |
|
| 64 |
# special condition to check if priority is email content and email has multi thread then we
|
| 65 |
# have to compare confidence score with primary confidence score
|
| 66 |
if "email_content" in identification_order:
|
| 67 |
+
email_chain_result = classify_email_gemeni(email_data["subject"], email_chain_text, rules) if email_chain_text else ("Unknown", "Unknown", "0")
|
| 68 |
email_chain_confidence = float(email_chain_result[2])
|
| 69 |
primary_email_confidence = float(primary_result[2])
|
| 70 |
if email_chain_confidence > primary_email_confidence and email_chain_confidence:
|
|
|
|
| 72 |
|
| 73 |
else:
|
| 74 |
# 1. Separate Classification:
|
| 75 |
+
document_result = classify_email_gemeni(email_data["subject"], attachment_text, rules) if attachment_text else ("Unknown", "Unknown", "0")
|
| 76 |
+
email_chain_result = classify_email_gemeni(email_data["subject"], email_chain_text, rules) if email_chain_text else ("Unknown", "Unknown", "0")
|
| 77 |
+
primary_email_result = classify_email_gemeni(email_data["subject"], email_body_text, rules)
|
| 78 |
|
| 79 |
# 2. Confidence Score Comparison:
|
| 80 |
document_confidence = float(document_result[2])
|
backend/main.py
CHANGED
|
@@ -13,7 +13,7 @@ origins = [
|
|
| 13 |
#router = APIRouter()
|
| 14 |
app.add_middleware(
|
| 15 |
CORSMiddleware,
|
| 16 |
-
allow_origins=
|
| 17 |
allow_credentials=True,
|
| 18 |
allow_methods=["*"],
|
| 19 |
allow_headers=["*"],
|
|
|
|
| 13 |
#router = APIRouter()
|
| 14 |
app.add_middleware(
|
| 15 |
CORSMiddleware,
|
| 16 |
+
allow_origins=["*"], # Replace "*" with your frontend domain in production
|
| 17 |
allow_credentials=True,
|
| 18 |
allow_methods=["*"],
|
| 19 |
allow_headers=["*"],
|