diff --git a/flask_app/agents/database_agent.py b/flask_app/agents/database_agent.py index 4c46948..f16a641 100644 --- a/flask_app/agents/database_agent.py +++ b/flask_app/agents/database_agent.py @@ -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"]} diff --git a/flask_app/app.py b/flask_app/app.py index 9e2738f..ac1ce32 100644 --- a/flask_app/app.py +++ b/flask_app/app.py @@ -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]) diff --git a/flask_app/static/js/database_response_agent.js b/flask_app/static/js/database_response_agent.js index 4c6b1f6..dfb4feb 100644 --- a/flask_app/static/js/database_response_agent.js +++ b/flask_app/static/js/database_response_agent.js @@ -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"; + } } \ No newline at end of file diff --git a/flask_app/static/js/navigation_response_agent.js b/flask_app/static/js/navigation_response_agent.js index 7f23ea1..d7f28f0 100644 --- a/flask_app/static/js/navigation_response_agent.js +++ b/flask_app/static/js/navigation_response_agent.js @@ -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); diff --git a/flask_app/static/js/utils.js b/flask_app/static/js/utils.js index 3a06412..1acdc3d 100644 --- a/flask_app/static/js/utils.js +++ b/flask_app/static/js/utils.js @@ -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" -} \ No newline at end of file +} +