Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from routes.user_by_id import UserById
from routes.account_by_id import AccountById
from routes.account_by_user_id import AccountByUserId
from models.ai_chatbot import GetResponse

# Resources
api.add_resource(Signup, '/api/signup', endpoint='/api/auth')
Expand All @@ -31,7 +32,9 @@
api.add_resource(UserById, '/api/users/<int:id>')
api.add_resource(AccountById, '/api/users/<int:user_id>/accounts/<string:account_id>')
api.add_resource(AccountByUserId, '/api/users/<int:user_id>/accounts')
api.add_resource(GetResponse, '/api/get-response')

# api.add_resource(OpenAiResponse, '/api/user/<string:user_id>/achievement')

# Register a callback function that loads a user from your database whenever
# a protected route is accessed. This should return any python object on a
Expand Down
Binary file not shown.
99 changes: 27 additions & 72 deletions backend/models/ai_chatbot.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,40 @@
from openai import OpenAI
import time
import os
from users import User
from achievements import Achievement
# Use an environment variable for the API key
from flask_restful import request, Resource

OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')

api_key = OPENAI_API_KEY
client = OpenAI()

user = User(
first_name='Alberto',
last_name='Sierra',
email='Alberto@Sierra.com',
zipcode='94903'
)
achievement = Achievement(
description='Go on vacation'
)
users = {'Alberto'}
achievements = {"retire"}


# # JSON Mode for frontend
response = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are a helpful assistant designed to output JSON."},

# {"role": "user", "content": "I have $200 extra, after my monthly expenses. I wants to invest the extra money in the S&P 500. Return the calculated amount in 10 years from now"}

# {"role": "user", "content": "Give me a list of retirement accounts and their performance in the past 10 years in APR"}

# {"role": "user", "content": "I have $5000 in my Roth IRA account, if i put in $200 a month, how much will it be in 30 years?"}

# {"role": "user", "content": "Help me to create a monthly budget with $1000 in 10005. With 10 major spending categories."}

# {"role": "user", "content": "Find what the average person per month in 94903 spends in healthcare. "}

{"role": "user", "content": "My name is {user.first_name}, and I live in {user.zipcode}. My goal is to: {achievement.description} I have $200 extra after my monthly expenses. How should I spend that?"}
]
)
print(response.choices[0].message.content)
# json_schema = {
# "name": "Alberto",
# "location": "94903",
# "goal": "go on vacation",
# "extraIncome": 200,
# "suggestions": [
# "Save the extra money for your vacation fund",
# "Consider putting the extra money towards booking a flight or accommodation for your vacation",
# "Use the extra money for activities and experiences during your vacation"
# ]
# }

#Chat-bot instructions and model
# assistant = client.beta.assistants.create(
# name="Budget Manager",
# instructions="You are a budget manager. Provide budgeting advice to save money or investing extra money. Return only JSON ",
# tools=[{"type": "code_interpreter"}],
# model="gpt-4-turbo-preview",
# )
def get_openai_response(user, achievement):
response = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are a helpful assistant, return JSON."},

# thread = client.beta.threads.create()
{"role": "user", "content": f"My name is Alberto', and I live in '94903'. My goal is to: 'go on vacation' I have $200 extra after my monthly expenses. How should I spend that? "} ])
return response.choices[0].message.content

# #User's message to the chat-bot
# message = client.beta.threads.messages.create(
# thread_id=thread.id,
# role="user",
# content="I have $200 extra, after my monthly expenses. I wants to invest the extra money in the S&P 500. Return the calculated amount in 30 years from now. return only JSON"
# )

# #Chat-bot response:
# #Plus second set of instructions -- provide users goals
# run = client.beta.threads.runs.create(
# thread_id=thread.id,
# assistant_id=assistant.id,
# instructions="Please address the user as Alberto. Return only JSON"
# )

# while run.status in ['queued', 'in_progress', 'cancelling']:
# time.sleep(1) # Wait for 1 second
# run = client.beta.threads.runs.retrieve(
# thread_id=thread.id,
# run_id=run.id
# )
# if run.status == 'completed':
# messages = client.beta.threads.messages.list(
# thread_id=thread.id
# )
# #Chat-bot response
# print(messages.data[0].content[0].text.value)
# else:
# print(run.status)



class GetResponse(Resource):
def get(self):
return get_openai_response(users, achievements)
26 changes: 13 additions & 13 deletions backend/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,41 @@
# Create accounts
print('Creating accounts...')
account1 = Account(
id='QlRwmeljv1fxg3aolDwXSe4Kqwv3RjFwmvbzN5',
id='1',
name='Bank3',
balance=10,
balance=10.00,
type='Checking',
currency='GBP',
user_id=user1.id
)

account2 = Account(
id='QlRwmeljv1fxg3aolDwXSe4Kqwv3RjFwmvbzN6',
id='2',
name='Bank4',
balance=70,
balance=70.00,
type='Credit',
currency='GBP',
limit=300,
limit=300.0,
user_id=user1.id
)

account3 = Account(
id='QlRwmeljv1fxg3aolDwXSe4Kqwv3RjFwmvbzN3',
name='Bank3',
balance=10,
id='3',
name='Bank23',
balance=10.00,
type='Checking',
currency='GBP',
user_id=user2.id
user_id=user1.id
)

