Skip to content

Commit f47b2d6

Browse files
authored
Merge pull request Azure#80 from Azure/assistantscleanup
Assistantscleanup
2 parents 805b107 + 4bd0233 commit f47b2d6

16 files changed

Lines changed: 619 additions & 147 deletions

File tree

gen-ai/Assistants/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Check out the provided samples to get started with integrating the Assistants AP
3535
| [Financial Assistant](./api-in-a-box/personal_finance/assistant-personal_finance.ipynb) | Function Calling with Yfinance to get latest stock prices. Summarization of user provided article. Extract country info from article, extract country, capital and other aspects, and call an API to get more information about each country. |
3636
| [Failed Banks](./api-in-a-box/failed_banks/assistant-failed_banks.ipynb) | Failed Banks is an Assistant designed to analyze and extract data concerning failed banks. It can provide insights into questions like identifying failed banks within specific states during a given time frame and generate charts illustrating bank failures across the US. |
3737
| [Wind Farm](./api-in-a-box/wind_farm/assistant-wind_farm.ipynb) | Utilizing Assistant tools such as the Code Interpreter and Function calling, this bot is capable of retrieving a CSV file that illustrates turbine wind speed, voltage, and the last maintenance date. It assists you in reviewing the file contents and aids in determining whether a specific turbine is in need of maintenance. |
38+
| [Sales Assistant](./api-in-a-box/sales_assistant/assistant_sales.ipynb) | Showcases how you can create an Assistant adept at managing various tasks, such as handling relational data across different files and supporting multiple users simultaneously within the same Assistant across distinct threads. |
3839
| [Assistants Bot-in-a-Box](./bot-in-a-box/) | The Assistants API Bot in-a-box automates virtual assistant deployment on Azure, facilitating seamless communication between users and assistants across various messaging channels. It streamlines message processing and response delivery through Azure Bot Services and the Assistants API. |
3940

4041
## Prerequisites

gen-ai/Assistants/api-in-a-box/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ while True:
145145
|----------------------|--------------------------------------------------|
146146
| [Math Tutor](math_tutor/assistant-math_tutor.ipynb) | Showcases the foundational concepts of Assistants such as Threads, Messages, Runs, Tools, and lifecycle management. |
147147
| [Financial Assistant](personal_finance/assistant-personal_finance.ipynb) | Function Calling with Yfinance to get latest stock prices. Summarization of user provided article. Extract country info from article, extract country, capital and other aspects, and call an API to get more information about each country. |
148-
| [Failed Banks](failed_banks/assistant-failed_banks.ipynb) | Failed Banks is an Assistant designed to analyze and extract data concerning failed banks. It can provide insights into questions like identifying failed banks within specific states during a given time frame and generate charts illustrating bank failures across the US. |
148+
| [Failed Banks](failed_banks/assistant-failed_banks.ipynb) | Using Assistant tools Code Interpreter and Function calling, this Assistant can get a CSV file, gather a list of failed banks by state, and generate a chart to visually represent the data. |
149149
| [Wind Farm](wind_farm/assistant-wind_farm.ipynb) | Utilizing Assistant tools such as the Code Interpreter and Function calling, this bot is capable of retrieving a CSV file that illustrates turbine wind speed, voltage, and the last maintenance date. It assists you in reviewing the file contents and aids in determining whether a specific turbine is in need of maintenance. |
150+
| [Sales Assistant](sales_assistant/assistant_sales.ipynb) | Showcases how you can create an Assistant adept at managing various tasks, such as handling relational data across different files and supporting multiple users simultaneously within the same Assistant across distinct threads. |
150151

151152
## Prerequisites
152153

gen-ai/Assistants/api-in-a-box/failed_banks/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Using Assistant tools Code Interpreter and Function calling, this bot can get a
1010
The objective of the provided notebook file is to create an Azure OpenAI Assistant named "Failed Banks Assistant" using the Azure OpenAI API. The assistant is designed to assist users in obtaining information about failed banks based on a provided CSV file. The assistant is equipped with the capability to process user messages, interact with the provided file, and respond with relevant information.
1111

1212
### Programming Languages
13-
- Python
13+
14+
- Python
1415

1516
### Estimated Runtime: 5 mins

gen-ai/Assistants/api-in-a-box/failed_banks/assistant-failed_banks.ipynb

Lines changed: 112 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,65 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"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",
815
"\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."
1066
]
1167
},
1268
{
@@ -15,27 +71,15 @@
1571
"metadata": {},
1672
"outputs": [],
1773
"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"
3276
]
3377
},
3478
{
3579
"cell_type": "markdown",
3680
"metadata": {},
3781
"source": [
38-
"### Load the environment variables"
82+
"### Parameters"
3983
]
4084
},
4185
{
@@ -44,19 +88,60 @@
4488
"metadata": {},
4589
"outputs": [],
4690
"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",
4897
"api_endpoint = os.getenv(\"OPENAI_URI\")\n",
4998
"api_key = os.getenv(\"OPENAI_KEY\")\n",
5099
"api_version = os.getenv(\"OPENAI_VERSION\")\n",
51100
"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"
53138
]
54139
},
55140
{
56141
"cell_type": "markdown",
57142
"metadata": {},
58143
"source": [
59-
"### Create an AzureOpenAI client"
144+
"### Create an Azure OpenAI client"
60145
]
61146
},
62147
{
@@ -147,7 +232,7 @@
147232
"source": [
148233
"def read_assistant_file(file_id:str):\n",
149234
" response_content = client.files.content(file_id)\n",
150-
" return response_content.read() \n",
235+
" return response_content.read()\n",
151236
"\n",
152237
"def print_messages(messages: Iterable[MessageFile]) -> None:\n",
153238
" message_list = []\n",
@@ -285,7 +370,7 @@
285370
"cell_type": "markdown",
286371
"metadata": {},
287372
"source": [
288-
"### Cleanup"
373+
"### Cleaning up"
289374
]
290375
},
291376
{
@@ -294,10 +379,11 @@
294379
"metadata": {},
295380
"outputs": [],
296381
"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)"
301387
]
302388
}
303389
],

gen-ai/Assistants/api-in-a-box/math_tutor/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ Showcases the foundational concepts of Assistants such as Threads, Messages, Run
77

88
### Objective
99

10-
The objective of the provided Python file is to create an Azure OpenAI Assistant named "Math Tutor" using the Azure OpenAI API. The assistant is designed to function as a personal math tutor, capable of answering math questions through code interpretation. The script initiates a conversation with the assistant, guiding it through various mathematical queries and scenarios to showcase its capabilities.
10+
The objective of the provided notebook file is to create an Azure OpenAI Assistant named "Math Tutor" using the Azure OpenAI API. The assistant is designed to function as a personal math tutor, capable of answering math questions through code interpretation. The script initiates a conversation with the assistant, guiding it through various mathematical queries and scenarios to showcase its capabilities.
1111

1212
### Programming Languages
13-
- Python
13+
14+
- Python
1415

1516
### Estimated Runtime: 5 mins

0 commit comments

Comments
 (0)