kopia lustrzana https://github.com/kartoza/docker-osm
moved layer selection into style agent
rodzic
d62ff8558b
commit
0bce885309
|
@ -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 = [
|
||||
set_color,
|
||||
set_opacity,
|
||||
set_width,
|
||||
set_visibility,
|
||||
select_layer_name,
|
||||
]
|
|
@ -19,7 +19,7 @@ class MarshallAgent:
|
|||
"properties": {
|
||||
"agent_name": {
|
||||
"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"],
|
||||
|
@ -32,16 +32,12 @@ class MarshallAgent:
|
|||
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'.
|
||||
|
||||
For tasks that ask to change the style of a map, such as opacity, color, or line width, you will
|
||||
use the StyleAgent. Examples StyleAgent prompts include 'change color to green', 'opacity 45%'
|
||||
and 'line width 4'.
|
||||
For tasks that change the style of a map, such as selecting a layer to style, changing the opacity, color,
|
||||
or line width of a layer, you will use the StyleAgent. Example StyleAgent prompts include 'change color to green',
|
||||
'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.
|
||||
Example MapInfoAgent prompts include 'select the water layer' and 'select buildings'.
|
||||
|
||||
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?'
|
||||
For tasks to 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 'fly to Houston, Texas'
|
||||
|
||||
If you can't find the appropriate agent, say that you didn't understand and ask
|
||||
for a more specific description of the task."""
|
||||
|
|
|
@ -19,6 +19,9 @@ class StyleAgent:
|
|||
def set_visibility(self, layer_name, 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):
|
||||
self.client = client
|
||||
self.model_version = model_version
|
||||
|
@ -40,15 +43,16 @@ class StyleAgent:
|
|||
"set_opacity": self.set_opacity,
|
||||
"set_width": self.set_width,
|
||||
"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."""
|
||||
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({
|
||||
"role": "user",
|
||||
"content": message,
|
||||
"content": final_message,
|
||||
})
|
||||
|
||||
# this will be the function gpt will call if it
|
||||
|
|
|
@ -152,12 +152,12 @@ def layer():
|
|||
@app.route('/style', methods=['POST'])
|
||||
def style():
|
||||
message = request.json.get('message', '')
|
||||
layer_name = request.json.get('layer_name', '')
|
||||
logging.debug(f"In style endpoint, layer_name is {layer_name} and message is {message}")
|
||||
prefixed_message = f"The following is referring to the layer {layer_name}."
|
||||
prepended_message = prefixed_message + " " + message
|
||||
logging.debug(f"In Style route, prepended_message is {prepended_message}")
|
||||
return jsonify(style_agent.listen(prepended_message))
|
||||
layer_names = request.json.get('layer_names', '')
|
||||
#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}."
|
||||
#prepended_message = prefixed_message + " " + message
|
||||
#logging.debug(f"In Style route, prepended_message is {prepended_message}")
|
||||
return jsonify(style_agent.listen(message, layer_names))
|
||||
|
||||
@app.route('/audio', methods=['POST'])
|
||||
def upload_audio():
|
||||
|
|
|
@ -29,6 +29,10 @@ class StyleResponseAgent extends ResponseAgent {
|
|||
this.map.setLayoutProperty(response_data.layer_name, 'visibility', 'none');
|
||||
}
|
||||
break;
|
||||
case "select_layer_name":
|
||||
const dropdown = document.getElementById('layerDropdown');
|
||||
dropdown.value = response_data.layer_name;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -215,31 +215,9 @@
|
|||
chatbox.value += "Error sending message.\n";
|
||||
});
|
||||
} else if (response_data.agent_name === 'StyleAgent') {
|
||||
const layer_name = dropdown.options[dropdown.selectedIndex].text;
|
||||
const bodytext = JSON.stringify({message: userMessage, layer_name: layer_name});
|
||||
console.log(`Bodytext: ${bodytext}`);
|
||||
//get the layer names from the style sheet
|
||||
const layer_names = map.getStyle().layers.map(layer => layer.id);
|
||||
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',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
@ -249,9 +227,10 @@
|
|||
.then(response => response.json())
|
||||
.then(data => {
|
||||
response_data = data.response;
|
||||
console.log(response_data);
|
||||
chatbox.value = mapInfoResponseAgent.handleResponse(userMessage, response_data);
|
||||
console.log(data);
|
||||
chatbox.value = styleResponseAgent.handleResponse(userMessage, response_data);
|
||||
return;
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error:", error);
|
||||
|
|
Ładowanie…
Reference in New Issue