(20241218) E-Mails now get a vendor/client tag when AI thinks the message is from one of those entities.

This commit is contained in:
2024-12-18 14:09:14 +05:30
parent b42da0dacb
commit 0a336c0938
2 changed files with 35 additions and 10 deletions
+29 -10
View File
@@ -125,9 +125,22 @@ class MailController:
{
"role": "system",
"content": (
"You're a mail summary expert that summarizes mails in 150 chars or less. "
"You're an expert mail summary program. "
"Provide the response in a structured JSON format with two fields: \"summary\" and \"senderType\". "
"The summary should be 150 chars or less. "
"If available, show login info like username and OTPs in your summary."
"If no login info is provided, please don't worry; just summarize what you see."
"\"senderType\" must be one of [\"Vendor\", \"Client\", null].\n"
"Example output 1: "
"{\"summary\":\"Sagar Supplies has shipped your materials. They are expected to reach by Thursday. "
"Use OTP 346780 when the delivery agent asks.\",\"senderType\":\"Vendor\"}\n"
"Example output 2: "
"{\"summary\":\"Mr. Mehta is enquiring about the submission of his tax filings, which are to be done "
"today.\",\"senderType\":\"Client\"}\n"
"Example output 3: "
"{\"summary\":\"JustDial's marketing message. They're offering a 35% discount to new accounts.\","
"\"senderType\":null}\n"
"Remember to respond only with the JSON string, nothing else. Good luck :)"
)
}
]
@@ -381,7 +394,7 @@ class MailController:
message = client_response.data,
snippet = client_response.data["subject"],
aiSnippet = None,
tags = ["email", "gmail"]
tags = ["Email", "Gmail"]
)
# Give a quick indicator of whether this mail is an inbox mail or sent mail:
@@ -391,13 +404,19 @@ class MailController:
else: mail_message.isSent = True
# Invoke the LLM:
ai_snippet = await self.summarize_mail_with_ai(
mongo_conn = mongo_conn,
user_info = user_info,
llm = llm,
message = mail_message
)
mail_message.aiSnippet = ai_snippet.summary
try:
ai_snippet = await self.summarize_mail_with_ai(
mongo_conn = mongo_conn,
user_info = user_info,
llm = llm,
message = mail_message
)
ai_json = ai_snippet.json
mail_message.aiSnippet = ai_snippet.summary
mail_message.aiSnippet["output"] = ai_json["summary"]
if ai_json["senderType"] is not None: mail_message.tags.append(ai_json["senderType"])
except Exception as exception:
current_app.printer(exception)
# Done here:
sync_result.success = True
@@ -540,7 +559,7 @@ class MailController:
# ┻ ┗ ┗┗┛┗ ┻ ┗┛┛┗┗ ┛┗┛
# We first load the authorization tokens:
auth_token = await self.get_token(
auth_token = await self.get_token_from_key(
mongo_conn = mongo_conn,
token_key = token_key,
)
+6
View File
@@ -40,6 +40,7 @@ from pydantic import BaseModel, Field, field_validator, PastDatetime, AwareDatet
from typing import Optional, Literal, Union, List, Any
# My utils:
from utils_v2.string import json
from utils_v2.string import regex
from utils_v2.date_time import date_time
@@ -233,6 +234,11 @@ class LLMOutput(BaseModel):
"invocationId": self.invocationId
}
@property
def json(self) -> dict | list | None:
try: return json.from_string(self.output)
except: return None
# *****************************************************************************************************************
# ***** ****