AIEmailAutomationUtility 0.0.10__py3-none-any.whl → 0.0.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- AIEmailAutomationUtility/Email_Classification.py +12 -12
- AIEmailAutomationUtility/Email_DocumentUploader.py +4 -4
- AIEmailAutomationUtility/Email_Draft.py +1 -1
- AIEmailAutomationUtility/Email_Read.py +21 -16
- {AIEmailAutomationUtility-0.0.10.dist-info → AIEmailAutomationUtility-0.0.12.dist-info}/METADATA +1 -1
- AIEmailAutomationUtility-0.0.12.dist-info/RECORD +14 -0
- AIEmailAutomationUtility-0.0.10.dist-info/RECORD +0 -14
- {AIEmailAutomationUtility-0.0.10.dist-info → AIEmailAutomationUtility-0.0.12.dist-info}/LICENCE.txt +0 -0
- {AIEmailAutomationUtility-0.0.10.dist-info → AIEmailAutomationUtility-0.0.12.dist-info}/WHEEL +0 -0
- {AIEmailAutomationUtility-0.0.10.dist-info → AIEmailAutomationUtility-0.0.12.dist-info}/top_level.txt +0 -0
@@ -7,7 +7,7 @@ from flask import Flask,request
|
|
7
7
|
|
8
8
|
class Email_Classification:
|
9
9
|
def detect_category_openai(self, openai_api_key, categories, email_body):
|
10
|
-
|
10
|
+
print("Inside detect_category_openai::")
|
11
11
|
try:
|
12
12
|
categories_str = ', '.join(categories)
|
13
13
|
message = [{
|
@@ -27,14 +27,14 @@ class Email_Classification:
|
|
27
27
|
presence_penalty=0,
|
28
28
|
)
|
29
29
|
category = json.loads(result.choices[0].message.content.replace("\n```", "").replace("```", "").replace("json","").replace("JSON","").replace("csv","").replace("CSV",""))['category']
|
30
|
-
|
30
|
+
print(f"category:: {category}")
|
31
31
|
return {"status": "Success", "message": category}
|
32
32
|
except Exception as e:
|
33
33
|
logger.log(f"Error detecting category with OpenAI: {str(e)}")
|
34
34
|
return {"success": "Failed", "message": f"Error detecting category with OpenAI: {str(e)}"}
|
35
35
|
|
36
36
|
def detect_category_gemini(self, gemini_api_key, categories, email_body, detect_email_category=True, signature=None):
|
37
|
-
|
37
|
+
print("Inside detect_category_gemini::")
|
38
38
|
try:
|
39
39
|
categories_str = ', '.join(categories)
|
40
40
|
if detect_email_category:
|
@@ -74,23 +74,23 @@ class Email_Classification:
|
|
74
74
|
if final_result.startswith("{{") and final_result.endswith("}}"):
|
75
75
|
final_result = final_result[1:-1]
|
76
76
|
final_result = json.loads(final_result)
|
77
|
-
|
77
|
+
print(f"finalResult::: {final_result}")
|
78
78
|
except json.JSONDecodeError:
|
79
|
-
|
79
|
+
print(f"Exception : Invalid JSON Response GEMINI 1.5: {final_result} {type(final_result)}")
|
80
80
|
|
81
81
|
if detect_email_category:
|
82
82
|
category = final_result.get('category', 'Others')
|
83
83
|
return {"status": "Success", "message": category}
|
84
84
|
else:
|
85
|
-
|
85
|
+
print(f"finalResult::: {final_result}")
|
86
86
|
return {"status": "Success", "message": final_result}
|
87
87
|
|
88
88
|
except Exception as e:
|
89
|
-
|
89
|
+
print(f"Error with Gemini AI detection/generation: {str(e)}")
|
90
90
|
return {"success": "Failed", "message": f"Error with Gemini AI detection/generation: {str(e)}"}
|
91
91
|
|
92
92
|
def detect_category_local(self, openai_api_key, categories, email_body, detect_email_category=True, signature=None, local_ai_url=None):
|
93
|
-
|
93
|
+
print("Inside detect_category_local::")
|
94
94
|
try:
|
95
95
|
categories_str = ', '.join(categories)
|
96
96
|
if detect_email_category:
|
@@ -125,17 +125,17 @@ class Email_Classification:
|
|
125
125
|
if json_start != -1 and json_end != -1:
|
126
126
|
json_str = final_result[json_start:json_end]
|
127
127
|
final_result = json.loads(json_str)
|
128
|
-
|
128
|
+
print(f"finalResult::: {final_result}")
|
129
129
|
category = final_result.get('category', 'Others')
|
130
|
-
|
130
|
+
print(f"category::1037 {category}")
|
131
131
|
return {"status": "Success", "message": category}
|
132
132
|
else:
|
133
133
|
raise ValueError("No valid JSON object found in the response")
|
134
134
|
except json.JSONDecodeError as e:
|
135
|
-
|
135
|
+
print(f"JSON decode error: {e}")
|
136
136
|
raise
|
137
137
|
else:
|
138
|
-
|
138
|
+
print(f"finalResult:1040 {final_result}")
|
139
139
|
return {"status": "Success", "message": final_result}
|
140
140
|
|
141
141
|
except Exception as e:
|
@@ -16,7 +16,7 @@ class Email_DocumentUploader:
|
|
16
16
|
|
17
17
|
# Save file temporarily
|
18
18
|
file_path = os.path.join(temp_dir, file_data['filename'])
|
19
|
-
|
19
|
+
print(f"file_path:: {file_path}")
|
20
20
|
with open(file_path, 'wb') as f:
|
21
21
|
f.write(file_data['content'])
|
22
22
|
|
@@ -46,7 +46,7 @@ class Email_DocumentUploader:
|
|
46
46
|
files=files,
|
47
47
|
data=params
|
48
48
|
)
|
49
|
-
|
49
|
+
print("file read")
|
50
50
|
|
51
51
|
if response.status_code == 200:
|
52
52
|
result = json.loads(response.text)
|
@@ -56,7 +56,7 @@ class Email_DocumentUploader:
|
|
56
56
|
return str(response.status_code), f"Upload failed: {response.text}"
|
57
57
|
|
58
58
|
def email_document_upload(self, file, parameters_details):
|
59
|
-
|
59
|
+
print(f"file ::: {file}")
|
60
60
|
if not file:
|
61
61
|
return "file not found"
|
62
62
|
|
@@ -81,5 +81,5 @@ class Email_DocumentUploader:
|
|
81
81
|
|
82
82
|
response_status, restAPI_Result = self.upload_document(upload_config, file_data)
|
83
83
|
|
84
|
-
|
84
|
+
print(f"Upload_Document response result: {restAPI_Result}")
|
85
85
|
return response_status, restAPI_Result
|
@@ -110,7 +110,7 @@ class Email_Draft:
|
|
110
110
|
success, draft_message = self.draft_email_response(email_details)
|
111
111
|
|
112
112
|
if success == "Success":
|
113
|
-
|
113
|
+
print(f"draft_message {draft_message}")
|
114
114
|
return draft_message
|
115
115
|
|
116
116
|
except Exception as e:
|
@@ -99,7 +99,7 @@ class Email_Read:
|
|
99
99
|
|
100
100
|
mail = imaplib.IMAP4_SSL(host, port)
|
101
101
|
mail.login(reciever_email_addr, receiver_email_pwd)
|
102
|
-
|
102
|
+
print("login successfully")
|
103
103
|
mail.select('inbox')
|
104
104
|
|
105
105
|
file_JsonArray, categories = self.read_JSON_File(templateName)
|
@@ -112,8 +112,8 @@ class Email_Read:
|
|
112
112
|
email_ids = email_ids[0].split()
|
113
113
|
|
114
114
|
if not email_ids:
|
115
|
-
|
116
|
-
|
115
|
+
print("Email not found, going to check new mail")
|
116
|
+
print("Email not found,\ngoing to check new mail \n")
|
117
117
|
else:
|
118
118
|
|
119
119
|
for email_id in email_ids:
|
@@ -140,8 +140,8 @@ class Email_Read:
|
|
140
140
|
email_body = msg.get_payload(decode=True).decode('utf-8', errors='replace')
|
141
141
|
|
142
142
|
openai_Process_Input = email_body
|
143
|
-
logger.log("\nEmail Subject:::
|
144
|
-
logger.log("\nEmail body:::
|
143
|
+
logger.log(f"\nEmail Subject::: {subject}")
|
144
|
+
logger.log(f"\nEmail body::: {openai_Process_Input}")
|
145
145
|
|
146
146
|
openai_api_key = email_config.get('openai_api_key', '')
|
147
147
|
geminiAI_APIKey = email_config.get('gemini_api_key', '')
|
@@ -162,7 +162,7 @@ class Email_Read:
|
|
162
162
|
email_classification = Email_Classification()
|
163
163
|
emailCategory = email_classification.detect_category(email_cat_data)
|
164
164
|
emailCategory = emailCategory['message']
|
165
|
-
|
165
|
+
print(f"\nDetected Email category ::: {emailCategory}")
|
166
166
|
|
167
167
|
if emailCategory == 'Others':
|
168
168
|
logger.log(f"Marking email as UNREAD. ")
|
@@ -172,7 +172,7 @@ class Email_Read:
|
|
172
172
|
mail.copy(email_id, LABEL)
|
173
173
|
mail.store(email_id, '+FLAGS', '\\Deleted') # Mark for deletion
|
174
174
|
mail.expunge()
|
175
|
-
|
175
|
+
print(f"Mail removed from inbox and added to '{LABEL}' label.")
|
176
176
|
|
177
177
|
elif emailCategory == "Product Enquiry":
|
178
178
|
|
@@ -188,7 +188,7 @@ class Email_Read:
|
|
188
188
|
|
189
189
|
email_draft = Email_Draft()
|
190
190
|
status, response = email_draft.draft_email(email_config, email_details, openai_Response['message'])
|
191
|
-
|
191
|
+
print(f"status ::: {status}")
|
192
192
|
else :
|
193
193
|
message = f"Invalid response method received '{responseMethod}' for category : '{emailCategory}'"
|
194
194
|
raise ValueError(message)
|
@@ -201,7 +201,7 @@ class Email_Read:
|
|
201
201
|
|
202
202
|
email_draft = Email_Draft()
|
203
203
|
status, response = email_draft.draft_email(email_config, email_details, LocalAI_Response)
|
204
|
-
|
204
|
+
print(f"status ::: {status}")
|
205
205
|
elif Model_Name == "GeminiAI":
|
206
206
|
logger.log("GeminiAI")
|
207
207
|
Detect_Email_category = False
|
@@ -211,7 +211,7 @@ class Email_Read:
|
|
211
211
|
|
212
212
|
email_draft = Email_Draft()
|
213
213
|
status, response = email_draft.draft_email(email_config, email_details, GeminiAI_Response)
|
214
|
-
|
214
|
+
print(f"status ::: {status}")
|
215
215
|
else:
|
216
216
|
raise ValueError(f"Invalid Model Name provided : '{Model_Name}'")
|
217
217
|
|
@@ -226,18 +226,18 @@ class Email_Read:
|
|
226
226
|
email_upload_document = Email_DocumentUploader()
|
227
227
|
with open(f"temp/{fileName}", "rb") as file:
|
228
228
|
response_status, restAPI_Result = email_upload_document.email_document_upload(file, parameters)
|
229
|
-
|
229
|
+
print(f"email_upload_document_response ::: {restAPI_Result}")
|
230
230
|
else:
|
231
231
|
|
232
232
|
new_fileName = self.create_file_from_emailBody(email_body, sender_email_addr, parameters)
|
233
233
|
with open(f"temp/{new_fileName}", "rb") as file:
|
234
234
|
response_status, restAPI_Result = email_upload_document.email_document_upload(file, parameters)
|
235
|
-
|
235
|
+
print(f"email_upload_document_response ::: {restAPI_Result}")
|
236
236
|
|
237
237
|
if response_status == "200" :
|
238
|
-
|
238
|
+
print(f"Attachment uploaded sucessfully against Document id: '{restAPI_Result}'.")
|
239
239
|
else:
|
240
|
-
|
240
|
+
print(restAPI_Result)
|
241
241
|
|
242
242
|
else :
|
243
243
|
message = f"Invalid response method received '{responseMethod}' for category : '{emailCategory}'"
|
@@ -281,6 +281,9 @@ class Email_Read:
|
|
281
281
|
receiver_email_pwd = data.get("receiver_email_pwd")
|
282
282
|
host = data.get("host")
|
283
283
|
port = data.get("port")
|
284
|
+
openai_api_key = data.get("openai_api_key")
|
285
|
+
geminiAI_APIKey = data.get("GeminiAI_APIKey")
|
286
|
+
localAIURL = data.get("LOCAL_AI_URL")
|
284
287
|
|
285
288
|
if not all([reciever_email_addr, receiver_email_pwd, host, port]):
|
286
289
|
raise ValueError("Missing required email configuration fields.")
|
@@ -294,7 +297,10 @@ class Email_Read:
|
|
294
297
|
'email': reciever_email_addr,
|
295
298
|
'password': receiver_email_pwd,
|
296
299
|
'host': host,
|
297
|
-
'port': int(port)
|
300
|
+
'port': int(port),
|
301
|
+
'openai_api_key': openai_api_key,
|
302
|
+
'gemini_api_key': geminiAI_APIKey,
|
303
|
+
'local_ai_url': localAIURL
|
298
304
|
}
|
299
305
|
|
300
306
|
emails = self.read_email(email_config)
|
@@ -370,7 +376,6 @@ class Email_Read:
|
|
370
376
|
if not os.path.exists(dir):
|
371
377
|
os.mkdir(dir)
|
372
378
|
fileName = sender_email_addr[sender_email_addr.find("<")+1:sender_email_addr.find("@")].strip().replace(".","_")
|
373
|
-
logger.log(f"{fileName = }")
|
374
379
|
|
375
380
|
if parameters["FILE_TYPE"] == "pdf":
|
376
381
|
fileName = fileName + ".pdf"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
AIEmailAutomationUtility/EmailReplyAssistant.py,sha256=NQlBPugGdEvNwGFOoaiJNb4JDQB_DYvCy_hWLgAVLns,3938
|
2
|
+
AIEmailAutomationUtility/Email_Classification.py,sha256=nq958GJ5GwOF7FgMSoItp1AOD0CUUg0Dz25ERLxy1GI,9283
|
3
|
+
AIEmailAutomationUtility/Email_DocumentUploader.py,sha256=bkDWekmhOOd7G6dAoVYYTEcerT0rGP49xlMIORU6mEw,3035
|
4
|
+
AIEmailAutomationUtility/Email_Draft.py,sha256=uCFiu9OUWDGmUBnWv9RqElv2P43SFnRw1HB6YuQ5p_8,5239
|
5
|
+
AIEmailAutomationUtility/Email_Read.py,sha256=qRtHY7qxQPe90JjMv27yW3bZoNtnTyuZqAl1cBB3PcQ,20732
|
6
|
+
AIEmailAutomationUtility/Email_Upload_Document.py,sha256=3bdkxfDlwoeRp-46KPw2Gs1dqBhEIoA1yE5GCudpdV8,1320
|
7
|
+
AIEmailAutomationUtility/Save_Draft.py,sha256=yzLgFN14I_lXE6qL0I3tKNduvcnWdbsY9i2mKdTtio4,5348
|
8
|
+
AIEmailAutomationUtility/Save_Transaction.py,sha256=Gg1w6hhzHmEFjsuzYvkq-3-EsWReetjLHsYSv5YIGgM,3816
|
9
|
+
AIEmailAutomationUtility/__init__.py,sha256=bB7N-qQD85RdMaXHg_ZU5oPtHtx9zgeG6-ue4rhcfYI,379
|
10
|
+
AIEmailAutomationUtility-0.0.12.dist-info/LICENCE.txt,sha256=2qX9IkEUBx0VJp1Vh9O2dsRwE-IpYId0lXDyn7OVsJ8,1073
|
11
|
+
AIEmailAutomationUtility-0.0.12.dist-info/METADATA,sha256=p2FYQU14fI60ODJSPRJSS2mGQ8z5jF_U80F2tTHCgTw,623
|
12
|
+
AIEmailAutomationUtility-0.0.12.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
13
|
+
AIEmailAutomationUtility-0.0.12.dist-info/top_level.txt,sha256=3jTWrTUblVkaP7mpwY2UBSnrlfot5Ykpfsehyke-Uzw,25
|
14
|
+
AIEmailAutomationUtility-0.0.12.dist-info/RECORD,,
|
@@ -1,14 +0,0 @@
|
|
1
|
-
AIEmailAutomationUtility/EmailReplyAssistant.py,sha256=NQlBPugGdEvNwGFOoaiJNb4JDQB_DYvCy_hWLgAVLns,3938
|
2
|
-
AIEmailAutomationUtility/Email_Classification.py,sha256=eL52Td50zo7V0QTIqjN4Khhg-5HKvf2RUITIcKz5yZ0,9343
|
3
|
-
AIEmailAutomationUtility/Email_DocumentUploader.py,sha256=ImTmMz_JeU6Xynt9kyu7lFv7vqrxzqAtBF-A7014fYc,3055
|
4
|
-
AIEmailAutomationUtility/Email_Draft.py,sha256=BfseewnnlwNl1moodq3kZiUPXDUE9a_nQjuFQsUp3fY,5244
|
5
|
-
AIEmailAutomationUtility/Email_Read.py,sha256=bmRS_jt_v0BxsOWQZcH12VKhcWUbc9dNuw3qkvbGCN4,20516
|
6
|
-
AIEmailAutomationUtility/Email_Upload_Document.py,sha256=3bdkxfDlwoeRp-46KPw2Gs1dqBhEIoA1yE5GCudpdV8,1320
|
7
|
-
AIEmailAutomationUtility/Save_Draft.py,sha256=yzLgFN14I_lXE6qL0I3tKNduvcnWdbsY9i2mKdTtio4,5348
|
8
|
-
AIEmailAutomationUtility/Save_Transaction.py,sha256=Gg1w6hhzHmEFjsuzYvkq-3-EsWReetjLHsYSv5YIGgM,3816
|
9
|
-
AIEmailAutomationUtility/__init__.py,sha256=bB7N-qQD85RdMaXHg_ZU5oPtHtx9zgeG6-ue4rhcfYI,379
|
10
|
-
AIEmailAutomationUtility-0.0.10.dist-info/LICENCE.txt,sha256=2qX9IkEUBx0VJp1Vh9O2dsRwE-IpYId0lXDyn7OVsJ8,1073
|
11
|
-
AIEmailAutomationUtility-0.0.10.dist-info/METADATA,sha256=iG4GkrRFAa5-1rXSU-nXQmnMbSqkIso7QKXPF7j4S78,623
|
12
|
-
AIEmailAutomationUtility-0.0.10.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
13
|
-
AIEmailAutomationUtility-0.0.10.dist-info/top_level.txt,sha256=3jTWrTUblVkaP7mpwY2UBSnrlfot5Ykpfsehyke-Uzw,25
|
14
|
-
AIEmailAutomationUtility-0.0.10.dist-info/RECORD,,
|
{AIEmailAutomationUtility-0.0.10.dist-info → AIEmailAutomationUtility-0.0.12.dist-info}/LICENCE.txt
RENAMED
File without changes
|
{AIEmailAutomationUtility-0.0.10.dist-info → AIEmailAutomationUtility-0.0.12.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|