Skip to content

Commit e321ab0

Browse files
committed
feat(playground): add playground lmanagement for default vector store model with limitation and updates
1 parent 1da5c3b commit e321ab0

4 files changed

Lines changed: 61 additions & 18 deletions

File tree

playground/app/features/routers/components/forms.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ def router_settings_form_fields() -> rx.Component:
2626
),
2727
entity_form_checkbox_field(
2828
label="Set as default vector store router",
29-
value=RoutersState.entity.is_default_vector_store,
30-
on_change=lambda value: RoutersState.set_edit_entity_attribut("is_default_vector_store", value),
31-
tooltip="Set as default vector store router. This option is only available for type 'text-embeddings-inference' routers.",
32-
disabled=(RoutersState.entity.type != "text-embeddings-inference") | (RoutersState.entity.is_default_vector_store is None),
29+
value=(RoutersState.entity.is_default & (RoutersState.entity.type == "text-embeddings-inference")),
30+
on_change=lambda value: RoutersState.set_edit_entity_attribut("is_default", value),
31+
tooltip=rx.cond(
32+
(RoutersState.entity.type == "text-embeddings-inference")
33+
& (RoutersState.default_vector_store_router.bool())
34+
& (RoutersState.default_vector_store_router.id != RoutersState.entity.id),
35+
"Another router is already set as default vector store. Please uncheck it explicitly before checking this one.",
36+
"Set as default vector store router. This option is only available for type 'text-embeddings-inference' routers.",
37+
),
38+
disabled=(RoutersState.entity.type != "text-embeddings-inference")
39+
| (RoutersState.entity.is_default is None)
40+
| ((RoutersState.default_vector_store_router.bool()) & (RoutersState.default_vector_store_router.id != RoutersState.entity.id)),
3341
),
3442
width="100%",
3543
),
@@ -108,11 +116,16 @@ def router_create_form_fields() -> rx.Component:
108116
),
109117
entity_form_checkbox_field(
110118
label="Set as default vector store router",
111-
value=RoutersState.entity_to_create.is_default_vector_store,
112-
on_change=lambda value: RoutersState.set_new_entity_attribut("is_default_vector_store", value),
113-
tooltip="Set as default vector store router. This option is only available for type 'text-embeddings-inference' routers.",
119+
value=(RoutersState.entity_to_create.is_default & (RoutersState.entity_to_create.type == "text-embeddings-inference")),
120+
on_change=lambda value: RoutersState.set_new_entity_attribut("is_default", value),
121+
tooltip=rx.cond(
122+
(RoutersState.entity_to_create.type == "text-embeddings-inference") & (RoutersState.default_vector_store_router.bool()),
123+
"Another router is already set as default vector store. Please uncheck it explicitly before checking this one.",
124+
"Set as default vector store router. This option is only available for type 'text-embeddings-inference' routers.",
125+
),
114126
disabled=(RoutersState.entity_to_create.type != "text-embeddings-inference")
115-
| (RoutersState.entity_to_create.is_default_vector_store is None),
127+
| (RoutersState.entity_to_create.is_default is None)
128+
| (RoutersState.default_vector_store_router.bool()),
116129
),
117130
width="100%",
118131
),

playground/app/features/routers/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Router(Entity):
1414
max_context_length: int | None = None
1515
cost_prompt_tokens: float | None = None
1616
cost_completion_tokens: float | None = None
17+
is_default: bool | None = None
1718
providers: int | None = None
1819
created: str | None = None
1920
updated: str | None = None
20-
is_default_vector_store: bool = False

playground/app/features/routers/state.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

playground/app/shared/components/forms.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def entity_form_select_field(
1212
value: str | None = None,
1313
on_change: Callable | None = None,
1414
disabled: bool = False,
15-
tooltip: str | None = None,
15+
tooltip: str | rx.Var | None = None,
1616
**kwargs,
1717
) -> rx.Component:
1818
return rx.vstack(
1919
rx.cond(
20-
bool(tooltip),
20+
tooltip,
2121
rx.hstack(
2222
rx.text(label, size=TEXT_SIZE_LABEL, weight="bold"),
2323
rx.tooltip(
@@ -46,12 +46,12 @@ def entity_form_input_field(
4646
label: str,
4747
value: str,
4848
on_change: Callable | None = None,
49-
tooltip: str | None = None,
49+
tooltip: str | rx.Var | None = None,
5050
**kwargs: Any,
5151
) -> rx.Component:
5252
return rx.vstack(
5353
rx.cond(
54-
bool(tooltip),
54+
tooltip,
5555
rx.hstack(
5656
rx.text(label, size=TEXT_SIZE_LABEL, weight="bold"),
5757
rx.tooltip(
@@ -77,9 +77,9 @@ def entity_form_input_field(
7777
def entity_form_checkbox_field(
7878
label: str,
7979
value: bool,
80-
description: str | None = None,
80+
description: str | rx.Var | None = None,
8181
on_change: Callable | None = None,
82-
tooltip: str | None = None,
82+
tooltip: str | rx.Var | None = None,
8383
disabled: bool = False,
8484
**kwargs: Any,
8585
) -> rx.Component:
@@ -92,7 +92,7 @@ def entity_form_checkbox_field(
9292
),
9393
rx.vstack(
9494
rx.cond(
95-
bool(tooltip),
95+
tooltip,
9696
rx.hstack(
9797
rx.text(
9898
label,
@@ -115,7 +115,7 @@ def entity_form_checkbox_field(
115115
),
116116
),
117117
rx.cond(
118-
bool(description),
118+
description,
119119
rx.text(
120120
description,
121121
size=TEXT_SIZE_LABEL,

0 commit comments

Comments
 (0)