import json
import openai
import requests

from llmcam.oas_to_requests import generate_request, toolbox_schema
from llmcam.fn_to_fc import *
! [ -e "openapi_rata.json" ] || wget https://rata.digitraffic.fi/swagger/openapi.json -O "openapi_rata.json"
messages = form_msgs([
    ("system", "You are a helpful system administrator. Use the supplied tools to help the user."),
    ("user", "Hello, what can you provide me about railway and train information?"),
])
complete(messages, tool_schema)
print_msgs(messages)
>> System:
You are a helpful system administrator. Use the supplied tools to help the user.
>> User:
Hello, what can you provide me about railway and train information?
>> Assistant:
I can provide you with a variety of railway and train-related information, including:  1. **Train
and Passenger Information:**    - Currently active passenger information messages.    - Messages
updated after a specific date.    - Real-time updates and locations for trains.    - GTFS data for
passenger and all trains.  2. **Trains and Routes:**    - Information about specific trains by their
number and departure date.    - Recent trains that are newer than a specified version.    - Trains
running on a specific departure date.    - Routesets and composition of trains.  3. **Stations:**
- List of stations and their geo-locations.    - Trains traveling through or between specific
stations.  4. **Train Operations:**    - Train tracking messages by train number or station.    -
Notices related to traffic restrictions and track work.  5. **Metadata and Categories:**    - List
of train types and categories.    - Detailed cause and third cause category codes.    - Operators
information.    - Time table periods.  Please let me know what specific information you would like,
and I'll be happy to assist you!
user_messages = [
    "I want to know the train schedule to Joensuu",
    "I want nearest departure information from Helsinki",
    "Where is that train now?",
    "How about its passenger information?",
    "Is there anything to pay attention to about the traffic situation?",
]
for msg in user_messages:
    messages.append(form_msg("user", msg))
    complete(messages, tool_schema)

print_msgs(messages)
>> System:
You are a helpful system administrator. Use the supplied tools to help the user.
>> User:
Hello, what can you provide me about railway and train information?
>> Assistant:
I can provide you with a variety of railway and train-related information, including:  1. **Train
and Passenger Information:**    - Currently active passenger information messages.    - Messages
updated after a specific date.    - Real-time updates and locations for trains.    - GTFS data for
passenger and all trains.  2. **Trains and Routes:**    - Information about specific trains by their
number and departure date.    - Recent trains that are newer than a specified version.    - Trains
running on a specific departure date.    - Routesets and composition of trains.  3. **Stations:**
- List of stations and their geo-locations.    - Trains traveling through or between specific
stations.  4. **Train Operations:**    - Train tracking messages by train number or station.    -
Notices related to traffic restrictions and track work.  5. **Metadata and Categories:**    - List
of train types and categories.    - Detailed cause and third cause category codes.    - Operators
information.    - Time table periods.  Please let me know what specific information you would like,
and I'll be happy to assist you!
>> User:
I want to know the train schedule to Joensuu
>> Assistant:
To provide you with the train schedule to Joensuu, please let me know your departure station and the
date of travel. This will help in fetching the most relevant train schedule information for you.
>> User:
I want nearest departure information from Helsinki
>> Assistant:
Here are the upcoming train departures from Helsinki to Joensuu:  ### Train 5 (IC - Long-distance) -
**Departure from Helsinki (Track 7):** November 16, 2024, at 14:19 - **Arrival at Joensuu (Track
1):** November 16, 2024, at 17:51  ### Train 11 (IC - Long-distance) - **Departure from Helsinki
(Track 9):** November 16, 2024, at 16:25 - **Arrival at Joensuu (Track 1):** November 16, 2024, at
21:15  ### Train 1 (IC - Long-distance) - **Departure from Helsinki (Track 10):** November 17, 2024,
at 04:54 - **Arrival at Joensuu (Track 1):** November 17, 2024, at 09:40  ### Train 3 (IC - Long-
distance) - **Departure from Helsinki (Track 9):** November 17, 2024, at 08:19 - **Arrival at
Joensuu (Track 1):** November 17, 2024, at 12:51  These trains are operated by VR and are
categorized as long-distance InterCity (IC) services. Please check with the operator for any changes
or updates closer to your travel date.
>> User:
Where is that train now?
>> Assistant:
Here's the current status of the trains to Joensuu:  - **Train 3** is currently running:   -
**Location:** Latitude 61.276187, Longitude 29.01863   - **Speed:** 134 km/h   - **Accuracy:** 371
meters  The other trains (Train 5, Train 11, and Train 1) currently do not have location data
available. They might not have started their journey yet or might be inactive at the moment.
>> User:
How about its passenger information?
>> Assistant:
Currently, there are no active passenger information messages available for trains 5, 11, 1, and 3
heading to Joensuu. Everything might be running smoothly without any significant updates or alerts
for these trains. Let me know if you need any other information!
>> User:
Is there anything to pay attention to about the traffic situation?
>> Assistant:
There are several traffic restrictions currently reported, but I don't have specific details on each
one. If you want to know more about a specific restriction, I can provide detailed information.
Generally, it's a good idea to be aware of any potential restrictions or planned disruptions when
traveling by train, especially over long distances.  If you need more specific details on any
traffic restrictions, please let me know, and I can delve into the individual notifications for you!