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}")
# determine the function to call
function_response = function_to_call(**function_args)
self.messages.append(response_message)
self.messages.append({
"role": "function",
"name": function_name,
"content": function_response,
})
### This is blowing up my context window
# self.messages.append(response_message)
# self.messages.append({
# "role": "function",
# "name": function_name,
# "content": function_response,
# })
return {"response": function_response}
elif response_message.get("content"):
return {"response": response_message["content"]}

Wyświetl plik

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

Wyświetl plik

@ -16,6 +16,7 @@ class DatabaseResponseAgent extends ResponseAgent {
.then(data => {
console.log("DatabaseResponseAgent data: ", data);
if (data.features.length > 0) {
const geomType = this.getGeoJSONFeatureType(data);
//remove the previous layer
if (this.map.getLayer('query_result')) {
this.map.removeLayer('query_result');
@ -25,16 +26,41 @@ class DatabaseResponseAgent extends ResponseAgent {
'type': 'geojson',
'data': data
});
this.map.addLayer({
"id": "query_result",
"type": "fill",
"source": "geojson",
'layout': {},
'paint': {
'fill-color': '#ff0000',
'fill-opacity': 0.4
}
});
if (geomType === "Polygon") {
this.map.addLayer({
"id": "query_result",
"type": "fill",
"source": "geojson",
'layout': {},
'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
const dropdown = document.getElementById('layerDropdown');
@ -86,4 +112,15 @@ class DatabaseResponseAgent extends ResponseAgent {
}
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") {
this.map.flyTo({
center: [response_data.longitude, response_data.latitude],
zoom: 16
zoom: 14
});
} else if (response_data.name === "zoom_in") {
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(response_data)
return "You: " + userMessage + "\nAI: " + JSON.stringify(response_data) + "\n"
}
}