@@ -51,6 +51,7 @@ def _format_router(self, router: dict) -> Router:
5151 type = router ["type" ],
5252 aliases = "," .join (router ["aliases" ]) if router ["aliases" ] else "" ,
5353 load_balancing_strategy = _load_balancing_strategy_converter .get (router ["load_balancing_strategy" ]),
54+ is_default = router ["is_default" ],
5455 max_context_length = router ["max_context_length" ],
5556 vector_size = router ["vector_size" ],
5657 cost_prompt_tokens = router ["cost_prompt_tokens" ],
@@ -175,6 +176,7 @@ async def delete_entity(self):
175176 load_balancing_strategy = "Shuffle" ,
176177 cost_prompt_tokens = 0.0 ,
177178 cost_completion_tokens = 0.0 ,
179+ is_default = False ,
178180 )
179181
180182 @rx .event
@@ -185,6 +187,9 @@ def set_new_entity_attribut(self, attribute: str, value: str | bool | None):
185187 else :
186188 setattr (self .entity_to_create , attribute , value )
187189
190+ if attribute == "type" and value != "text-embeddings-inference" :
191+ self .entity_to_create .is_default = False
192+
188193 @rx .event
189194 async def create_entity (self ):
190195 """Create a router."""
@@ -195,14 +200,17 @@ async def create_entity(self):
195200 self .create_entity_loading = True
196201 yield
197202
198- new_router_load_balancing_strategy = self .entity_to_create .load_balancing_strategy .lower ().replace (" " , "_" )
203+ new_router_load_balancing_strategy = (
204+ self .entity_to_create .load_balancing_strategy .lower ().replace (" " , "_" ) if self .entity_to_create .load_balancing_strategy else "shuffle"
205+ )
199206
200207 payload = {
201208 "name" : self .entity_to_create .name ,
202209 "type" : self .entity_to_create .type ,
203210 "load_balancing_strategy" : new_router_load_balancing_strategy ,
204211 "cost_prompt_tokens" : self .entity_to_create .cost_prompt_tokens ,
205212 "cost_completion_tokens" : self .entity_to_create .cost_completion_tokens ,
213+ "is_default" : self .entity_to_create .is_default ,
206214 }
207215
208216 if self .entity_to_create .aliases :
@@ -222,6 +230,16 @@ async def create_entity(self):
222230 response .raise_for_status ()
223231
224232 yield rx .toast .success ("Router created successfully" , position = "bottom-right" )
233+
234+ # Reset form
235+ self .entity_to_create = Router (
236+ type = "text-generation" ,
237+ load_balancing_strategy = "Shuffle" ,
238+ cost_prompt_tokens = 0.0 ,
239+ cost_completion_tokens = 0.0 ,
240+ is_default = False ,
241+ )
242+
225243 async for _ in self .load_entities ():
226244 yield
227245
@@ -249,6 +267,9 @@ def set_edit_entity_attribut(self, attribute: str, value: str | bool | None):
249267 else :
250268 setattr (self .entity , attribute , value )
251269
270+ if attribute == "type" and value != "text-embeddings-inference" :
271+ self .entity .is_default = False
272+
252273 @rx .var
253274 def is_settings_entity_dialog_open (self ) -> bool :
254275 """Check if settings dialog should be open."""
@@ -276,6 +297,7 @@ async def edit_entity(self):
276297 "load_balancing_strategy" : router_load_balancing_strategy ,
277298 "cost_prompt_tokens" : self .entity .cost_prompt_tokens ,
278299 "cost_completion_tokens" : self .entity .cost_completion_tokens ,
300+ "is_default" : self .entity .is_default ,
279301 }
280302
281303 response = None
@@ -347,3 +369,11 @@ async def next_page(self):
347369 yield
348370 async for _ in self .load_entities ():
349371 yield
372+
373+ @rx .var
374+ def default_vector_store_router (self ) -> Router | None :
375+ """Get the current default vector store router from the loaded entities."""
376+ for router in self .entities :
377+ if router .type == "text-embeddings-inference" and router .is_default :
378+ return router
379+ return None
0 commit comments