AI agents
AI Agents for Geospatial Analysis and Visualization
Uncomment the following line to install leafmap if needed.
Installation¶
In [ ]:
Copied!
# %pip install "geoai[agents]"
# %pip install "geoai[agents]"
Import libraries¶
In [ ]:
Copied!
from geoai import Map
from geoai.agents import (
GeoAgent,
create_ollama_model,
create_openai_model,
create_anthropic_model,
create_bedrock_model,
)
from geoai import Map
from geoai.agents import (
GeoAgent,
create_ollama_model,
create_openai_model,
create_anthropic_model,
create_bedrock_model,
)
Create a model¶
You can create a model with the following functions:
create_ollama_model: Create a model using Ollama. You will need to install Ollama) separately and pull the model you want to use, such asllama3.1.create_openai_model: Create a model using OpenAI. You will need an OpenAI API key. Set it in theOPENAI_API_KEYenvironment variable.create_anthropic_model: Create a model using Anthropic. You will need an Anthropic API key. Set it in theANTHROPIC_API_KEYenvironment variable.create_bedrock_model: Create a model using Bedrock. You will need an AWS account and theAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYenvironment variables set.
In [ ]:
Copied!
model = create_ollama_model(model="llama3.1")
model = create_ollama_model(model="llama3.1")
Create an agent with default map¶
In [ ]:
Copied!
agent = GeoAgent(model=model)
agent = GeoAgent(model=model)
In [ ]:
Copied!
agent.model
agent.model
In [ ]:
Copied!
agent.session.m
agent.session.m
In [ ]:
Copied!
agent.ask("Add OpenTopoMap basemap")
agent.ask("Add OpenTopoMap basemap")
In [ ]:
Copied!
agent.ask("Fly to Chicago")
agent.ask("Fly to Chicago")
In [ ]:
Copied!
agent.model
agent.model
Create an agent with a custom map¶
In [ ]:
Copied!
custom_map = Map(center=[-83.92, 35.96], zoom=11, projection="globe")
custom_map
custom_map = Map(center=[-83.92, 35.96], zoom=11, projection="globe")
custom_map
In [ ]:
Copied!
agent = GeoAgent(model=model, map_instance=custom_map)
agent.ask("Add basemap Esri.WorldImagery")
agent = GeoAgent(model=model, map_instance=custom_map)
agent.ask("Add basemap Esri.WorldImagery")
In [ ]:
Copied!
agent.ask("Remove Esri.WorldImagery")
agent.ask("Remove Esri.WorldImagery")
Show the agent UI¶
In [ ]:
Copied!
m = Map(center=[-100, 40], zoom=3, projection="globe")
agent = GeoAgent(model=model, map_instance=m)
agent.show_ui()
m = Map(center=[-100, 40], zoom=3, projection="globe")
agent = GeoAgent(model=model, map_instance=m)
agent.show_ui()