Skip to content

Commit 3cf4025

Browse files
committed
Make things configurable by env vars
1 parent 02e68f4 commit 3cf4025

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

stac_search/agents/collections_search.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
# Constants
1616
MODEL_NAME = "all-MiniLM-L6-v2"
17-
DATA_PATH = "data/chromadb"
17+
DATA_PATH = os.environ.get("DATA_PATH", "data/chromadb")
1818
OPENAI_MODEL = "gpt-4o-mini"
1919

20-
# STAC_CATALOG_NAME = "eoapi.dev"
21-
# STAC_COLLECTIONS_URL = "https://stac.eoapi.dev/"
22-
23-
STAC_CATALOG_NAME = "planetarycomputer"
24-
STAC_COLLECTIONS_URL = "https://planetarycomputer.microsoft.com/api/stac/v1"
20+
STAC_CATALOG_NAME = os.getenv("STAC_CATALOG_NAME", "planetarycomputer")
21+
STAC_COLLECTIONS_URL = os.getenv(
22+
"STAC_COLLECTIONS_URL", "https://planetarycomputer.microsoft.com/api/stac/v1"
23+
)
2524

2625
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", None)
2726

stac_search/agents/items_search.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import requests
66
from pydantic_ai import Agent, RunContext
77
from pprint import pprint
8+
import os
89

910
from stac_search.agents.collections_search import (
1011
collection_search,
1112
CollectionWithExplanation,
1213
)
1314

15+
GEODINI_API = os.getenv("GEODINI_API")
16+
1417

1518
@dataclass
1619
class Context:
@@ -197,7 +200,7 @@ async def construct_cql2_filter(ctx: RunContext[Context]) -> Cql2Filter:
197200

198201

199202
def get_polygon_from_geodini(location: str):
200-
geodini_api = "https://api.geodini.labs.sunu.in/search"
203+
geodini_api = f"{GEODINI_API}/search"
201204
response = requests.get(
202205
geodini_api,
203206
params={
@@ -275,10 +278,14 @@ async def item_search(ctx: Context) -> ItemSearchResult:
275278

276279
if ctx.return_search_params_only:
277280
print("Returning STAC query parameters only")
278-
return ItemSearchResult(search_params=params, aoi=polygon, explanation=explanation)
281+
return ItemSearchResult(
282+
search_params=params, aoi=polygon, explanation=explanation
283+
)
279284

280285
items = list(client.search(**params).items_as_dicts())
281-
return ItemSearchResult(items=items, aoi=polygon, explanation=explanation, search_params=params)
286+
return ItemSearchResult(
287+
items=items, aoi=polygon, explanation=explanation, search_params=params
288+
)
282289

283290

284291
async def main():

stac_search/load.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
from sentence_transformers import SentenceTransformer
66
import chromadb
77
from pystac_client import Client
8+
import os
9+
import logging
10+
11+
# Configure logging
12+
logging.basicConfig(level=logging.INFO)
13+
logger = logging.getLogger(__name__)
814

915
# Constants
1016
MODEL_NAME = "all-MiniLM-L6-v2"
11-
DATA_PATH = "data/chromadb"
17+
DATA_PATH = os.environ.get("DATA_PATH", "data/chromadb")
1218

1319

1420
def load_data(catalog_url, catalog_name):
1521
"""Load STAC collections into the vector database"""
16-
print("Initializing vector database...")
22+
logger.info("Initializing vector database...")
1723

1824
# Initialize the model
1925
model = SentenceTransformer(MODEL_NAME)
@@ -27,14 +33,14 @@ def load_data(catalog_url, catalog_name):
2733
# Initialize STAC client
2834
stac_client = Client.open(catalog_url)
2935

30-
print("Fetching STAC collections...")
36+
logger.info("Fetching STAC collections...")
3137
collections = fetch_collections(stac_client)
32-
print(f"Found {len(collections)} collections")
38+
logger.info(f"Found {len(collections)} collections")
3339

34-
print("Generating embeddings and storing in vector database...")
40+
logger.info("Generating embeddings and storing in vector database...")
3541
store_in_vector_db(collections, model, chroma_collection)
3642

37-
print("Data loading complete!")
43+
logger.info("Data loading complete!")
3844

3945

4046
def fetch_collections(stac_client):
@@ -73,8 +79,15 @@ def store_in_vector_db(collections, model, chroma_collection):
7379

7480

7581
if __name__ == "__main__":
76-
load_data(catalog_url="https://stac.eoapi.dev/", catalog_name="eoapi.dev")
77-
load_data(
78-
catalog_url="https://planetarycomputer.microsoft.com/api/stac/v1",
79-
catalog_name="planetarycomputer",
82+
# load_data(catalog_url="https://stac.eoapi.dev/", catalog_name="eoapi.dev")
83+
# load_data(
84+
# catalog_url="https://planetarycomputer.microsoft.com/api/stac/v1",
85+
# catalog_name="planetarycomputer",
86+
# )
87+
import os
88+
89+
STAC_CATALOG_URL = os.environ.get(
90+
"STAC_CATALOG_URL", "https://planetarycomputer.microsoft.com/api/stac/v1"
8091
)
92+
STAC_CATALOG_NAME = os.environ.get("STAC_CATALOG_NAME", "planetarycomputer")
93+
load_data(catalog_url=STAC_CATALOG_URL, catalog_name=STAC_CATALOG_NAME)

0 commit comments

Comments
 (0)