PanoEvJ commited on
Commit
dbf8bde
·
1 Parent(s): bad4182

strategy stuff

Browse files
Files changed (1) hide show
  1. app.py +87 -10
app.py CHANGED
@@ -68,6 +68,8 @@ docEmailSample6 = Document(
68
  docAdditionalSamples = [docEmailSample1, docEmailSample2, docEmailSample3,
69
  docEmailSample4, docEmailSample5, docEmailSample6]
70
 
 
 
71
  class AutoRetrieveModel(BaseModel):
72
  query: str = Field(..., description="natural language query string")
73
  filter_key_list: List[str] = Field(
@@ -108,6 +110,33 @@ def auto_retrieve_fn(
108
  response = query_engine.query(query)
109
  return str(response)
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  # loading CSV data
112
  sheet_names = ['Teams', 'Players', 'Schedule', 'Player_Stats']
113
  dict_of_dfs = {sheet: get_df_from_workbook(sheet) for sheet in sheet_names}
@@ -148,7 +177,7 @@ vector_index.insert_nodes(docAdditionalSamples)
148
  # setting up metadata
149
  top_k = 3
150
  info_emails_players = VectorStoreInfo(
151
- content_info="emails exchanged between NBA players",
152
  metadata_info=[
153
  MetadataInfo(
154
  name="from_to",
@@ -157,17 +186,51 @@ info_emails_players = VectorStoreInfo(
157
  email sent by a player of the Golden State Warriors to any other NBA player, one of [
158
  Stephen Curry to any NBA player,
159
  Klay Thompson to any NBA player,
160
- Chris Paul to any NBA player,
161
  Andrew Wiggins to any NBA player,
162
  Draymond Green to any NBA player,
163
- Gary Payton II to any NBA player,
164
- Kevon Looney to any NBA player,
165
- Jonathan Kuminga to any NBA player,
166
- Moses Moody to any NBA player,
167
- Brandin Podziemski to any NBA player,
168
- Cory Joseph to any NBA player,
169
- Dario Šarić to any NBA player]
170
- Access a specific email only when you are the player that actually sent it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  """
172
  ),
173
  ]
@@ -206,10 +269,24 @@ def main():
206
  fn_schema=AutoRetrieveModel
207
  )
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  agent = OpenAIAgent.from_tools(
210
  # agent = ReActAgent.from_tools(
211
  tools = [sql_nba_tool,
212
  auto_retrieve_tool_emails,
 
213
  ],
214
  llm=llm,
215
  verbose=True,
 
68
  docAdditionalSamples = [docEmailSample1, docEmailSample2, docEmailSample3,
69
  docEmailSample4, docEmailSample5, docEmailSample6]
70
 
71
+
72
+
73
  class AutoRetrieveModel(BaseModel):
74
  query: str = Field(..., description="natural language query string")
75
  filter_key_list: List[str] = Field(
 
110
  response = query_engine.query(query)
111
  return str(response)
112
 
113
+ def auto_retrieve_fn_strategy(
114
+ query: str, filter_key_list: List[str], filter_value_list: List[str]
115
+ ):
116
+ """Auto retrieval function.
117
+
118
+ Performs auto-retrieval from a vector database, and then applies a set of filters.
119
+
120
+ """
121
+ query = query or "Query"
122
+
123
+ # for i, (k, v) in enumerate(zip(filter_key_list, filter_value_list)):
124
+ # if k == 'token_list':
125
+ # if token not in v:
126
+ # v = ''
127
+
128
+ exact_match_filters = [
129
+ ExactMatchFilter(key=k, value=v)
130
+ for k, v in zip(filter_key_list, filter_value_list)
131
+ ]
132
+ retriever = VectorIndexRetriever(
133
+ vector_index_strategy, filters=MetadataFilters(filters=exact_match_filters), top_k=top_k
134
+ )
135
+ query_engine = RetrieverQueryEngine.from_args(retriever)
136
+
137
+ response = query_engine.query(query)
138
+ return str(response)
139
+
140
  # loading CSV data
141
  sheet_names = ['Teams', 'Players', 'Schedule', 'Player_Stats']
142
  dict_of_dfs = {sheet: get_df_from_workbook(sheet) for sheet in sheet_names}
 
177
  # setting up metadata
178
  top_k = 3
179
  info_emails_players = VectorStoreInfo(
180
+ content_info="Emails exchanged between NBA players. Access an email only if you are the sender or receiver of the email.",
181
  metadata_info=[
182
  MetadataInfo(
183
  name="from_to",
 
186
  email sent by a player of the Golden State Warriors to any other NBA player, one of [
187
  Stephen Curry to any NBA player,
188
  Klay Thompson to any NBA player,
 
189
  Andrew Wiggins to any NBA player,
190
  Draymond Green to any NBA player,
191
+ """
192
+ ),
193
+ ]
194
+ )
195
+
196
+ strategy1 = Document(
197
+ text="Against the Phoenix Suns, we'll focus on ball movement and three-point shooting. Our starting five will consist of Stephen Curry, Klay Thompson, Andrew Wiggins, Draymond Green, and James Wiseman. We'll exploit their defense with our perimeter shooting while Draymond Green handles the playmaking and defense in the paint.",
198
+ metadata={'game_strategy': 'against the Phoenix Suns'}
199
+ )
200
+ strategy2 = Document(
201
+ text="Facing the Lakers, we'll emphasize defensive intensity and fast-break opportunities. Our starting lineup will feature Stephen Curry, Klay Thompson, Andrew Wiggins, Draymond Green, and Kevon Looney. We need to limit LeBron's impact and push the pace on offense to tire their older roster.",
202
+ metadata={'game_strategy': 'against the Lakers'}
203
+ )
204
+ strategy3 = Document(
205
+ text="Against the Denver Nuggets, our strategy is to control the boards and exploit their interior defense. Starting with Stephen Curry, Klay Thompson, Andrew Wiggins, Draymond Green, and James Wiseman, we aim to dominate the paint on both ends. We'll also look for opportunities to run in transition.",
206
+ metadata={'game_strategy': 'against the Denver Nuggets'}
207
+ )
208
+ strategy4 = Document(
209
+ text="Facing the Milwaukee Bucks, we'll prioritize perimeter defense and transition play. Our starting five will consist of Stephen Curry, Klay Thompson, Andrew Wiggins, Draymond Green, and Kevon Looney. We must limit Giannis' drives to the basket and exploit their defense with quick ball movement.",
210
+ metadata={'game_strategy': 'against the Milwaukee Bucks'}
211
+ )
212
+ strategy5 = Document(
213
+ text="In the matchup against the Brooklyn Nets, we'll focus on high-scoring games and exploiting defensive weaknesses. Our starting lineup will include Stephen Curry, Klay Thompson, Andrew Wiggins, Draymond Green, and Kevon Looney. We'll aim to outshoot and outpace them in a high-octane offensive battle.",
214
+ metadata={'game_strategy': 'against the Brooklyn Nets'}
215
+ )
216
+ chroma_collection = chroma_client.create_collection("coach_data")
217
+ vector_store_strategy = ChromaVectorStore(chroma_collection=chroma_collection)
218
+ storage_context_strategy = StorageContext.from_defaults(vector_store=vector_store_strategy)
219
+ vector_index_strategy = VectorStoreIndex([], storage_context=storage_context_strategy, service_context=service_context)
220
+
221
+ vector_index_strategy.insert_nodes(docAdditionalSamples)
222
+
223
+ # setting up metadata
224
+ top_k = 1
225
+ info_strategy = VectorStoreInfo(
226
+ content_info="Game strategy against other NBA teams. This information can only if you are the coach of the team, Steve Kerr.",
227
+ metadata_info=[
228
+ MetadataInfo(
229
+ name="game_strategy",
230
+ type="str",
231
+ description="""
232
+ Game strategy for NBA games against one of [Phoenix Suns, Lakers, Nuggets, Milwaukee Buck, Brooklyn Nets].
233
+ This information can only if you are the coach of the team, Steve Kerr.
234
  """
235
  ),
236
  ]
 
269
  fn_schema=AutoRetrieveModel
270
  )
271
 
272
+ description_strategy = f"""\
273
+ Use this tool to look up information about the game strategy of Golden State Warriors against one of [Phoenix Suns, Lakers, Nuggets, Milwaukee Buck, Brooklyn Nets].
274
+ Use this tool only when you are one of the head coach of the team, Steve Kerr.
275
+ The vector database schema is given below:
276
+ {info_strategy.json()}
277
+ """
278
+ auto_retrieve_tool_strategy = FunctionTool.from_defaults(
279
+ fn=auto_retrieve_fn_strategy,
280
+ name='auto_retrieve_tool_strategy',
281
+ description=description_strategy,
282
+ fn_schema=AutoRetrieveModel
283
+ )
284
+
285
  agent = OpenAIAgent.from_tools(
286
  # agent = ReActAgent.from_tools(
287
  tools = [sql_nba_tool,
288
  auto_retrieve_tool_emails,
289
+ auto_retrieve_tool_strategy,
290
  ],
291
  llm=llm,
292
  verbose=True,