Skip to content

Commit b569353

Browse files
authored
Update structure of output folder (#27)
* Rename output directories * Add custom warnings * Fix key bug * Consolidate column outputs * Update docs * Output columns are now fixed * Split db into qualitative and quantitative outputs * Re-iterate for the LLM to focus on feature * Minor time tracking update * Add new utility function * Add `JurisdictionUpdater` * Record jurisdiction info * File name now contains download date * Add `num_ordinances_in_doc` func * Use `num_ordinances_in_doc` func * Add explicit ignore to prompt * Pass tech down one function * Write out run meta * Add total run time to jurisdiction info * Process now writes time to jurisdiction file and only usage goes to usage file * Add subdivision info * Datetime recorded in UTC * Updates to meta dict * Rename dirs args * Minor bug fix * Track LLM parse args in meta
1 parent 8b6ffe0 commit b569353

8 files changed

Lines changed: 404 additions & 133 deletions

File tree

compass/extraction/solar/parse.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
from copy import deepcopy
66
from itertools import chain
7+
from warnings import warn
78

89
import pandas as pd
910

@@ -24,6 +25,7 @@
2425
setup_graph_sef_types,
2526
setup_multiplier,
2627
)
28+
from compass.warnings import COMPASSWarning
2729

2830

2931
logger = logging.getLogger(__name__)
@@ -169,7 +171,7 @@ async def _parse_extra_restriction(
169171
chat_llm_caller=self._init_chat_llm_caller(system_message),
170172
)
171173
info = await run_async_tree(tree)
172-
info.update({"feature": feature})
174+
info.update({"feature": feature, "quantitative": is_numerical})
173175
return [info]
174176

175177
async def _parse_setback_feature(
@@ -268,7 +270,10 @@ async def _parse_p_or_np_text(
268270

269271
async def _extract_setback_values(self, text, **kwargs):
270272
"""Extract setback values for a given feature from input text"""
271-
return await self._run_setback_graph(setup_multiplier, text, **kwargs)
273+
decision_tree_out = await self._run_setback_graph(
274+
setup_multiplier, text, **kwargs
275+
)
276+
return _update_output_keys(decision_tree_out)
272277

273278
async def _run_setback_graph(
274279
self,
@@ -293,3 +298,25 @@ async def _run_setback_graph(
293298
if base_messages:
294299
return await run_async_tree_with_bm(tree, base_messages)
295300
return await run_async_tree(tree)
301+
302+
303+
def _update_output_keys(output):
304+
"""Standardize output keys
305+
306+
We could standardize output keys by modifying the LLM prompts, but
307+
have found that it's more accurate to instruct the LLM to use
308+
descriptive keys (e.g. "mult_value" instead of "value" or
309+
"mult_type" instead of "units")
310+
"""
311+
312+
if "mult_value" not in output:
313+
return output
314+
315+
output["value"] = output.pop("mult_value")
316+
317+
if units := output.get("units"):
318+
msg = f"Found non-null units value for multiplier: {units}"
319+
warn(msg, COMPASSWarning)
320+
output["units"] = "structure-height-multiplier"
321+
322+
return output

compass/extraction/wind/graphs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ def setup_conditional(**kwargs):
226226
G.add_node(
227227
"init",
228228
prompt=(
229+
"Focus only on setback from {feature}; do not respond based "
230+
"on any text related to {ignore_features}."
229231
"Does the setback from {feature} mention a minimum or maximum "
230232
"static setback distance regardless of the outcome of the "
231233
"multiplier calculation? This is often phrased as 'the greater "

compass/extraction/wind/parse.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
from copy import deepcopy
66
from itertools import chain
7+
from warnings import warn
78

89
import pandas as pd
910

@@ -25,6 +26,7 @@
2526
setup_multiplier,
2627
setup_conditional,
2728
)
29+
from compass.warnings import COMPASSWarning
2830

2931

3032
logger = logging.getLogger(__name__)
@@ -168,7 +170,7 @@ async def _parse_extra_restriction(
168170
chat_llm_caller=self._init_chat_llm_caller(system_message),
169171
)
170172
info = await run_async_tree(tree)
171-
info.update({"feature": feature})
173+
info.update({"feature": feature, "quantitative": is_numerical})
172174
return [info]
173175

174176
async def _parse_setback_feature(
@@ -203,7 +205,7 @@ async def _base_messages(self, text, **feature_kwargs):
203205
"""Get base messages for setback feature parsing"""
204206
system_message = SETBACKS_SYSTEM_MESSAGE.format(
205207
feature=feature_kwargs["feature"],
206-
tech=feature_kwargs["wes_type"],
208+
tech=feature_kwargs["tech"],
207209
)
208210
tree = setup_async_decision_tree(
209211
setup_base_graph,
@@ -270,8 +272,9 @@ async def _extract_setback_values(self, text, **kwargs):
270272
decision_tree_out = await self._run_setback_graph(
271273
setup_multiplier, text, **kwargs
272274
)
275+
decision_tree_out = _update_output_keys(decision_tree_out)
273276

274-
if decision_tree_out.get("mult_value") is None:
277+
if decision_tree_out.get("value") is None:
275278
return decision_tree_out
276279

277280
decision_tree_conditional_out = await self._run_setback_graph(
@@ -303,3 +306,25 @@ async def _run_setback_graph(
303306
if base_messages:
304307
return await run_async_tree_with_bm(tree, base_messages)
305308
return await run_async_tree(tree)
309+
310+
311+
def _update_output_keys(output):
312+
"""Standardize output keys
313+
314+
We could standardize output keys by modifying the LLM prompts, but
315+
have found that it's more accurate to instruct the LLM to use
316+
descriptive keys (e.g. "mult_value" instead of "value" or
317+
"mult_type" instead of "units")
318+
"""
319+
320+
if "mult_value" not in output:
321+
return output
322+
323+
output["value"] = output.pop("mult_value")
324+
325+
if units := output.get("units"):
326+
msg = f"Found non-null units value for multiplier: {units}"
327+
warn(msg, COMPASSWarning)
328+
output["units"] = output.pop("mult_type", None)
329+
330+
return output

0 commit comments

Comments
 (0)