11class Provider ::Openai ::AutoCategorizer
2+ DEFAULT_MODEL = "gpt-4.1-mini"
3+
24 def initialize ( client , model : "" , transactions : [ ] , user_categories : [ ] )
35 @client = client
46 @model = model
@@ -8,7 +10,7 @@ def initialize(client, model: "", transactions: [], user_categories: [])
810
911 def auto_categorize
1012 response = client . responses . create ( parameters : {
11- model : model ,
13+ model : model . presence || DEFAULT_MODEL ,
1214 input : [ { role : "developer" , content : developer_message } ] ,
1315 text : {
1416 format : {
@@ -26,6 +28,27 @@ def auto_categorize
2628 build_response ( extract_categorizations ( response ) )
2729 end
2830
31+ def instructions
32+ <<~INSTRUCTIONS . strip_heredoc
33+ You are an assistant to a consumer personal finance app. You will be provided a list
34+ of the user's transactions and a list of the user's categories. Your job is to auto-categorize
35+ each transaction.
36+
37+ Closely follow ALL the rules below while auto-categorizing:
38+
39+ - Return 1 result per transaction
40+ - Correlate each transaction by ID (transaction_id)
41+ - Attempt to match the most specific category possible (i.e. subcategory over parent category)
42+ - Category and transaction classifications should match (i.e. if transaction is an "expense", the category must have classification of "expense")
43+ - If you don't know the category, return "null"
44+ - You should always favor "null" over false positives
45+ - Be slightly pessimistic. Only match a category if you're 60%+ confident it is the correct one.
46+ - Each transaction has varying metadata that can be used to determine the category
47+ - Note: "hint" comes from 3rd party aggregators and typically represents a category name that
48+ may or may not match any of the user-supplied categories
49+ INSTRUCTIONS
50+ end
51+
2952 private
3053 attr_reader :client , :model , :transactions , :user_categories
3154
@@ -97,25 +120,4 @@ def developer_message
97120 ```
98121 MESSAGE
99122 end
100-
101- def instructions
102- <<~INSTRUCTIONS . strip_heredoc
103- You are an assistant to a consumer personal finance app. You will be provided a list
104- of the user's transactions and a list of the user's categories. Your job is to auto-categorize
105- each transaction.
106-
107- Closely follow ALL the rules below while auto-categorizing:
108-
109- - Return 1 result per transaction
110- - Correlate each transaction by ID (transaction_id)
111- - Attempt to match the most specific category possible (i.e. subcategory over parent category)
112- - Category and transaction classifications should match (i.e. if transaction is an "expense", the category must have classification of "expense")
113- - If you don't know the category, return "null"
114- - You should always favor "null" over false positives
115- - Be slightly pessimistic. Only match a category if you're 60%+ confident it is the correct one.
116- - Each transaction has varying metadata that can be used to determine the category
117- - Note: "hint" comes from 3rd party aggregators and typically represents a category name that
118- may or may not match any of the user-supplied categories
119- INSTRUCTIONS
120- end
121123end
0 commit comments