|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "# Failed Banks Information Assistant\n", |
| 7 | + "# Failed Banks Information Assistant" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "## Objective\n", |
8 | 15 | "\n", |
9 | | - "### Load the required libraries" |
| 16 | + "This notebook demonstrates the following:\n", |
| 17 | + "\n", |
| 18 | + "- Using Assistant tools Code Interpreter and Function calling, this bot can get a CSV file, gather a list of failed banks by state, and generate a chart to visually represent the data.\n", |
| 19 | + "\n", |
| 20 | + "This tutorial uses the following Azure AI services:\n", |
| 21 | + "- Access to Azure OpenAI Service - you can apply for access [here](https://aka.ms/oai/access)\n", |
| 22 | + "- Azure OpenAI service - you can create it from instructions [here](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource)\n", |
| 23 | + "- Azure OpenAI Studio - go to [https://oai.azure.com/](https://oai.azure.com/) to work with the Assistants API Playground\n", |
| 24 | + "- A connection to the Azure OpenAI Service with a [Key and Endpoint](https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart)\n", |
| 25 | + "\n", |
| 26 | + "Reference:\n", |
| 27 | + "- Learn more about how to use Assistants with our [How-to guide on Assistants](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant)\n", |
| 28 | + "- [Assistants OpenAI Overview](https://platform.openai.com/docs/assistants/overview)" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "metadata": {}, |
| 34 | + "source": [ |
| 35 | + "## Time\n", |
| 36 | + "\n", |
| 37 | + "You should expect to spend 5-10 minutes running this sample. " |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "markdown", |
| 42 | + "metadata": {}, |
| 43 | + "source": [ |
| 44 | + "## About this example\n", |
| 45 | + "\n", |
| 46 | + "This sample demonstrates the creation of an Azure OpenAI Assistant named \"Failed Banks Assistant\" through the Azure OpenAI API. The assistant is tailored to aid users in retrieving information about failed banks from a CSV file, the assistant efficiently processes user messages, interacts with the designated file, and promptly delivers pertinent information in response.\n", |
| 47 | + "\n", |
| 48 | + "### Data\n", |
| 49 | + "This sample uses files from the folder [`data/`](./data/) in this repo. You can clone this repo or copy this folder to make sure you have access to these files when running the sample." |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "metadata": {}, |
| 55 | + "source": [ |
| 56 | + "## Before you begin" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "### Installation\n", |
| 64 | + "\n", |
| 65 | + "Install the following packages required to execute this notebook." |
10 | 66 | ] |
11 | 67 | }, |
12 | 68 | { |
|
15 | 71 | "metadata": {}, |
16 | 72 | "outputs": [], |
17 | 73 | "source": [ |
18 | | - "import io\n", |
19 | | - "import os\n", |
20 | | - "import time\n", |
21 | | - "from datetime import datetime\n", |
22 | | - "from pathlib import Path\n", |
23 | | - "from typing import Iterable\n", |
24 | | - "\n", |
25 | | - "from dotenv import load_dotenv\n", |
26 | | - "from openai import AzureOpenAI\n", |
27 | | - "from openai.types import FileObject\n", |
28 | | - "from openai.types.beta.threads.message_content_image_file import MessageContentImageFile\n", |
29 | | - "from openai.types.beta.threads.message_content_text import MessageContentText\n", |
30 | | - "from openai.types.beta.threads.messages import MessageFile\n", |
31 | | - "from PIL import Image" |
| 74 | + "# Install the packages\n", |
| 75 | + "%pip install -r ../requirements.txt" |
32 | 76 | ] |
33 | 77 | }, |
34 | 78 | { |
35 | 79 | "cell_type": "markdown", |
36 | 80 | "metadata": {}, |
37 | 81 | "source": [ |
38 | | - "### Load the environment variables" |
| 82 | + "### Parameters" |
39 | 83 | ] |
40 | 84 | }, |
41 | 85 | { |
|
44 | 88 | "metadata": {}, |
45 | 89 | "outputs": [], |
46 | 90 | "source": [ |
47 | | - "load_dotenv(\"../.env\")\n", |
| 91 | + "import os\n", |
| 92 | + "\n", |
| 93 | + "from dotenv import load_dotenv\n", |
| 94 | + "\n", |
| 95 | + "load_dotenv(\"../.env\") # make sure to have the .env file in the root directory of the project\n", |
| 96 | + "\n", |
48 | 97 | "api_endpoint = os.getenv(\"OPENAI_URI\")\n", |
49 | 98 | "api_key = os.getenv(\"OPENAI_KEY\")\n", |
50 | 99 | "api_version = os.getenv(\"OPENAI_VERSION\")\n", |
51 | 100 | "api_deployment_name = os.getenv(\"OPENAI_GPT_DEPLOYMENT\")\n", |
52 | | - "email_URI = os.getenv(\"EMAIL_URI\")" |
| 101 | + "email_URI = os.getenv(\"EMAIL_URI\")\n", |
| 102 | + "\n", |
| 103 | + "should_cleanup: bool = False" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "markdown", |
| 108 | + "metadata": {}, |
| 109 | + "source": [ |
| 110 | + "## Run this Example" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "markdown", |
| 115 | + "metadata": {}, |
| 116 | + "source": [ |
| 117 | + "### Load the required libraries" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": null, |
| 123 | + "metadata": {}, |
| 124 | + "outputs": [], |
| 125 | + "source": [ |
| 126 | + "import io\n", |
| 127 | + "import time\n", |
| 128 | + "from datetime import datetime\n", |
| 129 | + "from pathlib import Path\n", |
| 130 | + "from typing import Iterable\n", |
| 131 | + "\n", |
| 132 | + "from openai import AzureOpenAI\n", |
| 133 | + "from openai.types import FileObject\n", |
| 134 | + "from openai.types.beta.threads.message_content_image_file import MessageContentImageFile\n", |
| 135 | + "from openai.types.beta.threads.message_content_text import MessageContentText\n", |
| 136 | + "from openai.types.beta.threads.messages import MessageFile\n", |
| 137 | + "from PIL import Image" |
53 | 138 | ] |
54 | 139 | }, |
55 | 140 | { |
56 | 141 | "cell_type": "markdown", |
57 | 142 | "metadata": {}, |
58 | 143 | "source": [ |
59 | | - "### Create an AzureOpenAI client" |
| 144 | + "### Create an Azure OpenAI client" |
60 | 145 | ] |
61 | 146 | }, |
62 | 147 | { |
|
147 | 232 | "source": [ |
148 | 233 | "def read_assistant_file(file_id:str):\n", |
149 | 234 | " response_content = client.files.content(file_id)\n", |
150 | | - " return response_content.read() \n", |
| 235 | + " return response_content.read()\n", |
151 | 236 | "\n", |
152 | 237 | "def print_messages(messages: Iterable[MessageFile]) -> None:\n", |
153 | 238 | " message_list = []\n", |
|
285 | 370 | "cell_type": "markdown", |
286 | 371 | "metadata": {}, |
287 | 372 | "source": [ |
288 | | - "### Cleanup" |
| 373 | + "### Cleaning up" |
289 | 374 | ] |
290 | 375 | }, |
291 | 376 | { |
|
294 | 379 | "metadata": {}, |
295 | 380 | "outputs": [], |
296 | 381 | "source": [ |
297 | | - "client.beta.assistants.delete(assistant.id)\n", |
298 | | - "client.beta.threads.delete(thread.id)\n", |
299 | | - "for file in assistant_files:\n", |
300 | | - " client.files.delete(file.id)" |
| 382 | + "if should_cleanup:\n", |
| 383 | + " client.beta.assistants.delete(assistant.id)\n", |
| 384 | + " client.beta.threads.delete(thread.id)\n", |
| 385 | + " for file in assistant_files:\n", |
| 386 | + " client.files.delete(file.id)" |
301 | 387 | ] |
302 | 388 | } |
303 | 389 | ], |
|
0 commit comments