File size: 902 Bytes
b36e1d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from openai import OpenAI
import os
my_key = os.environ.get('MY_OPENAI_KEY')
client = OpenAI(
    api_key= my_key
)

def expense_classifier(expense):
    chat_completion = client.chat.completions.create(
    messages=[
        {   "role": "system",
            "content": [
        {
          "type": "text",
          "text": """You are a helpful personal finance assistant. 
          The user will input some expense concept and you will classify it in a broader category from the following:
            [alcohol, food, restaurant, clothing, entertainment, transport, sports, wellbeing, personal_development,others] 
            Provide only the category as an answer
            """
        }
      ]
        },
        {
            "role": "user",
            "content": expense,
        }
    ],
    model="gpt-4o-mini",
    temperature=0
)
    return chat_completion.choices[0].message.content