streambricks 0.1.2__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streambricks-0.1.2 → streambricks-0.2.1}/PKG-INFO +1 -1
- streambricks-0.2.1/src/streambricks/__init__.py +16 -0
- streambricks-0.2.1/src/streambricks/widgets/model_selector.py +80 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/src/streambricks/widgets/model_widget.py +9 -47
- {streambricks-0.1.2 → streambricks-0.2.1}/src/streambricks/widgets/type_helpers.py +8 -0
- streambricks-0.1.2/src/streambricks/__init__.py +0 -8
- {streambricks-0.1.2 → streambricks-0.2.1}/.copier-answers.yml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.github/FUNDING.yml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.github/copilot-instructions.md +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.github/dependabot.yml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.github/workflows/build.yml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.github/workflows/documentation.yml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.gitignore +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/.pre-commit-config.yaml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/LICENSE +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/README.md +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/docs/.empty +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/duties.py +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/mkdocs.yml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/overrides/_dummy.txt +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/pyproject.toml +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/src/streambricks/helpers.py +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/src/streambricks/py.typed +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/src/streambricks/widgets/__init__.py +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/src/streambricks/widgets/multi_select.py +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/tests/__init__.py +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/tests/conftest.py +0 -0
- {streambricks-0.1.2 → streambricks-0.2.1}/tests/test_widgets.py +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
__version__ = "0.2.1"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from streambricks.widgets.model_widget import render_model_form, render_model_readonly
|
|
5
|
+
from streambricks.widgets.multi_select import multiselect, MultiSelectItem
|
|
6
|
+
from streambricks.widgets.model_selector import model_selector
|
|
7
|
+
from streambricks.helpers import run
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"MultiSelectItem",
|
|
11
|
+
"model_selector",
|
|
12
|
+
"multiselect",
|
|
13
|
+
"render_model_form",
|
|
14
|
+
"render_model_readonly",
|
|
15
|
+
"run",
|
|
16
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Model selector component for streamlit applications."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
import streamlit as st
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from collections.abc import Sequence
|
|
12
|
+
|
|
13
|
+
from tokonomics.model_discovery import ModelInfo, ProviderType
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def model_selector(
|
|
17
|
+
*,
|
|
18
|
+
initial_model: str | None = None,
|
|
19
|
+
providers: Sequence[ProviderType] | None = None,
|
|
20
|
+
expanded: bool = True,
|
|
21
|
+
) -> ModelInfo | None:
|
|
22
|
+
"""Render a model selector with provider and model dropdowns.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
initial_model: Initial model name to select
|
|
26
|
+
providers: List of providers to show models from
|
|
27
|
+
expanded: Whether to expand the model details by default
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Selected model info or None if not selected
|
|
31
|
+
"""
|
|
32
|
+
from tokonomics.model_discovery import get_all_models_sync
|
|
33
|
+
|
|
34
|
+
models = get_all_models_sync(providers=providers)
|
|
35
|
+
available_providers = sorted({model.provider for model in models})
|
|
36
|
+
current_model = None
|
|
37
|
+
current_provider = None
|
|
38
|
+
if initial_model:
|
|
39
|
+
current_model = next(
|
|
40
|
+
(m for m in models if m.pydantic_ai_id == initial_model),
|
|
41
|
+
None,
|
|
42
|
+
)
|
|
43
|
+
if current_model:
|
|
44
|
+
current_provider = current_model.provider
|
|
45
|
+
|
|
46
|
+
if len(available_providers) > 1:
|
|
47
|
+
default_provider_idx = (
|
|
48
|
+
available_providers.index(current_provider)
|
|
49
|
+
if current_provider in available_providers
|
|
50
|
+
else 0
|
|
51
|
+
)
|
|
52
|
+
selected_provider = st.selectbox(
|
|
53
|
+
"Provider",
|
|
54
|
+
options=available_providers,
|
|
55
|
+
index=default_provider_idx,
|
|
56
|
+
)
|
|
57
|
+
else:
|
|
58
|
+
selected_provider = available_providers[0]
|
|
59
|
+
|
|
60
|
+
provider_models = [m for m in models if m.provider == selected_provider]
|
|
61
|
+
model_names = [m.name for m in provider_models]
|
|
62
|
+
default_model_idx = 0
|
|
63
|
+
if current_model and current_model.provider == selected_provider:
|
|
64
|
+
try:
|
|
65
|
+
default_model_idx = model_names.index(current_model.name)
|
|
66
|
+
except ValueError:
|
|
67
|
+
default_model_idx = 0
|
|
68
|
+
|
|
69
|
+
selected_name = st.selectbox("Model", options=model_names, index=default_model_idx)
|
|
70
|
+
selected_model = next((m for m in provider_models if m.name == selected_name), None)
|
|
71
|
+
if selected_model:
|
|
72
|
+
with st.expander("Model Details", expanded=expanded):
|
|
73
|
+
st.markdown(selected_model.format())
|
|
74
|
+
return selected_model
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
from streambricks.helpers import run
|
|
79
|
+
|
|
80
|
+
run(model_selector)
|
|
@@ -15,6 +15,7 @@ import streamlit as st
|
|
|
15
15
|
from streambricks.widgets.type_helpers import (
|
|
16
16
|
add_new_item,
|
|
17
17
|
create_default_instance,
|
|
18
|
+
get_description,
|
|
18
19
|
get_with_default,
|
|
19
20
|
is_dataclass_like,
|
|
20
21
|
is_literal_type,
|
|
@@ -515,32 +516,14 @@ def render_model_instance_field(
|
|
|
515
516
|
|
|
516
517
|
# Get field value and handle 'MISSING' with type-appropriate defaults
|
|
517
518
|
field_value = get_with_default(value, field_name, field)
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
field_help = None
|
|
521
|
-
if hasattr(field, "metadata") and "description" in field.metadata:
|
|
522
|
-
field_help = field.metadata["description"]
|
|
523
|
-
elif hasattr(field, "native_field") and hasattr(
|
|
524
|
-
field.native_field, "description"
|
|
525
|
-
):
|
|
526
|
-
field_help = field.native_field.description # type: ignore
|
|
527
|
-
|
|
528
|
-
# Extract field info
|
|
529
|
-
nested_field_info = {
|
|
530
|
-
"name": field_name,
|
|
531
|
-
"type": field.type,
|
|
532
|
-
}
|
|
533
|
-
|
|
519
|
+
field_help = get_description(field)
|
|
520
|
+
nested_field_info = {"name": field_name, "type": field.type}
|
|
534
521
|
if field_help:
|
|
535
522
|
nested_field_info["help"] = field_help
|
|
536
523
|
|
|
537
|
-
|
|
538
|
-
if hasattr(field, "native_field") and hasattr(
|
|
539
|
-
field.native_field, "json_schema_extra"
|
|
540
|
-
):
|
|
524
|
+
if hasattr(field.native_field, "json_schema_extra"):
|
|
541
525
|
nested_field_info.update(field.native_field.json_schema_extra or {}) # type: ignore
|
|
542
526
|
|
|
543
|
-
# Render the field
|
|
544
527
|
renderer = get_field_renderer(nested_field_info)
|
|
545
528
|
updated_value[field_name] = renderer(
|
|
546
529
|
key=f"{key}_{field_name}",
|
|
@@ -550,7 +533,6 @@ def render_model_instance_field(
|
|
|
550
533
|
**nested_field_info,
|
|
551
534
|
)
|
|
552
535
|
|
|
553
|
-
# Create a new instance with the updated values
|
|
554
536
|
return fieldz.replace(value, **updated_value)
|
|
555
537
|
except Exception as e: # noqa: BLE001
|
|
556
538
|
st.error(f"Error rendering nested model fields: {e!s}")
|
|
@@ -617,7 +599,7 @@ def get_field_renderer(field_info: dict[str, Any]) -> WidgetFunc[Any]: # noqa:
|
|
|
617
599
|
raise ValueError(error_msg)
|
|
618
600
|
|
|
619
601
|
|
|
620
|
-
def render_model_readonly(model_class, instance):
|
|
602
|
+
def render_model_readonly[T](model_class: type[T], instance: T | None = None):
|
|
621
603
|
"""Render a model in read-only mode using a clean label-based layout."""
|
|
622
604
|
if instance is None:
|
|
623
605
|
st.info("No data available")
|
|
@@ -631,19 +613,11 @@ def render_model_readonly(model_class, instance):
|
|
|
631
613
|
field_value = getattr(instance, field_name, None)
|
|
632
614
|
field_type = field.type
|
|
633
615
|
label = field_name.replace("_", " ").title()
|
|
634
|
-
description = None
|
|
635
|
-
if hasattr(field, "metadata") and "description" in field.metadata:
|
|
636
|
-
description = field.metadata["description"]
|
|
637
|
-
elif hasattr(field, "native_field") and hasattr(
|
|
638
|
-
field.native_field, "description"
|
|
639
|
-
):
|
|
640
|
-
description = field.native_field.description # type: ignore
|
|
641
|
-
|
|
642
616
|
render_field_readonly(
|
|
643
617
|
label=label,
|
|
644
618
|
value=field_value,
|
|
645
619
|
field_type=field_type,
|
|
646
|
-
description=
|
|
620
|
+
description=get_description(field),
|
|
647
621
|
key=f"ro_{field_name}",
|
|
648
622
|
)
|
|
649
623
|
|
|
@@ -736,26 +710,14 @@ def render_model_field(model_class, field_name, value=None, container=st):
|
|
|
736
710
|
|
|
737
711
|
# Extract field metadata
|
|
738
712
|
field_info = {"name": field.name, "type": field.type, "default": field.default}
|
|
739
|
-
if hasattr(field, "
|
|
740
|
-
field.native_field, "json_schema_extra"
|
|
741
|
-
):
|
|
713
|
+
if hasattr(field.native_field, "json_schema_extra"):
|
|
742
714
|
field_info.update(field.native_field.json_schema_extra or {}) # type: ignore
|
|
743
715
|
|
|
744
|
-
# Format label from field name
|
|
745
716
|
label = field_name.replace("_", " ").title()
|
|
746
|
-
|
|
747
|
-
# Get description for help tooltip
|
|
748
|
-
help_text = None
|
|
749
|
-
if hasattr(field, "metadata") and "description" in field.metadata:
|
|
750
|
-
help_text = field.metadata["description"]
|
|
751
|
-
elif hasattr(field, "native_field") and hasattr(field.native_field, "description"):
|
|
752
|
-
help_text = field.native_field.description # type: ignore
|
|
753
|
-
|
|
754
|
-
# Add help text to field info if available
|
|
717
|
+
help_text = get_description(field)
|
|
755
718
|
if help_text:
|
|
756
719
|
field_info["help"] = help_text
|
|
757
720
|
|
|
758
|
-
# Get renderer and render the field
|
|
759
721
|
renderer = get_field_renderer(field_info)
|
|
760
722
|
return renderer(
|
|
761
723
|
key=field_name,
|
|
@@ -799,7 +761,7 @@ def render_model_form(model_or_instance, *, readonly: bool = False) -> Any:
|
|
|
799
761
|
for field in fieldz.fields(model_class):
|
|
800
762
|
# Check if field has a category defined
|
|
801
763
|
category = "General"
|
|
802
|
-
if
|
|
764
|
+
if "category" in field.metadata:
|
|
803
765
|
category = field.metadata["category"]
|
|
804
766
|
|
|
805
767
|
if category not in field_groups:
|
|
@@ -171,6 +171,14 @@ def create_default_instance(model_class: type) -> Any:
|
|
|
171
171
|
return model_class(**default_values)
|
|
172
172
|
|
|
173
173
|
|
|
174
|
+
def get_description(field: fieldz.Field) -> str | None:
|
|
175
|
+
if "description" in field.metadata:
|
|
176
|
+
return field.metadata["description"]
|
|
177
|
+
if hasattr(field.native_field, "description"):
|
|
178
|
+
return field.native_field.description # type: ignore
|
|
179
|
+
return None
|
|
180
|
+
|
|
181
|
+
|
|
174
182
|
def add_new_item(items_list: list, item_type: Any) -> None:
|
|
175
183
|
"""Add a new item to a list based on its type."""
|
|
176
184
|
if is_dataclass_like(item_type):
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.2"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
from streambricks.widgets.model_widget import render_model_form
|
|
5
|
-
from streambricks.widgets.multi_select import multiselect, MultiSelectItem
|
|
6
|
-
from streambricks.helpers import run
|
|
7
|
-
|
|
8
|
-
__all__ = ["MultiSelectItem", "multiselect", "render_model_form", "run"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|