import json
import os
from dotenv import load_dotenv
import openai
from openai import OpenAI
= OpenAI()
client
load_dotenv()# openai key
= os.getenv("OPENAI_API_KEY")
OPENAI_API_KEY = OPENAI_API_KEY
openai.api_key from IPython.display import display, Markdown
import time
import plotly.io as pio
= "notebook" pio.renderers.default
Welcome to our tutorial on “Building a Personalised Travel Planner using OpenAI Assistants APIs”. In this blog post, we will guide you through the process of creating “Voyage Vista”, a travel planning tool that uses OpenAI Assistants APIs to bring your dream vacation to life.
Voyage Vista: Your Personal Travel Planner
Voyage Vista is designed to make travel planning an immersive and enjoyable experience. It provides real-time weather updates, lists top tourist attractions, and offers customized travel guides, all with the aim of helping you create unforgettable memories.
Key Features
- Interactive Map: Voyage Vista’s map provides real-time weather updates with intuitive color-coded indicators, making it easy to plan your day.
- Customized Itineraries: Voyage Vista generates a detailed Word document that serves as your travel guide, filled with historical and cultural insights about your destination.
- Real-Time Weather Forecasts: Weather forecasts are displayed on an interactive map, helping you plan your day perfectly.
- Top Tourist Attractions: Voyage Vista ensures you don’t miss out on any highlights by listing the must-see spots of your chosen destination.
Leveraging OpenAI Assistants APIs
In the development of Voyage Vista, we will be using several features of the OpenAI Assistants APIs:
- Parallel Function Calling: This feature allows us to execute multiple functions simultaneously, improving the efficiency of our application.
- Code Interpreter: The Code Interpreter feature will be instrumental in processing and interpreting the data and generate word documents and other processing data.
- Threads: Threads allow us to manage multiple conversations or tasks concurrently, which is useful for handling multiple user requests at the same time.
- Messages: The Messages feature will be used to communicate with users, providing them with real-time updates and responses to their queries.
By leveraging these features, we aim to create a dynamic, efficient, and user-friendly travel planning tool. In the following sections of this tutorial, we will delve deeper into each of these features and show you how to use them to build your own version of Voyage Vista
print(openai.__version__)
1.7.0
import plotly.graph_objects as go
import requests
def get_coordinates(place_name, city_name):
"""Fetches coordinates of a place using Nominatim API."""
= f"https://nominatim.openstreetmap.org/search?format=json&q={place_name}, {city_name}"
url = requests.get(url)
response = response.json()
data if data:
return float(data[0]['lat']), float(data[0]['lon'])
else:
return None, None
This function takes a place name and city name and retrieve coordinates using nominatim API. It returns a tuple of latitude and longitude.
def create_city_map(city_name, attractions, is_rainy):
if not attractions:
print(f"No attractions found for {city_name}")
return None
# Prepare lists for latitudes and longitudes
= [], []
lats, lons
# Add markers for each attraction
= []
markers for index, place in enumerate(attractions):
= get_coordinates(place, city_name)
lat, lon if lat and lon:
lats.append(lat)
lons.append(lon)= 'red' if is_rainy[index].lower() == 'yes' else 'blue'
marker_color
markers.append(go.Scattermapbox(= [lon],
lon = [lat],
lat = 'markers+text', # Combine markers and text
mode = go.scattermapbox.Marker(size=14, color=marker_color),
marker = [f"{index + 1}. {place}"],
text = "top right", # Position of the text,
textposition =place
name
))
# Create a Plotly map
= go.Figure(markers)
city_map
# Automatically adjust the zoom to fit all markers
city_map.update_layout(="open-street-map",
mapbox_style= {
mapbox 'center': go.layout.mapbox.Center(lat=sum(lats) / len(lats), lon=sum(lons) / len(lons)),
'zoom': 10 # Adjust this value for best fit
},={"r":0,"t":0,"l":0,"b":0}
margin
)
city_map.show()
# save the map to png file
f'{city_name}.png')
city_map.write_image(
return {'png': f'{city_name}.png'}
# Dummy data
= 'London'
city_name = ['London Eye', 'Buckingham Palace', 'British Museum']
attractions = ['Yes', 'No', 'No']
is_rainy
create_city_map(city_name, attractions, is_rainy)
{'png': 'London.png'}
create_city_map
function is helpfule to plot the map of tourist attractions, it also takes weather information such as is_raining and color code the map accordingly.
# !pip install -U kaleido
= os.getenv("OPENWEATHER_API_KEY") api_key
import requests
import json
import os
from datetime import datetime
def get_weather(location, date, unit="metric", use_coordinates=False):
"""Get weather for a given location and date using OpenWeather API."""
= datetime.now().date()
current_date = datetime.strptime(date, "%Y-%m-%d").date()
requested_date
if requested_date == current_date:
= "weather" # Current weather
endpoint elif requested_date < current_date:
= (
endpoint "timemachine" # Historical weather (requires different API subscription)
)else:
= "forecast" # Future weather (limited to 5-16 days based on API plan)
endpoint
= f"http://api.openweathermap.org/data/2.5/{endpoint}"
base_url
if use_coordinates:
= {
params "lat": location[0],
"lon": location[1],
"appid": api_key,
"units": unit,
}else:
= {"q": location, "appid": api_key, "units": unit}
params
if endpoint == "timemachine":
"dt"] = int(requested_date.timestamp())
params[
try:
= requests.get(base_url, params=params)
response
response.raise_for_status()= response.json()
data
= {
weather "location": location,
"date": date,
"unit": "Celsius" if unit == "metric" else "Fahrenheit",
"temperature": data["list"][0]["main"]["temp"],
"humidity": data["list"][0]["main"]["humidity"],
"wind_speed": data["list"][0]["wind"]["speed"],
"description": data["list"][0]["weather"][0]["description"],
}# weather.update(data["list"][0])
return json.dumps(weather, indent=4)
except KeyError as err:
# for current date
= requests.get(base_url, params=params)
response
response.raise_for_status()= response.json()
data = {
weather "location": location,
"date": date,
"unit": "Celsius" if unit == "metric" else "Fahrenheit",
"temperature": data["main"]["temp"],
"humidity": data["main"]["humidity"],
"wind_speed": data["wind"]["speed"],
"description": data["weather"][0]["description"],
}return json.dumps(weather, indent=4)
except requests.exceptions.HTTPError as err:
return json.dumps({"error": f"HTTP Error: {err}"})
except requests.exceptions.RequestException as e:
return json.dumps({"error": f"Request Error: {e}"})
= get_weather("Kyoto", "2024-01-11")
weather_info print(weather_info)
{
"location": "Kyoto",
"date": "2024-01-11",
"unit": "Celsius",
"temperature": 6.17,
"humidity": 78,
"wind_speed": 2.36,
"description": "overcast clouds"
}
The get_weather
function for fetching weather information for a specific location and date using the OpenWeather API. It handles current, historical, and future weather data. The script is designed to process requests for specific dates and locations, returning a JSON formatted output with details like temperature, humidity, wind speed, and a weather description.
# find location and weather details
= "Fushimi Inari-taisha Shrine, Kyoto"
place_name = get_coordinates(place_name, "Kyoto")
lat, lon print(f"Coordinates of {place_name}: {lat}, {lon}")
= get_weather((lat, lon), use_coordinates=True, date="2024-01-11")
weather_info print(weather_info)
Coordinates of Fushimi Inari-taisha Shrine, Kyoto: 34.9672545, 135.7737731
{
"location": [
34.9672545,
135.7737731
],
"date": "2024-01-11",
"unit": "Celsius",
"temperature": 6.24,
"humidity": 77,
"wind_speed": 2.06,
"description": "overcast clouds"
}
= get_weather((lat, lon), use_coordinates=True, date="2024-01-10")
weather_info print(weather_info)
{
"location": [
34.9672545,
135.7737731
],
"date": "2024-01-10",
"unit": "Celsius",
"temperature": 7.22,
"humidity": 78,
"wind_speed": 0.45,
"description": "overcast clouds"
}
= "Kyoto" city_name
Create an TravelPlanner Assistant
We plan to use a few functions and code interpreter as a tools in our assistant.
So Let’s start with defining JSONs so that our assistant can ask us to call these functions providing arguments.
= {
get_coordinates_json "type": "function",
"function": {
"name": "get_coordinates",
"description": "Fetches coordinates of a place using Nominatim API.",
"parameters": {
"type": "object",
"properties": {
"place_name": {
"type": "string",
"description": "The name of the specific place."
},"city_name": {
"type": "string",
"description": "The name of the city where the place is located."
}
},"required": ["place_name", "city_name"]
}
} }
= {
create_city_map_json "type": "function",
"function": {
"name": "create_city_map",
"description": "Creates a map with markers for specified attractions in a city.",
"parameters": {
"type": "object",
"properties": {
"city_name": {
"type": "string",
"description": "The name of the city."
},"attractions": {
"type": "array",
"items": {
"type": "string"
},"description": "A list of attraction names in the city."
},"is_rainy": {
"type": "array",
"items": {
"type": "string"
},"description": "A list of strings indicating whether it is rainy for each attraction."
}
},"required": ["city_name", "attractions", "is_rainy"]
}
} }
= {
get_weather_json "type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a given location and date using OpenWeather API.",
"parameters": {
"type": "object",
"properties": {
"location": {
"oneOf": [
{"type": "string",
"description": "The location name for which weather information is required."
},
{"type": "array",
"items": {
"type": "number"
},"minItems": 2,
"maxItems": 2,
"description": "The coordinates (latitude, longitude) for which weather information is required."
}
]
},"date": {
"type": "string",
"description": "The date for the weather forecast in YYYY-MM-DD format."
},"unit": {
"type": "string",
"enum": ["metric", "imperial"],
"description": "The unit for temperature (metric or imperial)."
},"use_coordinates": {
"type": "boolean",
"description": "Flag to use coordinates instead of location name."
}
},"required": ["location", "date", "use_coordinates"]
}
} }
= {
available_functions "get_coordinates": get_coordinates,
"create_city_map": create_city_map,
"get_weather": get_weather
}
= [
tools
get_coordinates_json,
create_city_map_json,
get_weather_json,"type":"code_interpreter"}
{ ]
= """You are a personal travel assistant.You use available functions to help your user plan their trip.
instructions Create inputs to the functions carefully. If you could not find the available functions,
you can use your own knowledge to help your user.Sometimes you have to use parallel functions to get the desired output
Find the exact date they are planning to visit and use that information for getting current weather.
To do plotting, we need coordinates, current weather and tourist attractions.
so for plotting maps, first get coordinates of each tourist attractions that you suggest, then get current weather and then do the plotting of map.mro
We are color coding the markers based on weather condition. If it is rainy, we use red color, otherwise blue. This is helpful for the user to plan their trip accordingly.
"""
= client.beta.assistants.create(
assistant ="Travel Assistant",
name=instructions,
instructions=tools,
tools="gpt-4-1106-preview"
model )
= client.chat.completions.create(
response ="gpt-4-1106-preview",
model=[
messages"role": "user", "content": "What's the today's date, return date: YYYY-MM-DD in json"},
{
],=0.3,
temperature=1,
seed={"type": "json_object"},
response_format )
= json.loads(response.choices[0].message.content)
current_date print(current_date)
{'date': '2023-04-06'}
We tried to find the current date from the ChatCompletion
model, which failed to give us the correct date. So, adding a code interpreter to get the current date will be helpful.
Create a Thread
- Threads are stateful.
- A thread can be assosciated with many assistants
- We can add messages to the thread.
- Code interpreter and other tools can add messages to a thread
= client.beta.threads.create() thread
Message 1: City Information, Attractions, Weather, and Map
# adding personalisation
= "temples, gardens, museums, food" preferences
= client.beta.threads.messages.create(
message =thread.id,
thread_id="user",
role=f"""I am planning a visit to {city_name} today and would appreciate detailed information about the city.
content Please provide an overview of the location(20-30 words each), and list the top 10 tourist attractions. Additionally, could you include the current date and weather forecast for each attraction? Utilize the code interpreter to retrieve the current date in the city location.
Kindly organize the attractions in a sequence that facilitates an efficient visiting route.
Attraction focus preferences: {preferences}
"""
)
So far we added messages to a thread, to get the response from the model, we should create a Run.
Runs are asynchronous.
= client.beta.threads.runs.create(
run =thread.id,
thread_id=assistant.id,
assistant_id )
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id )
run.status
'in_progress'
while run.status == "queued" or run.status == "in_progress":
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id
)print(run.status)
5)
time.sleep(
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
requires_action
= client.beta.threads.messages.list(
messages =thread.id
thread_id
)
messages
SyncCursorPage[ThreadMessage](data=[ThreadMessage(id='msg_fLewruXXNrfKUrjUwCKlmcVQ', assistant_id='asst_LacvLlXSc8oG1sM5eIk4CY4D', content=[MessageContentText(text=Text(annotations=[], value="The current date in Kyoto is January 10, 2024.\n\nKyoto is a city that harmoniously blends centuries of history with modern culture. It was Japan's capital for over a millennium, leaving it with numerous temples, shrines, and traditional tea houses.\n\nHere are the top 10 tourist attractions in Kyoto, with a focus on temples, gardens, museums, and food:\n\n**Temples and Gardens:**\n1. **Kinkaku-ji (Golden Pavilion):** A Zen temple with top floors covered entirely in gold leaf, set beside a tranquil pond.\n2. **Fushimi Inari Taisha:** A Shinto shrine famous for its thousands of vermilion torii gates leading up to Mount Inari.\n3. **Ginkaku-ji (Silver Pavilion):** A Zen temple known for its beautiful sand garden and moss garden, despite not being covered in silver.\n4. **Arashiyama Bamboo Grove:** A natural forest of bamboo in Arashiyama, providing a unique and picturesque walking experience.\n5. **Ryoan-ji:** A Zen temple with one of Japan's most famous rock gardens.\n6. **Tofuku-ji:** A large Zen temple in southeastern Kyoto, renowned for its spectacular autumn colors and large garden complex.\n\n**Museums:**\n7. **Kyoto International Manga Museum:** A museum dedicated to the art of Japanese manga, with extensive collections and exhibitions.\n\n**Food Experience:**\n8. **Nishiki Market:** A vibrant and historic market with a variety of food-related shops and eateries offering local Japanese cuisine.\n9. **Pontocho Alley:** A historic and atmospheric dining area along the Pontocho geographic feature, known for its traditional dining establishments.\n10. **Gion:** Kyoto's most famous geisha district, offering a glimpse into traditional Japanese entertainment and fine dining.\n\nNow I will get the coordinates for each of these attractions and then retrieve the current weather forecast for each location for today."), type='text')], created_at=1704878735, file_ids=[], metadata={}, object='thread.message', role='assistant', run_id='run_mwlAc83GMWAwvaxohUbHDwz7', thread_id='thread_RLEZYpAQcB654HqzZipvzxtd'), ThreadMessage(id='msg_gYoCCX8t88p9aLECqTuJx2yz', assistant_id=None, content=[MessageContentText(text=Text(annotations=[], value='I am planning a visit to Kyoto today and would appreciate detailed information about the city.\n Please provide an overview of the location(20-30 words each), and list the top 10 tourist attractions. Additionally, could you include the current date and weather forecast for each attraction? Utilize the code interpreter to retrieve the current date in the city location.\n Kindly organize the attractions in a sequence that facilitates an efficient visiting route.\n \n Attraction focus preferences: temples, gardens, museums, food\n \n '), type='text')], created_at=1704878722, file_ids=[], metadata={}, object='thread.message', role='user', run_id=None, thread_id='thread_RLEZYpAQcB654HqzZipvzxtd')], object='list', first_id='msg_fLewruXXNrfKUrjUwCKlmcVQ', last_id='msg_gYoCCX8t88p9aLECqTuJx2yz', has_more=False)
0].content[0].text.value)) display(Markdown(messages.data[
The current date in Kyoto is January 10, 2024.
Kyoto is a city that harmoniously blends centuries of history with modern culture. It was Japan’s capital for over a millennium, leaving it with numerous temples, shrines, and traditional tea houses.
Here are the top 10 tourist attractions in Kyoto, with a focus on temples, gardens, museums, and food:
Temples and Gardens: 1. Kinkaku-ji (Golden Pavilion): A Zen temple with top floors covered entirely in gold leaf, set beside a tranquil pond. 2. Fushimi Inari Taisha: A Shinto shrine famous for its thousands of vermilion torii gates leading up to Mount Inari. 3. Ginkaku-ji (Silver Pavilion): A Zen temple known for its beautiful sand garden and moss garden, despite not being covered in silver. 4. Arashiyama Bamboo Grove: A natural forest of bamboo in Arashiyama, providing a unique and picturesque walking experience. 5. Ryoan-ji: A Zen temple with one of Japan’s most famous rock gardens. 6. Tofuku-ji: A large Zen temple in southeastern Kyoto, renowned for its spectacular autumn colors and large garden complex.
Museums: 7. Kyoto International Manga Museum: A museum dedicated to the art of Japanese manga, with extensive collections and exhibitions.
Food Experience: 8. Nishiki Market: A vibrant and historic market with a variety of food-related shops and eateries offering local Japanese cuisine. 9. Pontocho Alley: A historic and atmospheric dining area along the Pontocho geographic feature, known for its traditional dining establishments. 10. Gion: Kyoto’s most famous geisha district, offering a glimpse into traditional Japanese entertainment and fine dining.
Now I will get the coordinates for each of these attractions and then retrieve the current weather forecast for each location for today.
run.required_action.submit_tool_outputs.tool_calls
[RequiredActionFunctionToolCall(id='call_QTNG67vENQeBEh7T6YtdbvnT', function=Function(arguments='{"place_name": "Kinkaku-ji", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_DS1QkJx7pc0Kc6DoVZnRbaz8', function=Function(arguments='{"place_name": "Fushimi Inari Taisha", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_0k6pBOHoLiyzDPPrA6yCAawf', function=Function(arguments='{"place_name": "Ginkaku-ji", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_6E86WQUO451Joepkc2ARj8Tj', function=Function(arguments='{"place_name": "Arashiyama Bamboo Grove", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_zPOYPakCUIidP4QIYswakgPy', function=Function(arguments='{"place_name": "Ryoan-ji", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_chrPG8vzLsFBOIGxE5BuqaTv', function=Function(arguments='{"place_name": "Tofuku-ji", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_gBpn2vamE4N4o0V94Fia2uUD', function=Function(arguments='{"place_name": "Kyoto International Manga Museum", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_YYsZcHLNoi4wWyldPDubn3XB', function=Function(arguments='{"place_name": "Nishiki Market", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_dQrnr5RwQmOgXjHTwp7jAIwH', function=Function(arguments='{"place_name": "Pontocho Alley", "city_name": "Kyoto"}', name='get_coordinates'), type='function'),
RequiredActionFunctionToolCall(id='call_mKU0DfFMwRZusd3GpoibUqRg', function=Function(arguments='{"place_name": "Gion", "city_name": "Kyoto"}', name='get_coordinates'), type='function')]
if run.status == 'requires_action':
= []
tool_outputs
for call in run.required_action.submit_tool_outputs.tool_calls:
= call.function.name
function_name = available_functions[function_name]
function = json.loads(call.function.arguments)
arguments = function(**arguments)
output "tool_call_id": call.id, "output": json.dumps(output)})
tool_outputs.append({
= client.beta.threads.runs.submit_tool_outputs(
run =thread.id,
thread_id=run.id,
run_id=tool_outputs
tool_outputs
)
while run.status == "queued" or run.status == "in_progress":
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id
)print(run.status)
5)
time.sleep(
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
requires_action
run.required_action.submit_tool_outputs.tool_calls
[RequiredActionFunctionToolCall(id='call_DI416D4K83nFoDykdtt4jD9a', function=Function(arguments='{"location": [35.03952925, 135.72953725309281], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_9hSwBOjwnYXpzCQ4AqyY125A', function=Function(arguments='{"location": [34.967519249999995, 135.77971008109822], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_0whxrUtiStO7xqd2Bo4sZTal', function=Function(arguments='{"location": [35.0268996, 135.7983713692728], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_jOce38WU7eHnAVA7zj7Ll8KC', function=Function(arguments='{"location": [35.018018, 135.67450037543992], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_n1Jlh9vhETxop6K2OTSS4fnR', function=Function(arguments='{"location": [35.033463049999995, 135.71808844984773], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_GbMdIh3yZi0ewITHZnEwUxtK', function=Function(arguments='{"location": [34.977170599999994, 135.77457537579082], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_WcDWRi92gOjEZLOWUgIsTGMS', function=Function(arguments='{"location": [35.0116959, 135.75917635140422], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_OP7zNm17Z3q9kXPzd6m1IMeG', function=Function(arguments='{"location": [35.005024399999996, 135.76556992963424], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_SnlZSP8csQFyhj3vEowe60tc', function=Function(arguments='{"location": [35.0080674, 135.7710399], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function'),
RequiredActionFunctionToolCall(id='call_5fwfwFRdNCUQ4uvBvyZz3asm', function=Function(arguments='{"location": [35.0046897, 135.77840296124248], "date": "2024-01-10", "use_coordinates": true}', name='get_weather'), type='function')]
if run.status == 'requires_action':
= []
tool_outputs
for call in run.required_action.submit_tool_outputs.tool_calls:
= call.function.name
function_name = available_functions[function_name]
function = json.loads(call.function.arguments)
arguments = function(**arguments)
output "tool_call_id": call.id, "output": json.dumps(output)})
tool_outputs.append({
= client.beta.threads.runs.submit_tool_outputs(
run =thread.id,
thread_id=run.id,
run_id=tool_outputs
tool_outputs
)
while run.status == "queued" or run.status == "in_progress":
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id
)print(run.status)
5)
time.sleep(
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
in_progress
requires_action
tool_outputs
[{'tool_call_id': 'call_DI416D4K83nFoDykdtt4jD9a',
'output': '"{\\n \\"location\\": [\\n 35.03952925,\\n 135.72953725309281\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 6.47,\\n \\"humidity\\": 78,\\n \\"wind_speed\\": 0.45,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_9hSwBOjwnYXpzCQ4AqyY125A',
'output': '"{\\n \\"location\\": [\\n 34.967519249999995,\\n 135.77971008109822\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.01,\\n \\"humidity\\": 78,\\n \\"wind_speed\\": 0.45,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_0whxrUtiStO7xqd2Bo4sZTal',
'output': '"{\\n \\"location\\": [\\n 35.0268996,\\n 135.7983713692728\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 5.98,\\n \\"humidity\\": 80,\\n \\"wind_speed\\": 0.45,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_jOce38WU7eHnAVA7zj7Ll8KC',
'output': '"{\\n \\"location\\": [\\n 35.018018,\\n 135.67450037543992\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.33,\\n \\"humidity\\": 78,\\n \\"wind_speed\\": 0.45,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_n1Jlh9vhETxop6K2OTSS4fnR',
'output': '"{\\n \\"location\\": [\\n 35.033463049999995,\\n 135.71808844984773\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 6.91,\\n \\"humidity\\": 78,\\n \\"wind_speed\\": 0.45,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_GbMdIh3yZi0ewITHZnEwUxtK',
'output': '"{\\n \\"location\\": [\\n 34.977170599999994,\\n 135.77457537579082\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.35,\\n \\"humidity\\": 77,\\n \\"wind_speed\\": 2.57,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_WcDWRi92gOjEZLOWUgIsTGMS',
'output': '"{\\n \\"location\\": [\\n 35.0116959,\\n 135.75917635140422\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.27,\\n \\"humidity\\": 77,\\n \\"wind_speed\\": 2.63,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_OP7zNm17Z3q9kXPzd6m1IMeG',
'output': '"{\\n \\"location\\": [\\n 35.005024399999996,\\n 135.76556992963424\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.27,\\n \\"humidity\\": 77,\\n \\"wind_speed\\": 2.57,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_SnlZSP8csQFyhj3vEowe60tc',
'output': '"{\\n \\"location\\": [\\n 35.0080674,\\n 135.7710399\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.27,\\n \\"humidity\\": 77,\\n \\"wind_speed\\": 2.57,\\n \\"description\\": \\"overcast clouds\\"\\n}"'},
{'tool_call_id': 'call_5fwfwFRdNCUQ4uvBvyZz3asm',
'output': '"{\\n \\"location\\": [\\n 35.0046897,\\n 135.77840296124248\\n ],\\n \\"date\\": \\"2024-01-10\\",\\n \\"unit\\": \\"Celsius\\",\\n \\"temperature\\": 7.21,\\n \\"humidity\\": 78,\\n \\"wind_speed\\": 0.45,\\n \\"description\\": \\"overcast clouds\\"\\n}"'}]
run.required_action.submit_tool_outputs.tool_calls
[RequiredActionFunctionToolCall(id='call_Y82SeDKWhkAEoENL2OQ0Cyib', function=Function(arguments='{"city_name":"Kyoto","attractions":["Kinkaku-ji","Ryoan-ji","Ginkaku-ji","Tofuku-ji","Fushimi Inari Taisha","Arashiyama Bamboo Grove","Kyoto International Manga Museum","Nishiki Market","Pontocho Alley","Gion"],"is_rainy":["blue","blue","blue","blue","blue","blue","blue","blue","blue","blue"]}', name='create_city_map'), type='function')]
if run.status == 'requires_action':
= []
tool_outputs
for call in run.required_action.submit_tool_outputs.tool_calls:
= call.function.name
function_name = available_functions[function_name]
function = json.loads(call.function.arguments)
arguments = function(**arguments)
output "tool_call_id": call.id, "output": json.dumps(output)})
tool_outputs.append({
= client.beta.threads.runs.submit_tool_outputs(
run =thread.id,
thread_id=run.id,
run_id=tool_outputs
tool_outputs
)
while run.status == "queued" or run.status == "in_progress":
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id
)print(run.status)
5)
time.sleep(
in_progress
in_progress
in_progress
completed
= client.beta.threads.messages.list(
messages =thread.id
thread_id
)
messages
SyncCursorPage[ThreadMessage](data=[ThreadMessage(id='msg_vWXC3uYvoYHB2cp4zD0ceEX0', assistant_id='asst_LacvLlXSc8oG1sM5eIk4CY4D', content=[MessageContentText(text=Text(annotations=[], value='I have organized your visit to the top attractions in Kyoto according to your preference for temples, gardens, museums, and food, and also considering an efficient route. All attractions have been color-coded with blue markers, as the weather is overcast without rain. \n\nHere is the map with the planned route:\n\n![Kyoto Map with Attractions](sandbox:/mnt/data/Kyoto.png)\n\nYou can visit these attractions in the following order to optimize your travel time:\n\n1. **Kinkaku-ji (Golden Pavilion)**\n2. **Ryoan-ji**\n3. **Ginkaku-ji (Silver Pavilion)**\n4. **Tofuku-ji**\n5. **Fushimi Inari Taisha**\n6. **Arashiyama Bamboo Grove**\n7. **Kyoto International Manga Museum**\n8. **Nishiki Market**\n9. **Pontocho Alley**\n10. **Gion**\n\nEnjoy your trip to Kyoto!'), type='text')], created_at=1704878973, file_ids=[], metadata={}, object='thread.message', role='assistant', run_id='run_mwlAc83GMWAwvaxohUbHDwz7', thread_id='thread_RLEZYpAQcB654HqzZipvzxtd'), ThreadMessage(id='msg_63EcysxnX7oQMMUOzjrdtlzi', assistant_id='asst_LacvLlXSc8oG1sM5eIk4CY4D', content=[MessageContentText(text=Text(annotations=[], value='The weather forecast for Kyoto today, January 10, 2024, indicates "overcast clouds" for all the attractions with temperatures ranging from approximately 5.98°C to 7.35°C. There is no rain predicted, thus the map will use blue markers for all the attractions. Below is the summary of the weather for each attraction:\n\n1. **Kinkaku-ji (Golden Pavilion):** 6.47°C, overcast clouds\n2. **Fushimi Inari Taisha:** 7.01°C, overcast clouds\n3. **Ginkaku-ji (Silver Pavilion):** 5.98°C, overcast clouds\n4. **Arashiyama Bamboo Grove:** 7.33°C, overcast clouds\n5. **Ryoan-ji:** 6.91°C, overcast clouds\n6. **Tofuku-ji:** 7.35°C, overcast clouds\n7. **Kyoto International Manga Museum:** 7.27°C, overcast clouds\n8. **Nishiki Market:** 7.27°C, overcast clouds\n9. **Pontocho Alley:** 7.27°C, overcast clouds\n10. **Gion:** 7.21°C, overcast clouds\n\nNow, I will use this information to create an organized sequence for visiting these attractions and plot a map with blue markers to represent the current weather conditions. Let\'s start by organizing the route for efficiency.'), type='text')], created_at=1704878867, file_ids=[], metadata={}, object='thread.message', role='assistant', run_id='run_mwlAc83GMWAwvaxohUbHDwz7', thread_id='thread_RLEZYpAQcB654HqzZipvzxtd'), ThreadMessage(id='msg_fLewruXXNrfKUrjUwCKlmcVQ', assistant_id='asst_LacvLlXSc8oG1sM5eIk4CY4D', content=[MessageContentText(text=Text(annotations=[], value="The current date in Kyoto is January 10, 2024.\n\nKyoto is a city that harmoniously blends centuries of history with modern culture. It was Japan's capital for over a millennium, leaving it with numerous temples, shrines, and traditional tea houses.\n\nHere are the top 10 tourist attractions in Kyoto, with a focus on temples, gardens, museums, and food:\n\n**Temples and Gardens:**\n1. **Kinkaku-ji (Golden Pavilion):** A Zen temple with top floors covered entirely in gold leaf, set beside a tranquil pond.\n2. **Fushimi Inari Taisha:** A Shinto shrine famous for its thousands of vermilion torii gates leading up to Mount Inari.\n3. **Ginkaku-ji (Silver Pavilion):** A Zen temple known for its beautiful sand garden and moss garden, despite not being covered in silver.\n4. **Arashiyama Bamboo Grove:** A natural forest of bamboo in Arashiyama, providing a unique and picturesque walking experience.\n5. **Ryoan-ji:** A Zen temple with one of Japan's most famous rock gardens.\n6. **Tofuku-ji:** A large Zen temple in southeastern Kyoto, renowned for its spectacular autumn colors and large garden complex.\n\n**Museums:**\n7. **Kyoto International Manga Museum:** A museum dedicated to the art of Japanese manga, with extensive collections and exhibitions.\n\n**Food Experience:**\n8. **Nishiki Market:** A vibrant and historic market with a variety of food-related shops and eateries offering local Japanese cuisine.\n9. **Pontocho Alley:** A historic and atmospheric dining area along the Pontocho geographic feature, known for its traditional dining establishments.\n10. **Gion:** Kyoto's most famous geisha district, offering a glimpse into traditional Japanese entertainment and fine dining.\n\nNow I will get the coordinates for each of these attractions and then retrieve the current weather forecast for each location for today."), type='text')], created_at=1704878735, file_ids=[], metadata={}, object='thread.message', role='assistant', run_id='run_mwlAc83GMWAwvaxohUbHDwz7', thread_id='thread_RLEZYpAQcB654HqzZipvzxtd'), ThreadMessage(id='msg_gYoCCX8t88p9aLECqTuJx2yz', assistant_id=None, content=[MessageContentText(text=Text(annotations=[], value='I am planning a visit to Kyoto today and would appreciate detailed information about the city.\n Please provide an overview of the location(20-30 words each), and list the top 10 tourist attractions. Additionally, could you include the current date and weather forecast for each attraction? Utilize the code interpreter to retrieve the current date in the city location.\n Kindly organize the attractions in a sequence that facilitates an efficient visiting route.\n \n Attraction focus preferences: temples, gardens, museums, food\n \n '), type='text')], created_at=1704878722, file_ids=[], metadata={}, object='thread.message', role='user', run_id=None, thread_id='thread_RLEZYpAQcB654HqzZipvzxtd')], object='list', first_id='msg_vWXC3uYvoYHB2cp4zD0ceEX0', last_id='msg_gYoCCX8t88p9aLECqTuJx2yz', has_more=False)
messages.model_dump()
{'data': [{'id': 'msg_vWXC3uYvoYHB2cp4zD0ceEX0',
'assistant_id': 'asst_LacvLlXSc8oG1sM5eIk4CY4D',
'content': [{'text': {'annotations': [],
'value': 'I have organized your visit to the top attractions in Kyoto according to your preference for temples, gardens, museums, and food, and also considering an efficient route. All attractions have been color-coded with blue markers, as the weather is overcast without rain. \n\nHere is the map with the planned route:\n\n![Kyoto Map with Attractions](sandbox:/mnt/data/Kyoto.png)\n\nYou can visit these attractions in the following order to optimize your travel time:\n\n1. **Kinkaku-ji (Golden Pavilion)**\n2. **Ryoan-ji**\n3. **Ginkaku-ji (Silver Pavilion)**\n4. **Tofuku-ji**\n5. **Fushimi Inari Taisha**\n6. **Arashiyama Bamboo Grove**\n7. **Kyoto International Manga Museum**\n8. **Nishiki Market**\n9. **Pontocho Alley**\n10. **Gion**\n\nEnjoy your trip to Kyoto!'},
'type': 'text'}],
'created_at': 1704878973,
'file_ids': [],
'metadata': {},
'object': 'thread.message',
'role': 'assistant',
'run_id': 'run_mwlAc83GMWAwvaxohUbHDwz7',
'thread_id': 'thread_RLEZYpAQcB654HqzZipvzxtd'},
{'id': 'msg_63EcysxnX7oQMMUOzjrdtlzi',
'assistant_id': 'asst_LacvLlXSc8oG1sM5eIk4CY4D',
'content': [{'text': {'annotations': [],
'value': 'The weather forecast for Kyoto today, January 10, 2024, indicates "overcast clouds" for all the attractions with temperatures ranging from approximately 5.98°C to 7.35°C. There is no rain predicted, thus the map will use blue markers for all the attractions. Below is the summary of the weather for each attraction:\n\n1. **Kinkaku-ji (Golden Pavilion):** 6.47°C, overcast clouds\n2. **Fushimi Inari Taisha:** 7.01°C, overcast clouds\n3. **Ginkaku-ji (Silver Pavilion):** 5.98°C, overcast clouds\n4. **Arashiyama Bamboo Grove:** 7.33°C, overcast clouds\n5. **Ryoan-ji:** 6.91°C, overcast clouds\n6. **Tofuku-ji:** 7.35°C, overcast clouds\n7. **Kyoto International Manga Museum:** 7.27°C, overcast clouds\n8. **Nishiki Market:** 7.27°C, overcast clouds\n9. **Pontocho Alley:** 7.27°C, overcast clouds\n10. **Gion:** 7.21°C, overcast clouds\n\nNow, I will use this information to create an organized sequence for visiting these attractions and plot a map with blue markers to represent the current weather conditions. Let\'s start by organizing the route for efficiency.'},
'type': 'text'}],
'created_at': 1704878867,
'file_ids': [],
'metadata': {},
'object': 'thread.message',
'role': 'assistant',
'run_id': 'run_mwlAc83GMWAwvaxohUbHDwz7',
'thread_id': 'thread_RLEZYpAQcB654HqzZipvzxtd'},
{'id': 'msg_fLewruXXNrfKUrjUwCKlmcVQ',
'assistant_id': 'asst_LacvLlXSc8oG1sM5eIk4CY4D',
'content': [{'text': {'annotations': [],
'value': "The current date in Kyoto is January 10, 2024.\n\nKyoto is a city that harmoniously blends centuries of history with modern culture. It was Japan's capital for over a millennium, leaving it with numerous temples, shrines, and traditional tea houses.\n\nHere are the top 10 tourist attractions in Kyoto, with a focus on temples, gardens, museums, and food:\n\n**Temples and Gardens:**\n1. **Kinkaku-ji (Golden Pavilion):** A Zen temple with top floors covered entirely in gold leaf, set beside a tranquil pond.\n2. **Fushimi Inari Taisha:** A Shinto shrine famous for its thousands of vermilion torii gates leading up to Mount Inari.\n3. **Ginkaku-ji (Silver Pavilion):** A Zen temple known for its beautiful sand garden and moss garden, despite not being covered in silver.\n4. **Arashiyama Bamboo Grove:** A natural forest of bamboo in Arashiyama, providing a unique and picturesque walking experience.\n5. **Ryoan-ji:** A Zen temple with one of Japan's most famous rock gardens.\n6. **Tofuku-ji:** A large Zen temple in southeastern Kyoto, renowned for its spectacular autumn colors and large garden complex.\n\n**Museums:**\n7. **Kyoto International Manga Museum:** A museum dedicated to the art of Japanese manga, with extensive collections and exhibitions.\n\n**Food Experience:**\n8. **Nishiki Market:** A vibrant and historic market with a variety of food-related shops and eateries offering local Japanese cuisine.\n9. **Pontocho Alley:** A historic and atmospheric dining area along the Pontocho geographic feature, known for its traditional dining establishments.\n10. **Gion:** Kyoto's most famous geisha district, offering a glimpse into traditional Japanese entertainment and fine dining.\n\nNow I will get the coordinates for each of these attractions and then retrieve the current weather forecast for each location for today."},
'type': 'text'}],
'created_at': 1704878735,
'file_ids': [],
'metadata': {},
'object': 'thread.message',
'role': 'assistant',
'run_id': 'run_mwlAc83GMWAwvaxohUbHDwz7',
'thread_id': 'thread_RLEZYpAQcB654HqzZipvzxtd'},
{'id': 'msg_gYoCCX8t88p9aLECqTuJx2yz',
'assistant_id': None,
'content': [{'text': {'annotations': [],
'value': 'I am planning a visit to Kyoto today and would appreciate detailed information about the city.\n Please provide an overview of the location(20-30 words each), and list the top 10 tourist attractions. Additionally, could you include the current date and weather forecast for each attraction? Utilize the code interpreter to retrieve the current date in the city location.\n Kindly organize the attractions in a sequence that facilitates an efficient visiting route.\n \n Attraction focus preferences: temples, gardens, museums, food\n \n '},
'type': 'text'}],
'created_at': 1704878722,
'file_ids': [],
'metadata': {},
'object': 'thread.message',
'role': 'user',
'run_id': None,
'thread_id': 'thread_RLEZYpAQcB654HqzZipvzxtd'}],
'object': 'list',
'first_id': 'msg_vWXC3uYvoYHB2cp4zD0ceEX0',
'last_id': 'msg_gYoCCX8t88p9aLECqTuJx2yz',
'has_more': False}
0].content[0].text.value.replace("sandbox:/mnt/data/",""))) display(Markdown(messages.data[
I have organized your visit to the top attractions in Kyoto according to your preference for temples, gardens, museums, and food, and also considering an efficient route. All attractions have been color-coded with blue markers, as the weather is overcast without rain.
Here is the map with the planned route:
You can visit these attractions in the following order to optimize your travel time:
- Kinkaku-ji (Golden Pavilion)
- Ryoan-ji
- Ginkaku-ji (Silver Pavilion)
- Tofuku-ji
- Fushimi Inari Taisha
- Arashiyama Bamboo Grove
- Kyoto International Manga Museum
- Nishiki Market
- Pontocho Alley
- Gion
Enjoy your trip to Kyoto!
Message 2: Asking for a word document with all the details
= f"{city_name}.png" city_map
= client.files.create(
city_file file=open(city_map, "rb"),
="assistants"
purpose )
Create a Document Creator Assistant
A thread can be passed to many assistants. Here we are creating a new assistant that focuses on exceling the document creation.
= client.beta.assistants.create(
assistant_doc ="Travel Guide Word Document Creater Assistant",
name="""You are a helpful assistant that creates word document with useful information about the city,
instructions explaining each attractions, arranging in easy order to travel, include weather details, map png file .""",
=[{"type":"code_interpreter"}],
tools="gpt-4-1106-preview",
model=[city_file.id]
file_ids
)
# new message
= client.beta.threads.messages.create(
message =thread.id,
thread_id="user",
role=f"Create a word document , with the png file {city_file.id} and include all the helpful details., add information about each attractions (20-30 words each)",
content=[city_file.id]
file_ids )
= client.beta.threads.runs.create(
run =thread.id,
thread_id=assistant_doc.id,
assistant_id )
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id )
while run.status == "queued" or run.status == "in_progress":
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id
)print(run.status)
60)
time.sleep(
in_progress
in_progress
completed
= client.beta.threads.messages.list(
messages =thread.id
thread_id )
= messages.data[0].content[0].text.annotations[0].file_path.file_id file_id
def write_file_to_temp_dir(file_id, output_path):
= openai.files.content(file_id)
file_data = file_data.read()
file_data_bytes with open(output_path, "wb") as file:
file.write(file_data_bytes)
f'{city_name}.docx') write_file_to_temp_dir(file_id,
Display the Travel Guide
A word document is created with the following details
# new message
= client.beta.threads.messages.create(
message =thread.id,
thread_id="user",
role="List all the files in your sandbox"
content )
= client.beta.threads.runs.create(
run =thread.id,
thread_id=assistant.id,
assistant_id
)
while run.status == "queued" or run.status == "in_progress":
= client.beta.threads.runs.retrieve(
run =thread.id,
thread_id=run.id
run_id
)print(run.status)
5) time.sleep(
in_progress
in_progress
completed
= client.beta.threads.messages.list(
messages =thread.id
thread_id
)
for message in messages.data:
0].text.value))
display(Markdown(message.content[print("*" * 80)
break
Here are the files currently in the sandbox:
uploaded_file.png
file-wMpsZcIr84ClEkkCXMAkDsVp
(this is the original uploaded file before renaming)Kyoto_Travel_Guide.docx
Kyoto_Travel_Guide_Descriptions.docx
Please let me know if you would like to access any of these files or if you need further assistance.
********************************************************************************
Delete Assistants : Caution
from openai import OpenAI
= OpenAI()
client
= client.beta.assistants.list(
my_assistants ="desc",
order="50",
limit
)print(my_assistants.data)
[Assistant(id='asst_fdcUT8iMJ4p8FY4bqCYHHjje', created_at=1704877182, description=None, file_ids=['file-wMpsZcIr84ClEkkCXMAkDsVp'], instructions='You are a helpful assistant that creates word document with useful information about the city,\n explaining each attractions, arranging in easy order to travel, include weather details, map png file .', metadata={}, model='gpt-4-1106-preview', name='Travel Guide Word Document Creater Assistant', object='assistant', tools=[ToolCodeInterpreter(type='code_interpreter')]), Assistant(id='asst_ldiqo3CshePFP1Gasfqbe41b', created_at=1704876788, description=None, file_ids=['file-wMpsZcIr84ClEkkCXMAkDsVp'], instructions='You are a helpful assistant that creates word document with useful information about the city,\n explaining each attractions, arranging in easy order to travel, include weather details, map png file .', metadata={}, model='gpt-4-1106-preview', name='Travel Guide Word Document Creater Assistant', object='assistant', tools=[ToolCodeInterpreter(type='code_interpreter')]), Assistant(id='asst_kvnGAfgTPJXiDCfKo0mJWPih', created_at=1704876106, description=None, file_ids=[], instructions='You are a personal travel assistant.You use available functions to help your user plan their trip.\nCreate inputs to the functions carefully. If you could not find the available functions,\nyou can use your own knowledge to help your user.Sometimes you have to use parallel functions to get the desired output\n\nFind the exact date they are planning to visit and use that information for getting current weather.\n\nTo do plotting, we need coordinates, current weather and tourist attractions.\n\nso for plotting maps, first get coordinates of each tourist attractions that you suggest, then get current weather and then do the plotting of map.mro\n\nWe are color coding the markers based on weather condition. If it is rainy, we use red color, otherwise blue. This is helpful for the user to plan their trip accordingly.\n\n', metadata={}, model='gpt-4-1106-preview', name='Travel Assistant', object='assistant', tools=[ToolFunction(function=FunctionDefinition(name='get_coordinates', description='Fetches coordinates of a place using Nominatim API.', parameters={'type': 'object', 'properties': {'place_name': {'type': 'string', 'description': 'The name of the specific place.'}, 'city_name': {'type': 'string', 'description': 'The name of the city where the place is located.'}}, 'required': ['place_name', 'city_name']}), type='function'), ToolFunction(function=FunctionDefinition(name='create_city_map', description='Creates a map with markers for specified attractions in a city.', parameters={'type': 'object', 'properties': {'city_name': {'type': 'string', 'description': 'The name of the city.'}, 'attractions': {'type': 'array', 'items': {'type': 'string'}, 'description': 'A list of attraction names in the city.'}, 'is_rainy': {'type': 'array', 'items': {'type': 'string'}, 'description': 'A list of strings indicating whether it is rainy for each attraction.'}}, 'required': ['city_name', 'attractions', 'is_rainy']}), type='function'), ToolFunction(function=FunctionDefinition(name='get_weather', description='Get weather for a given location and date using OpenWeather API.', parameters={'type': 'object', 'properties': {'location': {'oneOf': [{'type': 'string', 'description': 'The location name for which weather information is required.'}, {'type': 'array', 'items': {'type': 'number'}, 'minItems': 2, 'maxItems': 2, 'description': 'The coordinates (latitude, longitude) for which weather information is required.'}]}, 'date': {'type': 'string', 'description': 'The date for the weather forecast in YYYY-MM-DD format.'}, 'unit': {'type': 'string', 'enum': ['metric', 'imperial'], 'description': 'The unit for temperature (metric or imperial).'}, 'use_coordinates': {'type': 'boolean', 'description': 'Flag to use coordinates instead of location name.'}}, 'required': ['location', 'date', 'use_coordinates']}), type='function'), ToolCodeInterpreter(type='code_interpreter')])]
for assistant in my_assistants.data:
= client.beta.assistants.delete(assistant.id)
response print(response)
AssistantDeleted(id='asst_fdcUT8iMJ4p8FY4bqCYHHjje', deleted=True, object='assistant.deleted')
AssistantDeleted(id='asst_ldiqo3CshePFP1Gasfqbe41b', deleted=True, object='assistant.deleted')
AssistantDeleted(id='asst_kvnGAfgTPJXiDCfKo0mJWPih', deleted=True, object='assistant.deleted')