Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 2.14 KB

20240628165703.md

File metadata and controls

45 lines (33 loc) · 2.14 KB

Using marvin ai to extract geo locations

I just used Marvin AI to get geo locations from unstructured location strings 💡 🎉

I like the combination of using a Pydantic 🐍 base model + fn decorator + type hints + a prompt in a function docstring - nice and clean. 😍 📈

import marvin
from pydantic import BaseModel, Field


class Location(BaseModel):
    fuzzy_input_name: str = Field(..., description="The original input string")
    location_string_extracted: str = Field(..., description="The extracted location string")
    latitude: float = Field(..., description="Latitude of the location")
    longitude: float = Field(..., description="Longitude of the location")


@marvin.fn
def get_locations(location_strings: list[str]) -> list[Location]:
    """Estimate geo locations from fuzzy input strings."""


if __name__ == "__main__":
    location_strings = [
        "Medium Road Block 789 Pine St, San Francisco 2024-06-28 13:03:00",
        "High Event Champs-Élysées, Paris 2024-06-28 14:00:00",
        "Medium Festival Barcelona 2024-06-28 15:00:00",
        "Low Protest 1234 Museumplein, Amsterdam 2024-06-28 16:00:00",
        "Medium Gathering Bondi Beach, Sydney 2024-06-28 18:00:00"
    ]
    locations = get_locations(location_strings)

    for location in locations:
        print(location)

    # output:
    # fuzzy_input_name='Medium Road Block 789 Pine St, San Francisco 2024-06-28 13:03:00' location_string_extracted='789 Pine St, San Francisco' latitude=37.7903 longitude=-122.404
    # fuzzy_input_name='High Event Champs-Élysées, Paris 2024-06-28 14:00:00' location_string_extracted='Champs-Élysées, Paris' latitude=48.8566 longitude=2.3522
    # fuzzy_input_name='Medium Festival Barcelona 2024-06-28 15:00:00' location_string_extracted='Barcelona' latitude=41.3851 longitude=2.1734
    # fuzzy_input_name='Low Protest 1234 Museumplein, Amsterdam 2024-06-28 16:00:00' location_string_extracted='Museumplein, Amsterdam' latitude=52.3567 longitude=4.8791
    # fuzzy_input_name='Medium Gathering Bondi Beach, Sydney 2024-06-28 18:00:00' location_string_extracted='Bondi Beach, Sydney' latitude=-33.8908 longitude=151.2743

#marvinai