Sulaiman8 commited on
Commit
be085ab
·
verified ·
1 Parent(s): db4a9db

Upload pydantic_schema.py

Browse files
Files changed (1) hide show
  1. pydantic_schema.py +49 -0
pydantic_schema.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel, Field
2
+ from typing import List, Literal, Optional
3
+
4
+ # --- Pydantic Models ---
5
+
6
+ class CreditCardRecommendation(BaseModel):
7
+ """
8
+ Structured response for credit card recommendations.
9
+ Handles both successful recommendations and cases where no suitable card is found.
10
+ """
11
+ card_found: bool = Field(
12
+ description="A boolean flag that MUST be `True` if a card is recommended, and `False` otherwise."
13
+ )
14
+ best_card: Optional[str] = Field(
15
+ default=None,
16
+ description="The name of the best credit card recommended. This MUST be null if card_found is false."
17
+ )
18
+ explanation: Optional[List[str]] = Field(
19
+ default=None,
20
+ description=("A numbered list explaining why the card is best: "
21
+ "1. Main benefit aligned to user query. "
22
+ "2-3. Additional perks. "
23
+ "4. Final justification tying everything to the query."
24
+ )
25
+ )
26
+ reply_if_card_not_found: Optional[str] = Field(
27
+ default=None,
28
+ description=(
29
+ "A user-facing message generated by rephrasing the AI agent's internal monologue when no exact card is found. "
30
+ "This reply should politely explain and justify that no perfect match was found and present the alternative cards or information, if available, as helpful suggestions to explore. "
31
+ "This field MUST be populated if and only if card_found is false."
32
+ )
33
+ )
34
+
35
+ # In your Pydantic Models section
36
+
37
+ class IntentClassification(BaseModel):
38
+ """
39
+ Classifies the user query into 'credit-card-recommendation',
40
+ 'general-credit-related', or 'out-of-scope'.
41
+ """
42
+ intent: Literal["credit-card-recommendation", "general-credit-related", "out-of-scope"] = Field(
43
+ description=(
44
+ "The classification of the user's query. "
45
+ "'credit-card-recommendation' for seeking card suggestions. "
46
+ "'general-credit-related' for informational questions about credit cards. "
47
+ "'out-of-scope' for all other cases."
48
+ )
49
+ )