{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMlDthhM8w5NIUNYffwmHfr",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "GM-U1_ArmVFO"
},
"outputs": [],
"source": [
"!pip install -q gradio>=4.0.0"
]
},
{
"cell_type": "code",
"source": [
"import gradio as gr\n",
"import openai\n",
"import json\n",
"import html\n",
"from openai import OpenAI\n",
"import random\n",
"import datetime\n",
"from google.colab import userdata"
],
"metadata": {
"id": "FciiJrKSmfOV"
},
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"source": [
"api_key = userdata.get('OPENAI_API_KEY')\n",
"client = OpenAI(api_key=api_key)\n",
"model = \"gpt-4.1-mini\""
],
"metadata": {
"id": "7fPLICmznVur"
},
"execution_count": 24,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def abcd_taskTool():\n",
" tasks = [\n",
" {\"taskId\": \"T001\", \"accNo\": \"1234567890\", \"status\": \"Pending\", \"description\": \"Update account details\"},\n",
" {\"taskId\": \"T002\", \"accNo\": \"9876543210\", \"status\": \"In Progress\", \"description\": \"Verify transaction\"}\n",
" ]\n",
"\n",
" probability_of_tasks = 0.8\n",
" if random.random() < probability_of_tasks:\n",
" return tasks\n",
" else:\n",
" return []"
],
"metadata": {
"id": "zyXLchykmoW_"
},
"execution_count": 35,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def abcd_NotifyTool():\n",
" # Mock notification function\n",
" return True"
],
"metadata": {
"id": "h4J8HOOJm78X"
},
"execution_count": 11,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Tool definitions for OpenAI\n",
"tools = [\n",
" {\n",
" \"type\": \"function\",\n",
" \"function\": {\n",
" \"name\": \"abcd_taskTool\",\n",
" \"description\": \"Retrieve a list of ABCD tasks.\",\n",
" \"parameters\": {}\n",
" }\n",
" },\n",
" {\n",
" \"type\": \"function\",\n",
" \"function\": {\n",
" \"name\": \"abcd_NotifyTool\",\n",
" \"description\": \"Notify the support team about tasks.\",\n",
" \"parameters\": {}\n",
" }\n",
" }\n",
"]"
],
"metadata": {
"id": "KOtTI6PunNJ7"
},
"execution_count": 12,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Function to mask first four digits of accNo\n",
"def mask_accNo(accNo):\n",
" return \"****\" + accNo[4:] if len(accNo) >= 4 else accNo"
],
"metadata": {
"id": "p7wU9CRBnTAS"
},
"execution_count": 13,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Function to format tasks as an HTML table\n",
"def format_tasks_as_table(tasks):\n",
" if not tasks:\n",
" return \"No tasks found.\"\n",
"\n",
" table = \"
| Task ID | Account Number | Status | Description |
|---|---|---|---|
| {html.escape(task.get('taskId', ''))} | \"\n", " table += f\"{html.escape(mask_accNo(task.get('accNo', '')))} | \"\n", " table += f\"{html.escape(task.get('status', ''))} | \"\n", " table += f\"{html.escape(task.get('description', ''))} | \"\n", " table += \"