fixed context length issue and added ability to put all feature types on the map

pull/137/head
shanergi 2023-10-30 18:16:24 -04:00
rodzic dd77e9fc09
commit 85e40b5282
5 zmienionych plików z 60 dodań i 19 usunięć

Wyświetl plik

@ -122,12 +122,15 @@ class DatabaseAgent:
logger.info(f"Function args: {function_args}") logger.info(f"Function args: {function_args}")
# determine the function to call # determine the function to call
function_response = function_to_call(**function_args) function_response = function_to_call(**function_args)
self.messages.append(response_message)
self.messages.append({ ### This is blowing up my context window
"role": "function", # self.messages.append(response_message)
"name": function_name, # self.messages.append({
"content": function_response, # "role": "function",
}) # "name": function_name,
# "content": function_response,
# })
return {"response": function_response} return {"response": function_response}
elif response_message.get("content"): elif response_message.get("content"):
return {"response": response_message["content"]} return {"response": response_message["content"]}

Wyświetl plik

@ -109,7 +109,7 @@ def geojson():
results = db.execute(query) results = db.execute(query)
if not results: if not results:
return jsonify({"type": "FeatureCollection", "features": []}) return jsonify({"type": "FeatureCollection", "features": []})
results = results[:1000] #results = results[:5000]
features = [] features = []
for result in results: for result in results:
geometry_dict = json.loads(result[0]) geometry_dict = json.loads(result[0])

Wyświetl plik

@ -16,6 +16,7 @@ class DatabaseResponseAgent extends ResponseAgent {
.then(data => { .then(data => {
console.log("DatabaseResponseAgent data: ", data); console.log("DatabaseResponseAgent data: ", data);
if (data.features.length > 0) { if (data.features.length > 0) {
const geomType = this.getGeoJSONFeatureType(data);
//remove the previous layer //remove the previous layer
if (this.map.getLayer('query_result')) { if (this.map.getLayer('query_result')) {
this.map.removeLayer('query_result'); this.map.removeLayer('query_result');
@ -25,16 +26,41 @@ class DatabaseResponseAgent extends ResponseAgent {
'type': 'geojson', 'type': 'geojson',
'data': data 'data': data
}); });
this.map.addLayer({
"id": "query_result", if (geomType === "Polygon") {
"type": "fill", this.map.addLayer({
"source": "geojson", "id": "query_result",
'layout': {}, "type": "fill",
'paint': { "source": "geojson",
'fill-color': '#ff0000', 'layout': {},
'fill-opacity': 0.4 'paint': {
} 'fill-color': '#ff0000',
}); 'fill-opacity': 0.4
}
});
} else if (geomType === "LineString") {
this.map.addLayer({
"id": "query_result",
"type": "line",
"source": "geojson",
'layout': {},
'paint': {
'line-color': '#ff0000',
'line-opacity': 0.4
}
});
} else if (geomType === "Point") {
this.map.addLayer({
"id": "query_result",
"type": "circle",
"source": "geojson",
'layout': {},
'paint': {
'circle-color': '#ff0000',
'circle-opacity': 0.4
}
});
}
//add the layer to the dropdown //add the layer to the dropdown
const dropdown = document.getElementById('layerDropdown'); const dropdown = document.getElementById('layerDropdown');
@ -86,4 +112,15 @@ class DatabaseResponseAgent extends ResponseAgent {
} }
return this.getResponseString(userMessage, response_data); return this.getResponseString(userMessage, response_data);
} }
getGeoJSONFeatureType(geojson) {
const features = geojson.features || [];
if (features.length === 0) {
return;
}
const firstFeature = features[0];
const geometry = firstFeature.geometry || {};
return geometry.type || "Unknown";
}
} }

Wyświetl plik

@ -4,7 +4,7 @@ class NavigationResponseAgent extends ResponseAgent {
if (response_data.name === "go_to_location") { if (response_data.name === "go_to_location") {
this.map.flyTo({ this.map.flyTo({
center: [response_data.longitude, response_data.latitude], center: [response_data.longitude, response_data.latitude],
zoom: 16 zoom: 14
}); });
} else if (response_data.name === "zoom_in") { } else if (response_data.name === "zoom_in") {
this.map.zoomTo(this.map.getZoom() + response_data.zoom_levels); this.map.zoomTo(this.map.getZoom() + response_data.zoom_levels);

Wyświetl plik

@ -40,4 +40,5 @@ function getResponseString(userMessage, response_data) {
console.log(typeof response_data) console.log(typeof response_data)
console.log(response_data) console.log(response_data)
return "You: " + userMessage + "\nAI: " + JSON.stringify(response_data) + "\n" return "You: " + userMessage + "\nAI: " + JSON.stringify(response_data) + "\n"
} }