Skip to content

Commit 4ad4951

Browse files
committed
fix: review change from @yangm2
1 parent f65d1b3 commit 4ad4951

File tree

1 file changed

+17
-50
lines changed

1 file changed

+17
-50
lines changed

backend/tenantfirstaid/chat.py

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -77,58 +77,25 @@ def prepare_openai_tools(self, city: str, state: str) -> list | None:
7777
# This filters out other cities in the same state.
7878
# The user is gated into selecting a city in Oregon so we don't worry about
7979
# whether the relevant documents exist or not.
80+
FILTER_STATE_IS_OREGON = ComparisonFilter(type="eq", key="state", value="or")
81+
FILTER_CITY_IS_NULL = ComparisonFilter(type="eq", key="city", value="null")
82+
FILTER_CITY_IS_GIVEN = ComparisonFilter(type="eq", key="city", value=city)
83+
FILTER_OREGON_AND_NULL_CITY = CompoundFilter(
84+
type="and", filters=[FILTER_STATE_IS_OREGON, FILTER_CITY_IS_NULL]
85+
)
86+
FILTER_OREGON_AND_SOME_CITY = CompoundFilter(
87+
type="and", filters=[FILTER_STATE_IS_OREGON, FILTER_CITY_IS_GIVEN]
88+
)
89+
FILTER_UNION = CompoundFilter(
90+
type="or",
91+
filters=[FILTER_OREGON_AND_NULL_CITY, FILTER_OREGON_AND_SOME_CITY],
92+
)
8093
if city != "null":
81-
filters = CompoundFilter(
82-
type="or",
83-
filters=[
84-
CompoundFilter(
85-
type="and",
86-
filters=[
87-
ComparisonFilter(
88-
type="eq",
89-
key="city",
90-
value=city,
91-
),
92-
ComparisonFilter(
93-
type="eq",
94-
key="state",
95-
value=state,
96-
),
97-
],
98-
),
99-
CompoundFilter(
100-
type="and",
101-
filters=[
102-
ComparisonFilter(
103-
type="eq",
104-
key="city",
105-
value="null",
106-
),
107-
ComparisonFilter(
108-
type="eq",
109-
key="state",
110-
value=state,
111-
),
112-
],
113-
),
114-
],
115-
)
94+
filters = FILTER_UNION
11695
else:
117-
filters = CompoundFilter(
118-
type="and",
119-
filters=[
120-
ComparisonFilter(
121-
type="eq",
122-
key="city",
123-
value="null",
124-
),
125-
ComparisonFilter(
126-
type="eq",
127-
key="state",
128-
value=state,
129-
),
130-
],
131-
)
96+
filters = FILTER_OREGON_AND_NULL_CITY
97+
98+
print("Preparing OpenAI tools with filters:", filters)
13299

133100
max_num_results = int(os.getenv("NUM_FILE_SEARCH_RESULTS", 10))
134101

0 commit comments

Comments
 (0)