|
24 | 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 | 25 | "\n", |
26 | 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", |
| 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 | 28 | "- [Assistants OpenAI Overview](https://platform.openai.com/docs/assistants/overview)" |
29 | 29 | ] |
30 | 30 | }, |
|
43 | 43 | "source": [ |
44 | 44 | "## About this example\n", |
45 | 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." |
| 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." |
47 | 50 | ] |
48 | 51 | }, |
49 | 52 | { |
50 | 53 | "cell_type": "markdown", |
51 | 54 | "metadata": {}, |
52 | 55 | "source": [ |
53 | | - "### Data\n", |
54 | | - "\n", |
55 | | - "This sample uses files from the folder [`data/`](data/failed_banks.csv) 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." |
| 56 | + "## Before you begin" |
56 | 57 | ] |
57 | 58 | }, |
58 | 59 | { |
59 | 60 | "cell_type": "markdown", |
60 | 61 | "metadata": {}, |
61 | 62 | "source": [ |
62 | | - "### Load the required libraries" |
| 63 | + "### Installation\n", |
| 64 | + "\n", |
| 65 | + "Install the following packages required to execute this notebook." |
63 | 66 | ] |
64 | 67 | }, |
65 | 68 | { |
|
68 | 71 | "metadata": {}, |
69 | 72 | "outputs": [], |
70 | 73 | "source": [ |
71 | | - "import io\n", |
72 | | - "import os\n", |
73 | | - "import time\n", |
74 | | - "from datetime import datetime\n", |
75 | | - "from pathlib import Path\n", |
76 | | - "from typing import Iterable\n", |
77 | | - "\n", |
78 | | - "from dotenv import load_dotenv\n", |
79 | | - "from openai import AzureOpenAI\n", |
80 | | - "from openai.types import FileObject\n", |
81 | | - "from openai.types.beta.threads.message_content_image_file import MessageContentImageFile\n", |
82 | | - "from openai.types.beta.threads.message_content_text import MessageContentText\n", |
83 | | - "from openai.types.beta.threads.messages import MessageFile\n", |
84 | | - "from PIL import Image" |
| 74 | + "# Install the packages\n", |
| 75 | + "%pip install -r ../requirements.txt" |
85 | 76 | ] |
86 | 77 | }, |
87 | 78 | { |
88 | 79 | "cell_type": "markdown", |
89 | 80 | "metadata": {}, |
90 | 81 | "source": [ |
91 | | - "### Load the environment variables" |
| 82 | + "### Parameters" |
92 | 83 | ] |
93 | 84 | }, |
94 | 85 | { |
|
97 | 88 | "metadata": {}, |
98 | 89 | "outputs": [], |
99 | 90 | "source": [ |
100 | | - "load_dotenv(\"../.env\") #make sure to have the .env file in the root directory of the project\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", |
101 | 97 | "api_endpoint = os.getenv(\"OPENAI_URI\")\n", |
102 | 98 | "api_key = os.getenv(\"OPENAI_KEY\")\n", |
103 | 99 | "api_version = os.getenv(\"OPENAI_VERSION\")\n", |
104 | 100 | "api_deployment_name = os.getenv(\"OPENAI_GPT_DEPLOYMENT\")\n", |
105 | | - "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" |
106 | 138 | ] |
107 | 139 | }, |
108 | 140 | { |
109 | 141 | "cell_type": "markdown", |
110 | 142 | "metadata": {}, |
111 | 143 | "source": [ |
112 | | - "### Create an AzureOpenAI client" |
| 144 | + "### Create an Azure OpenAI client" |
113 | 145 | ] |
114 | 146 | }, |
115 | 147 | { |
|
200 | 232 | "source": [ |
201 | 233 | "def read_assistant_file(file_id:str):\n", |
202 | 234 | " response_content = client.files.content(file_id)\n", |
203 | | - " return response_content.read() \n", |
| 235 | + " return response_content.read()\n", |
204 | 236 | "\n", |
205 | 237 | "def print_messages(messages: Iterable[MessageFile]) -> None:\n", |
206 | 238 | " message_list = []\n", |
|
338 | 370 | "cell_type": "markdown", |
339 | 371 | "metadata": {}, |
340 | 372 | "source": [ |
341 | | - "### Cleanup" |
| 373 | + "### Cleaning up" |
342 | 374 | ] |
343 | 375 | }, |
344 | 376 | { |
|
347 | 379 | "metadata": {}, |
348 | 380 | "outputs": [], |
349 | 381 | "source": [ |
350 | | - "client.beta.assistants.delete(assistant.id)\n", |
351 | | - "client.beta.threads.delete(thread.id)\n", |
352 | | - "for file in assistant_files:\n", |
353 | | - " 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)" |
354 | 387 | ] |
355 | 388 | } |
356 | 389 | ], |
|
0 commit comments