From 10d7e9dc787e9301d87a953f97ebd38f6185f980 Mon Sep 17 00:00:00 2001 From: Mayank8881 <134052456+Mayank8881@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:25:31 +0530 Subject: [PATCH] Add files via upload --- cookbooks/15_Personal_Finance_Tracker.ipynb | 208 ++++++++++++++++++++ cookbooks/15_personal_finance_tracker.py | 164 +++++++++++++++ 2 files changed, 372 insertions(+) create mode 100644 cookbooks/15_Personal_Finance_Tracker.ipynb create mode 100644 cookbooks/15_personal_finance_tracker.py diff --git a/cookbooks/15_Personal_Finance_Tracker.ipynb b/cookbooks/15_Personal_Finance_Tracker.ipynb new file mode 100644 index 00000000..cd690994 --- /dev/null +++ b/cookbooks/15_Personal_Finance_Tracker.ipynb @@ -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(\"user@example.com\", \"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 user@example.com: 'Consider reducing your grocery budget to save more.'.\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "k9fvuTaGtGBp" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/cookbooks/15_personal_finance_tracker.py b/cookbooks/15_personal_finance_tracker.py new file mode 100644 index 00000000..ffda91b1 --- /dev/null +++ b/cookbooks/15_personal_finance_tracker.py @@ -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 + 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("user@example.com", "Consider reducing your grocery budget to save more.") +