nagarmayank commited on
Commit
a8f2af1
·
1 Parent(s): 5238772

Add transaction_origin field and expand classification options in TransactionParser

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -44,6 +44,11 @@ class TransactionParser(BaseModel):
44
  # transaction_date: str = Field(description="Use today's date strictly in yyyy-mm-dd format.")
45
  transaction_origin: str = Field(description="The origin of the transaction. Provide the card or account number as well.")
46
 
 
 
 
 
 
47
  class AgentState(TypedDict):
48
  messages: Annotated[list[AnyMessage], operator.add]
49
 
@@ -71,7 +76,7 @@ class Agent:
71
  if self.system:
72
  messages = [SystemMessage(content=self.system)] + messages
73
 
74
- message = self.model.invoke(messages)
75
  print(f"{datetime.now(ist_tz)}: Classifying transaction type completed.")
76
  return {"messages": [message]}
77
 
@@ -134,16 +139,10 @@ def write_message(data: dict, header: str = Header()):
134
  if header != HF_TOKEN:
135
  raise HTTPException(status_code=400, detail="Invalid header")
136
 
137
- prompt = """You are a smart assistant adept at classifying different messages. \
138
- You will be penalized heavily for incorrect classification. \
139
- Your task is to classify the message into one of the following categories: \
140
- Transaction or OTP. \
141
- Output the classification in a structured format like below. \
142
- {"classification": "OTP"} \
143
- """
144
 
145
  message = data['message']
146
-
147
  try:
148
  model = ChatGoogleGenerativeAI(model=GOOGLE_MODEL, max_retries=3, callbacks = [OpikTracer()])
149
  except Exception as e: #fallback model
 
44
  # transaction_date: str = Field(description="Use today's date strictly in yyyy-mm-dd format.")
45
  transaction_origin: str = Field(description="The origin of the transaction. Provide the card or account number as well.")
46
 
47
+ class TransactionClassification(BaseModel):
48
+ """This Pydantic class is used to classify the transaction message. The message is taken and the output is structured in a specific format based upon below definition."""
49
+
50
+ classification: str = Field(description="Classification of the transaction. Strictly choose one of the values - Transaction, OTP, Scheduled, Reminder")
51
+
52
  class AgentState(TypedDict):
53
  messages: Annotated[list[AnyMessage], operator.add]
54
 
 
76
  if self.system:
77
  messages = [SystemMessage(content=self.system)] + messages
78
 
79
+ message = self.model.with_structured_output(TransactionClassification).invoke(messages)
80
  print(f"{datetime.now(ist_tz)}: Classifying transaction type completed.")
81
  return {"messages": [message]}
82
 
 
139
  if header != HF_TOKEN:
140
  raise HTTPException(status_code=400, detail="Invalid header")
141
 
142
+ prompt = """You are a smart assistant adept at working with bank transaction messages."""
 
 
 
 
 
 
143
 
144
  message = data['message']
145
+
146
  try:
147
  model = ChatGoogleGenerativeAI(model=GOOGLE_MODEL, max_retries=3, callbacks = [OpikTracer()])
148
  except Exception as e: #fallback model