Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Personal Finance Tracker Agent #672

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Exciting news! We're participating in DevFest.AI throughout October 2024! 🗓
- [Local Quickstart](#local-quickstart)
- [SDK Reference](#sdk-reference)
- [API Reference](#api-reference)
- [Why Julep vs. LangChain?](#why-julep-vs-langchain)
- [Different Use Cases](#different-use-cases)
- [Different Form Factor](#different-form-factor)
- [In Summary](#in-summary)

</details>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down
208 changes: 208 additions & 0 deletions cookbooks/15_Personal_Finance_Tracker.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"source": [
"import uuid\n",
"import yaml\n",
"import time\n",
"from julep import Client\n",
"\n",
"TRACKER_UUID = uuid.uuid4()\n",
"BUDGET_TASK_UUID = uuid.uuid4()\n",
"ADVICE_TASK_UUID = uuid.uuid4()\n",
"\n",
"api_key = \"\" # Your API key here\n",
"client = Client(api_key=api_key, environment=\"dev\")\n",
"\n",
"agent = client.agents.create_or_update(\n",
" agent_id=TRACKER_UUID,\n",
" name=\"Personal Finance Tracker\",\n",
" about=\"Tracks user expenses, analyzes spending patterns, and provides financial advice.\",\n",
" model=\"gpt-4o\",\n",
")\n",
"\n",
"log_expense_task_def = yaml.safe_load(f\"\"\"\n",
"name: Log Expense\n",
"\n",
"input_schema:\n",
" type: object\n",
" properties:\n",
" amount:\n",
" type: number\n",
" category:\n",
" type: string\n",
" description:\n",
" type: string\n",
"\n",
"tools:\n",
"- name: finance_tool\n",
" system:\n",
" resource: agent\n",
" subresource: tool\n",
" operation: create\n",
"\n",
"main:\n",
"- tool: finance_tool\n",
" arguments:\n",
" agent_id: \"'{agent.id}'\"\n",
" data:\n",
" amount: inputs[0].amount\n",
" category: inputs[0].category\n",
" description: inputs[0].description\n",
"\"\"\")\n",
"\n",
"log_expense_task = client.tasks.create_or_update(\n",
" task_id=TRACKER_UUID,\n",
" agent_id=TRACKER_UUID,\n",
" **log_expense_task_def\n",
")\n",
"\n",
"set_budget_task_def = yaml.safe_load(f\"\"\"\n",
"name: Set Budget\n",
"\n",
"input_schema:\n",
" type: object\n",
" properties:\n",
" category:\n",
" type: string\n",
" budget_amount:\n",
" type: number\n",
"\n",
"tools:\n",
"- name: finance_tool\n",
" system:\n",
" resource: agent\n",
" subresource: tool\n",
" operation: create\n",
"\n",
"main:\n",
"- tool: finance_tool\n",
" arguments:\n",
" agent_id: \"'{agent.id}'\"\n",
" data:\n",
" category: inputs[0].category\n",
" budget_amount: inputs[0].budget_amount\n",
"\"\"\")\n",
"\n",
"set_budget_task = client.tasks.create_or_update(\n",
" task_id=BUDGET_TASK_UUID,\n",
" agent_id=TRACKER_UUID,\n",
" **set_budget_task_def\n",
")\n",
"\n",
"send_advice_task_def = yaml.safe_load(f\"\"\"\n",
"name: Send Financial Advice\n",
"\n",
"input_schema:\n",
" type: object\n",
" properties:\n",
" advice:\n",
" type: string\n",
" email:\n",
" type: string\n",
"\n",
"tools:\n",
"- name: email_tool\n",
" system:\n",
" resource: agent\n",
" subresource: tool\n",
" operation: create\n",
"\n",
"main:\n",
"- tool: email_tool\n",
" arguments:\n",
" agent_id: \"'{agent.id}'\"\n",
" to: inputs[0].email\n",
" subject: \"Financial Advice\"\n",
" body: inputs[0].advice\n",
"\"\"\")\n",
"\n",
"send_advice_task = client.tasks.create_or_update(\n",
" task_id=ADVICE_TASK_UUID,\n",
" agent_id=TRACKER_UUID,\n",
" **send_advice_task_def\n",
")\n",
"\n",
"def log_expense(amount, category, description):\n",
" execution = client.executions.create(\n",
" task_id=TRACKER_UUID,\n",
" input={\"amount\": amount, \"category\": category, \"description\": description}\n",
" )\n",
" print(\"Logging expense...\")\n",
" time.sleep(5)\n",
" result = client.executions.get(execution.id)\n",
" print(f\"Expense logged: {description} of ${amount} in {category} category.\")\n",
"\n",
"def set_budget(category, budget_amount):\n",
" execution = client.executions.create(\n",
" task_id=BUDGET_TASK_UUID,\n",
" input={\"category\": category, \"budget_amount\": budget_amount}\n",
" )\n",
" print(\"Setting budget...\")\n",
" time.sleep(5)\n",
" result = client.executions.get(execution.id)\n",
" print(f\"Budget set for {category}: ${budget_amount}.\")\n",
"\n",
"def send_financial_advice(email, advice):\n",
" execution = client.executions.create(\n",
" task_id=ADVICE_TASK_UUID,\n",
" input={\"advice\": advice, \"email\": email}\n",
" )\n",
" print(\"Sending financial advice...\")\n",
" time.sleep(5)\n",
" result = client.executions.get(execution.id)\n",
" print(f\"Advice sent to {email}: '{advice}'.\")\n",
"\n",
"log_expense(50, \"Groceries\", \"Weekly grocery shopping\")\n",
"set_budget(\"Groceries\", 200)\n",
"send_financial_advice(\"[email protected]\", \"Consider reducing your grocery budget to save more.\")\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "32Q7ccRJs_h5",
"outputId": "3ffa8354-ec10-4fed-9da8-9bf7c234a35d"
},
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Logging expense...\n",
"Expense logged: Weekly grocery shopping of $50 in Groceries category.\n",
"Setting budget...\n",
"Budget set for Groceries: $200.\n",
"Sending financial advice...\n",
"Advice sent to [email protected]: 'Consider reducing your grocery budget to save more.'.\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "k9fvuTaGtGBp"
},
"execution_count": null,
"outputs": []
}
]
}
164 changes: 164 additions & 0 deletions cookbooks/15_personal_finance_tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# -*- coding: utf-8 -*-
"""15_Personal_Finance_Tracker.ipynb

Automatically generated by Colab.

Original file is located at
https://colab.research.google.com/drive/1jzy4evusmnkPxntEdpibh_Xm12T-m8in
"""

import uuid
import yaml
import time
from julep import Client

TRACKER_UUID = uuid.uuid4()
BUDGET_TASK_UUID = uuid.uuid4()
ADVICE_TASK_UUID = uuid.uuid4()

api_key = "" # Your API key here
client = Client(api_key=api_key, environment="dev")

agent = client.agents.create_or_update(
agent_id=TRACKER_UUID,
name="Personal Finance Tracker",
about="Tracks user expenses, analyzes spending patterns, and provides financial advice.",
model="gpt-4o",
)

log_expense_task_def = yaml.safe_load(f"""
name: Log Expense

input_schema:
type: object
properties:
amount:
type: number
category:
type: string
description:
type: string

tools:
- name: finance_tool
system:
resource: agent
subresource: tool
operation: create

main:
- tool: finance_tool
arguments:
agent_id: "'{agent.id}'"
data:
amount: inputs[0].amount
creatorrr marked this conversation as resolved.
Show resolved Hide resolved
category: inputs[0].category
description: inputs[0].description
""")

log_expense_task = client.tasks.create_or_update(
task_id=TRACKER_UUID,
agent_id=TRACKER_UUID,
**log_expense_task_def
)

set_budget_task_def = yaml.safe_load(f"""
name: Set Budget

input_schema:
type: object
properties:
category:
type: string
budget_amount:
type: number

tools:
- name: finance_tool
system:
resource: agent
subresource: tool
operation: create

main:
- tool: finance_tool
arguments:
agent_id: "'{agent.id}'"
data:
category: inputs[0].category
budget_amount: inputs[0].budget_amount
""")

set_budget_task = client.tasks.create_or_update(
task_id=BUDGET_TASK_UUID,
agent_id=TRACKER_UUID,
**set_budget_task_def
)

send_advice_task_def = yaml.safe_load(f"""
name: Send Financial Advice

input_schema:
type: object
properties:
advice:
type: string
email:
type: string

tools:
- name: email_tool
system:
resource: agent
subresource: tool
operation: create

main:
- tool: email_tool
arguments:
agent_id: "'{agent.id}'"
to: inputs[0].email
subject: "Financial Advice"
body: inputs[0].advice
""")

send_advice_task = client.tasks.create_or_update(
task_id=ADVICE_TASK_UUID,
agent_id=TRACKER_UUID,
**send_advice_task_def
)

def log_expense(amount, category, description):
execution = client.executions.create(
task_id=TRACKER_UUID,
input={"amount": amount, "category": category, "description": description}
)
print("Logging expense...")
time.sleep(5)
result = client.executions.get(execution.id)
print(f"Expense logged: {description} of ${amount} in {category} category.")

def set_budget(category, budget_amount):
execution = client.executions.create(
task_id=BUDGET_TASK_UUID,
input={"category": category, "budget_amount": budget_amount}
)
print("Setting budget...")
time.sleep(5)
result = client.executions.get(execution.id)
print(f"Budget set for {category}: ${budget_amount}.")

def send_financial_advice(email, advice):
execution = client.executions.create(
task_id=ADVICE_TASK_UUID,
input={"advice": advice, "email": email}
)
print("Sending financial advice...")
time.sleep(5)
result = client.executions.get(execution.id)
print(f"Advice sent to {email}: '{advice}'.")

log_expense(50, "Groceries", "Weekly grocery shopping")
set_budget("Groceries", 200)
send_financial_advice("[email protected]", "Consider reducing your grocery budget to save more.")

Loading