Spaces:
Sleeping
Sleeping
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 |