|
1 | | -import datetime |
| 1 | +from datetime import date |
2 | 2 | import logging |
3 | 3 | import os |
4 | 4 | from dataclasses import dataclass |
|
9 | 9 | from pydantic_ai import Agent, RunContext |
10 | 10 | from pystac_client import Client |
11 | 11 | from pydantic import BaseModel, ConfigDict |
12 | | -from shapely.geometry import shape, mapping |
13 | 12 |
|
14 | 13 | from stac_search.agents.collections_search import ( |
15 | 14 | collection_search, |
@@ -47,18 +46,22 @@ class ItemSearchParams: |
47 | 46 | SMALL_MODEL_NAME, |
48 | 47 | result_type=ItemSearchParams, |
49 | 48 | deps_type=Context, |
50 | | - system_prompt=f""" |
| 49 | + system_prompt=""" |
51 | 50 | For the given query, extract the start date, end date, and location. |
52 | 51 |
|
53 | 52 | If the query contains a spatial extent, use the `set_spatial_extent` tool to get the location. |
54 | 53 | If the query contains a temporal range, use the `set_temporal_range` tool to get the datetime. |
55 | 54 | If the query needs cloud cover filtering, use the `construct_cql2_filter` tool to create a CQL2 filter. |
56 | 55 |
|
57 | | -For context, the current date is {datetime.datetime.now().strftime("%Y-%m-%d")}. |
58 | 56 | """, |
59 | 57 | ) |
60 | 58 |
|
61 | 59 |
|
| 60 | +@search_items_agent.system_prompt |
| 61 | +def search_items_agent_system_prompt(): |
| 62 | + return f"The current date is {date.today()}" |
| 63 | + |
| 64 | + |
62 | 65 | @dataclass |
63 | 66 | class CollectionQuery: |
64 | 67 | query: str |
@@ -146,11 +149,15 @@ class TemporalRangeResult: |
146 | 149 | For the given query, if it contains a temporal range, return the start date and end date. If it doesn't contain a temporal range, return None. |
147 | 150 | The temporal range should be of the form YYYY-MM-DD/YYYY-MM-DD. |
148 | 151 | For open-ended ranges, use "..", for example "2023-01-01/.." or "../2023-12-31". |
149 | | -The current date is {datetime.datetime.now().strftime("%Y-%m-%d")}. |
150 | 152 | """, |
151 | 153 | ) |
152 | 154 |
|
153 | 155 |
|
| 156 | +@temporal_range_agent.system_prompt |
| 157 | +def temporal_range_agent_system_prompt(): |
| 158 | + return f"The current date is {date.today()}" |
| 159 | + |
| 160 | + |
154 | 161 | @search_items_agent.tool |
155 | 162 | async def set_temporal_range(ctx: RunContext[Context]) -> TemporalRangeResult: |
156 | 163 | result = await temporal_range_agent.run(ctx.deps.query) |
@@ -289,11 +296,7 @@ async def item_search(ctx: Context) -> ItemSearchResult: |
289 | 296 | client = Client.open(STAC_CATALOG_URL) |
290 | 297 | params = { |
291 | 298 | "max_items": 20, |
292 | | - # looks like collections is required by Planetary Computer STAC API |
293 | | - # but can be omitted for elasticsearch based STAC APIs like the element84 one |
294 | 299 | "collections": collections_to_search, |
295 | | - # "collections": ["*"], |
296 | | - # "datetime": "2018", |
297 | 300 | "datetime": results.data.datetime, |
298 | 301 | "filter": results.data.filter, |
299 | 302 | } |
|
0 commit comments