@@ -77,58 +77,25 @@ def prepare_openai_tools(self, city: str, state: str) -> list | None:
77
77
# This filters out other cities in the same state.
78
78
# The user is gated into selecting a city in Oregon so we don't worry about
79
79
# 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
+ )
80
93
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
116
95
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 )
132
99
133
100
max_num_results = int (os .getenv ("NUM_FILE_SEARCH_RESULTS" , 10 ))
134
101
0 commit comments