StMarkSchool/StMarkFinancialAI
0
1from openai import OpenAI2def print_ascii_splash() : # Print ASCII Art for the initial splash screen3 print(r'''4 _ __ __ __ _______ _ __ __ __ __ ___5| | / /__ / /________ ____ ___ ___ / /_____ / ____(_)___ ____ _____ _____(_)___ _/ / / / / / / |/ /6| | /| / / _ \/ / ___/ __ \/ __ `__ \/ _ \ / __/ __ \ / /_ / / __ \/ __ `/ __ \/ ___/ / __ `/ / / / / / / /|_/ / 7| |/ |/ / __/ / /__/ /_/ / / / / / / __/ / /_/ /_/ / / __/ / / / / / /_/ / / / / /__/ / /_/ / / / /___/ /___/ / / / 8|__/|__/\___/_/\___/\____/_/ /_/ /_/\___/ \__/\____/ /_/ /_/_/ /_/\__,_/_/ /_/\___/_/\__,_/_/ /_____/_____/_/ /_/ 9 10 ''')11 12def load_model() : 13 client = OpenAI()14 return client15 16def get_response(question, client, history = None, model = "gpt-4o-mini") : 17 if history is None : 18 history = [19 {"role": "system", 20 "content": "You are a personal finance assistant working with K-12 students, you should ONLY answer questions related to personal finance, finance, economics, and strictly refrain from answering any other questions. Structure your input to multiple steps, but be as concise as possible. Use simple English fit for K-12 students. Cite, and link to all resources used."21 },22 23 {24 "role": "user",25 "content": question26 }27 ,28 ]29 else : 30 added_dict = {31 "role": "user",32 "content": question33 }34 history.append(added_dict)35 response = client.chat.completions.create(36 model = model,37 messages= history38 )39 response = response.choices[0].message.content40 added_dict = {41 "role": "assistant",42 "content": response43 }44 history.append(added_dict)45 return response, history46 47def clear_memory(history) : 48 history = None49 return history