moved layer selection into style agent

pull/137/head
shanergi 2023-11-20 15:04:15 -05:00
rodzic d62ff8558b
commit 0bce885309
6 zmienionych plików z 47 dodań i 45 usunięć

Wyświetl plik

@ -87,9 +87,28 @@ set_visibility = {
}, },
} }
select_layer_name = {
"type": "function",
"function": {
"name": "select_layer_name",
"description": "Gets a layer name from the text of a given task related to selecting layers on a map.",
"parameters": {
"type": "object",
"properties": {
"layer_name": {
"type": "string",
"description": "The name of the layer.",
},
},
"required": ["layer_name"],
},
},
}
style_function_descriptions = [ style_function_descriptions = [
set_color, set_color,
set_opacity, set_opacity,
set_width, set_width,
set_visibility, set_visibility,
select_layer_name,
] ]

Wyświetl plik

@ -19,7 +19,7 @@ class MarshallAgent:
"properties": { "properties": {
"agent_name": { "agent_name": {
"type": "string", "type": "string",
"description": "The name of the agent to choose. One of 'NavigationAgent', 'StyleAgent', 'MapInfoAgent', 'DatabaseAgent'.", "description": "The name of the agent to choose. One of 'NavigationAgent', 'StyleAgent', 'DatabaseAgent'.",
}, },
}, },
"required": ["agent_name"], "required": ["agent_name"],
@ -32,16 +32,12 @@ class MarshallAgent:
For tasks related to adding layers and other geospatial data to the map, use the DatabaseAgent. For tasks related to adding layers and other geospatial data to the map, use the DatabaseAgent.
Examples include 'add buildings to the map', 'show industrial buildings', and 'get landuse polygons within this extent'. Examples include 'add buildings to the map', 'show industrial buildings', and 'get landuse polygons within this extent'.
For tasks that ask to change the style of a map, such as opacity, color, or line width, you will For tasks that change the style of a map, such as selecting a layer to style, changing the opacity, color,
use the StyleAgent. Examples StyleAgent prompts include 'change color to green', 'opacity 45%' or line width of a layer, you will use the StyleAgent. Example StyleAgent prompts include 'change color to green',
and 'line width 4'. 'select the buildings layer', 'opacity 45%', 'select water', and 'line width 4'.
For tasks related to getting the name of a layer, you will use the MapInfoAgent. For tasks to navigate the map, such as panning, zooming, or flying to a location, you will use the NavigationAgent.
Example MapInfoAgent prompts include 'select the water layer' and 'select buildings'. Example NavigationAgent prompts include 'go to Paris', 'show me the Statue of Liberty', and 'fly to Houston, Texas'
For tasks that ask where something is, or task you with navigate the map, such as panning, zooming,
or flying to a location, you will use the NavigationAgent. Example NavigationAgent prompts include
'go to Paris', 'show me the Statue of Liberty', and 'where is Houston, Texas?'
If you can't find the appropriate agent, say that you didn't understand and ask If you can't find the appropriate agent, say that you didn't understand and ask
for a more specific description of the task.""" for a more specific description of the task."""

Wyświetl plik

@ -19,6 +19,9 @@ class StyleAgent:
def set_visibility(self, layer_name, visibility): def set_visibility(self, layer_name, visibility):
return {"name": "set_visibility", "layer_name": layer_name, "visibility": visibility} return {"name": "set_visibility", "layer_name": layer_name, "visibility": visibility}
def select_layer_name(self, layer_name):
return {"name": "select_layer_name", "layer_name": layer_name}
def __init__(self, client, model_version): def __init__(self, client, model_version):
self.client = client self.client = client
self.model_version = model_version self.model_version = model_version
@ -40,15 +43,16 @@ class StyleAgent:
"set_opacity": self.set_opacity, "set_opacity": self.set_opacity,
"set_width": self.set_width, "set_width": self.set_width,
"set_visibility": self.set_visibility, "set_visibility": self.set_visibility,
"select_layer_name": self.select_layer_name,
} }
def listen(self, message): def listen(self, message, layer_names):
"""Listen to a message from the user.""" """Listen to a message from the user."""
logging.info(f"In StyleAgent...message is: {message}") logging.info(f"In StyleAgent...message is: {message}")
final_message = f"""Available layer names are {layer_names}. Use the apprpriate layer name referenced below in your response:\n {message}"""
self.messages.append({ self.messages.append({
"role": "user", "role": "user",
"content": message, "content": final_message,
}) })
# this will be the function gpt will call if it # this will be the function gpt will call if it

Wyświetl plik

@ -152,12 +152,12 @@ def layer():
@app.route('/style', methods=['POST']) @app.route('/style', methods=['POST'])
def style(): def style():
message = request.json.get('message', '') message = request.json.get('message', '')
layer_name = request.json.get('layer_name', '') layer_names = request.json.get('layer_names', '')
logging.debug(f"In style endpoint, layer_name is {layer_name} and message is {message}") #logging.debug(f"In style endpoint, layer_name is {layer_names} and message is {message}")
prefixed_message = f"The following is referring to the layer {layer_name}." #prefixed_message = f"The following is referring to the layer {layer_name}."
prepended_message = prefixed_message + " " + message #prepended_message = prefixed_message + " " + message
logging.debug(f"In Style route, prepended_message is {prepended_message}") #logging.debug(f"In Style route, prepended_message is {prepended_message}")
return jsonify(style_agent.listen(prepended_message)) return jsonify(style_agent.listen(message, layer_names))
@app.route('/audio', methods=['POST']) @app.route('/audio', methods=['POST'])
def upload_audio(): def upload_audio():

Wyświetl plik

@ -29,6 +29,10 @@ class StyleResponseAgent extends ResponseAgent {
this.map.setLayoutProperty(response_data.layer_name, 'visibility', 'none'); this.map.setLayoutProperty(response_data.layer_name, 'visibility', 'none');
} }
break; break;
case "select_layer_name":
const dropdown = document.getElementById('layerDropdown');
dropdown.value = response_data.layer_name;
break;
default: default:
break; break;
} }

Wyświetl plik

@ -215,31 +215,9 @@
chatbox.value += "Error sending message.\n"; chatbox.value += "Error sending message.\n";
}); });
} else if (response_data.agent_name === 'StyleAgent') { } else if (response_data.agent_name === 'StyleAgent') {
const layer_name = dropdown.options[dropdown.selectedIndex].text; //get the layer names from the style sheet
const bodytext = JSON.stringify({message: userMessage, layer_name: layer_name}); const layer_names = map.getStyle().layers.map(layer => layer.id);
console.log(`Bodytext: ${bodytext}`);
fetch('/style', { fetch('/style', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({message: userMessage, layer_name: layer_name})
})
.then(response => response.json())
.then(data => {
response_data = data.response;
console.log(data);
chatbox.value = styleResponseAgent.handleResponse(userMessage, response_data);
return;
})
.catch(error => {
console.error("Error:", error);
chatbox.value += "Error sending message.\n";
});
} else if (response_data.agent_name === 'MapInfoAgent') {
const layer_names = get_layer_names(map);
fetch('/layer', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@ -249,9 +227,10 @@
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
response_data = data.response; response_data = data.response;
console.log(response_data); console.log(data);
chatbox.value = mapInfoResponseAgent.handleResponse(userMessage, response_data); chatbox.value = styleResponseAgent.handleResponse(userMessage, response_data);
return; return;
}) })
.catch(error => { .catch(error => {
console.error("Error:", error); console.error("Error:", error);