I’m planning my family’s car road trip in Europe, and it struck me that a lot of boring planning and research can be automated with the help of LLMs (and the Wolfram Language, of course!). Here are some early ideas. With just a few lines of code, I already feel the planning power that I never had before :), and it feels that I’m just scratching the surface.
Let’s start with plotting a course from A to B:
ClearAll[drawDrivingDirections,goodLocationQ,goodLocations];drawDrivingDirections[locations_,labels:{__String}]:=Module[{dist=TravelDistance[locations,TravelMethod->"Driving"],time=TravelTime[locations,TravelMethod->"Driving"],distDirect=TravelDistance[{locations[[1]],locations[[-1]]},TravelMethod->"Driving"],timeDirect=TravelTime[{locations[[1]],locations[[-1]]},TravelMethod->"Driving"],directions=TravelDirections[locations,TravelMethod->"Driving"]},If[Length[locations]!=Length[labels],Return[Failure["IncorrectArguments",<|"MessageTemplate"->"locations has length `1` but labels has length `2`","MessageParameters"->Length/@{locations,labels}|>]]];GeoGraphics[{Style[Line[directions],Thick,Red],GeoMarker/@locations,MapThread[Text[#1,#2,{-1,0},Background->LightPink]&,{labels,locations}]},PlotLabel->Style[StringForm["``\n`` [``]\nvs. direct: +`` [``]",StringRiffle[labels," "],time,Round@dist,time-timeDirect,Round[dist-distDirect]],FontWeight->Bold,FontSize->16],ImageSize->Full]];
For example, let’s plot directions from Geneva to Salzburg:
In[]:=
drawDrivingDirections,
Out[]=
I already know the distance and the rough time this trip would take me; but it goes through Zurich and Munich, the cities that I have already visited before. Can I find a more interesting route? Sure, we just need to ask ChatGPT for help, asking it to go through smaller towns and villages, and potentially avoiding certain cities:
DatasetFromList[header_,rows_]:=Dataset[AssociationThread[header,#]&/@rows]
In[]:=
ClearAll[llmSuggestions]llmSuggestions=LLMFunction["I am planning to car roadtrip. I will drive from `1` to `2`. `3`. \nPlease suggest some interesting points of interest"<>", such as small villages and towns, lakes, etc. along the way. I'm OK with small detours (no longer than 30 minutes)."<>"Please provide the answer in the following format. Do not include any preamble, just output the information requested. For each point, including "<>"the starting point and the end point, output: The location name, e.g., a city / lake / point of interest. Then on a new line, "<>"a paragraph of one or two sentences describing why the stop should be taken: what is interesting / remarkable about it, followed by an empty line."];
In[]:=
ClearAll[llmDirections]llmDirections[from_,to_,considerations_]:=Module[{response=llmSuggestions[from,to,considerations],data,entities},data=(StringTrim/@StringSplit[#,"\n"])&/@StringSplit[response,"\n\n"];entities=Interpreter["Entity"]/@data[[All,1]];DatasetFromList[{"Name","Location","Description"},MapThread[List,{data[[All,1]],entities,data[[All,2]]}]]]
In[]:=
llmDirections["Geneva","Salzburg","Avoid going through Bern, Zurich, and Munich, opting for smaller towns and villages instead"]
Out[]=
Let’s adjust our drawing function, accounting for Locations that might not resolve properly:
drawDrivingDirections[points:{__Entity}]:=drawDrivingDirections[points,EntityValue[#,"Name"]&/@points];goodLocationQ[loc_]:=Not[FailureQ[loc]||MissingQ[EntityValue[loc,"Latitude"]]];goodLocations[data_Dataset]:=Select[data,goodLocationQ[#Location]&];drawDrivingDirections[data_Dataset]:=drawDrivingDirections[Normal@goodLocations[data][All,"Location"]];
In[]:=
drawDrivingDirections[%467]
Hm, that’s an interesting suggestion, but it does a pretty long detour in Italy. Looking at the map, I have new idea: don’t leave Switzerland, visit Liechtenstein, and possibly Innsbruck.
In[]:=
llmDirections["Geneva","Salzburg","The path should go through Switzerland, than visit Liechtenstein, and go through Innsbruck"]
Out[]=
In[]:=
drawDrivingDirections[%]
Out[]=
That’s already better; I will play with the path between Montreux and Liechtenstein some more to get more stops there, but overall the path from Liechtenstein to Salzburg is already more interesting and avoid Munich. Let’s do a final touch to format a time and distance table:
Ok, let’s see what are our options from Montreux to Liechtenstein:
That’s interesting, but it goes up north and extends the travel time considerably. What about a path in the south, via Interlaken?
Well, this doesn’t work because Interlaken was not resolved properly:
We need a different one:
We can avoid going to Andermatt and find something else interesting along the day. I can go on and on. The ability to generate ideas, and quickly visualize the driving direction is quite addictive!
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Planning a road trip with AI: LLM functions and ChatGPT for driving route design
by Victor Kryukov
Wolfram Community, STAFF PICKS, May 2, 2024
https://community.wolfram.com/groups/-/m/t/3168968
by Victor Kryukov
Wolfram Community, STAFF PICKS, May 2, 2024
https://community.wolfram.com/groups/-/m/t/3168968