This code is taking two country names and returns the distance between the related capital cities. The challenge was to make sure the post request to ollama was returning consistently a proper json - meeting the defined schema, actually putting a loop to retry if not.
This is a very simple tinkering , that fits into the use of functions to compose calls to ollama (llms).
main.py italy denmark
Retrieved city info for italy: {'capital_city': 'Rome', 'latitude': 41.9028, 'longitude': 12.4964}
Retrieved city info for denmark: {'capital_city': 'Copenhagen', 'latitude': 55.6761, 'longitude': 12.5683}
City 1: {'capital_city': 'Rome', 'latitude': 41.9028, 'longitude': 12.4964}
City 2: {'capital_city': 'Copenhagen', 'latitude': 55.6761, 'longitude': 12.5683}
The distance between Rome and Copenhagen is 1530 km
Or using the docker image to run it almost anywhere.
brew install ollama
ollama serve
Now ollama runs on localhost:11434 , you can design any client to call on it
ollama pull mistral
pip install -r requirements.txt
Use the debug launch.json : you will get the invite to enter the first country, and the second.
Examples:
python main.py france italy
python main.py malawi people-republic-of-china
The code will not recognize capitals and states. For example, run the following:
python main.py britanny corsica
python main.py tahiti nouvelle-calédonie
Have fun !!!
Thank you for the guidance!
Matt Williams https://www.youtube.com/watch?v=RXDWkiuXtG0