account4 = Account(
id='QlRwmeljv1fxg3aolDwXSe4Kqwv3RjFwmvbzN4',
id='4',
name='Bank4',
balance=70,
balance=70.00,
type='Credit',
currency='GBP',
limit=300,
user_id=user2.id
limit=300.0,
user_id=user1.id
)

db.session.add_all([account1, account2, account3, account4])
Expand Down
43 changes: 21 additions & 22 deletions frontend/app/(tabs)/_layout.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
import { useContext } from 'react'
import { Redirect, Tabs } from 'expo-router'
import { GlobalState } from '../../global-provider'
import IconDashboard from '../../assets/icons/dashboard.svg'
import IconAccounts from '../../assets/icons/accounts.svg'
import IconBudget from '../../assets/icons/budget.svg'
import IconTransactions from '../../assets/icons/transactions.svg'
import IconInvestments from '../../assets/icons/investments.svg'
import { useContext } from "react";
import { Redirect, Tabs } from "expo-router";
import { GlobalState } from "../../global-provider";
import IconDashboard from "../../assets/icons/dashboard.svg";
import IconAccounts from "../../assets/icons/accounts.svg";
import IconBudget from "../../assets/icons/budget.svg";
import IconTransactions from "../../assets/icons/transactions.svg";
import IconInvestments from "../../assets/icons/investments.svg";

export default function TabLayout() {
const global = useContext(GlobalState)

const global = useContext(GlobalState);

return (
<Tabs screenOptions={{ tabBarActiveTintColor: 'green' }}>
<Tabs screenOptions={{ tabBarActiveTintColor: "green" }}>
<Tabs.Screen
name='dashboard'
name="dashboard"
options={{
title: 'Dashboard',
title: "Dashboard",
tabBarIcon: () => <IconDashboard />,
}}
/>
<Tabs.Screen
name='accounts'
name="accounts"
options={{
title: 'Accounts',
title: "Accounts",
tabBarIcon: () => <IconAccounts />,
}}
/>
<Tabs.Screen
name='transactions'
name="transactions"
options={{
title: 'Transactions',
title: "Transactions",
tabBarIcon: () => <IconTransactions />,
}}
/>
<Tabs.Screen
name='budget'
name="budget"
options={{
title: 'Budget',
title: "Budget",
tabBarIcon: () => <IconBudget />,
}}
/>
<Tabs.Screen
name='investments'
name="investments"
options={{
title: 'Investments',
title: "Investments",
tabBarIcon: () => <IconInvestments />,
}}
/>
</Tabs>
)
);
}
83 changes: 49 additions & 34 deletions frontend/app/(tabs)/accounts.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
import { View, Text } from "react-native";
import { View, Text, ScrollView, Pressable } from "react-native";
import { useState, useEffect } from "react";
import { useNavigation } from "@react-navigation/native";
import OpenAiChat from "../../components/OpenAiChat";
import LinkedAccount from "../../components/LinkedAccount";
import { Button } from "react-native-paper";
import { Link, router } from "expo-router";

export default function Tab() {
const account1_info = {
name: "Cash 2",
desc: "Selling income",
balance: "560 euros",
};
const account2_info = {
name: "Credit card",
desc: "Discover Card",
balance: "5,000 euros",
};
const account3_info = {
name: "Fidelity",
desc: "Retirement fund",
balance: "20,000 euros",
};
const [accountDetails, setAccountDetails] = useState(null);

return (
<View
style={{
justifyContent: "center",
alignItems: "start",
flex: 1,
marginLeft: 20,
}}
>
<Text className="mb-3 font-bold scale-125 p-2">Manual account</Text>
<LinkedAccount account_info={account1_info} />
<Text className="mb-3 font-bold scale-125 p-2">Linked Credit cards</Text>
<LinkedAccount account_info={account2_info} />
useEffect(() => {
const userId = "1";
const accountId = "1";

const url = `http://127.0.0.1:5555/api/users/${userId}/accounts/${accountId}`;

<Text className="mb-3 font-bold scale-125 p-2">
Linked Investment accounts
</Text>
<LinkedAccount account_info={account3_info} />
</View>
// Fetch account details from your API
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then((data) => {
setAccountDetails(data);
console.log("Data: ", data);
})
.catch((error) =>
console.error("Error fetching account details:", error)
);
}, []);

return (
<ScrollView>
<Text>Manual account</Text>
{accountDetails ? (
<LinkedAccount account={accountDetails} />
) : (
<Text>No account details found.</Text>
)}
<Pressable
onPress={() =>
router.push({
pathname: `/accounts/AddNewAccount/`,
})
}
>
<Button className="bg-forest-green">
<Text className="text-white">Add a new Account</Text>
</Button>
</Pressable>
</ScrollView>
);
}
11 changes: 7 additions & 4 deletions frontend/app/(tabs)/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { View, Text } from 'react-native'
import { View, Text } from "react-native";
import OpenAiChat from "../../components/OpenAiChat";

export default function Tab() {
return (
<View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}>
<Text>Tab [Home|Settings]</Text>
<View style={{ justifyContent: "center", alignItems: "center", flex: 1 }}>
<Text>
<OpenAiChat />
</Text>
</View>
)
);
}
Loading