-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ba2d37
commit f556f93
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Using marvin ai to extract geo locations | ||
|
||
I just used Marvin AI to get geo locations based on a fuzzy location string 💡🎉 | ||
|
||
I like the combination of using a Pydantic 🐍 base model + typing + a prompt in the docstring of a function, feels really 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. | ||
Args: | ||
location_strings (list[str]): List of location strings. | ||
Returns: | ||
list[Location]: List of Location objects with extracted details and geo coordinates. | ||
Format for each input string: | ||
<type> <priority> <location> <description> <city> <number> | ||
Example components: | ||
<priority> : Priority level (e.g., 'High', 'Medium', 'Low'). | ||
<description> : Brief incident/service description (e.g., 'Accident', 'Service Call'). | ||
<location> : Could contain street name, postal code, and/or city name. | ||
<date + time> : Indicates the time of the incident/service. | ||
Note: | ||
- Street names or postal codes are the most specific identifiers. | ||
- Use the city name if no street name or postal code is found. | ||
""" | ||
if __name__ == "__main__": | ||
location_strings = [ | ||
"High Accident 123 Main St, New York 2024-06-28 12:59:00", | ||
"Medium Service Call Los Angeles 2024-06-28 13:00:00", | ||
"Low Fire Incident 456 Elm St, 60614, Chicago 2024-06-28 13:01:00", | ||
"High Medical Emergency Uptown, Boston 2024-06-28 13:02:00", | ||
"Medium Road Block 789 Pine St, San Francisco 2024-06-28 13:03:00", | ||
] | ||
locations = get_locations(location_strings) | ||
for location in locations: | ||
print(location) | ||
# Output: | ||
# fuzzy_input_name='High Accident 123 Main St, New York 2024-06-28 12:59:00' location_string_extracted='123 Main St, New York' latitude=40.7127753 longitude=-74.0059728 | ||
# fuzzy_input_name='Medium Service Call Los Angeles 2024-06-28 13:00:00' location_string_extracted='Los Angeles' latitude=34.0522342 longitude=-118.2436849 | ||
# fuzzy_input_name='Low Fire Incident 456 Elm St, 60614, Chicago 2024-06-28 13:01:00' location_string_extracted='456 Elm St, 60614, Chicago' latitude=41.8493 longitude=-87.648 | ||
# fuzzy_input_name='High Medical Emergency Uptown, Boston 2024-06-28 13:02:00' location_string_extracted='Uptown, Boston' latitude=42.3600825 longitude=-71.0588801 | ||
# 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.7749295 longitude=-122.4194155 | ||
``` | ||
|
||
#marvinai |