streambricks 0.1.1__tar.gz → 0.2.0__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.
Files changed (27) hide show
  1. {streambricks-0.1.1 → streambricks-0.2.0}/PKG-INFO +1 -1
  2. {streambricks-0.1.1 → streambricks-0.2.0}/src/streambricks/__init__.py +8 -8
  3. {streambricks-0.1.1 → streambricks-0.2.0}/src/streambricks/helpers.py +48 -48
  4. {streambricks-0.1.1 → streambricks-0.2.0}/src/streambricks/widgets/__init__.py +6 -6
  5. streambricks-0.2.0/src/streambricks/widgets/model_selector.py +97 -0
  6. {streambricks-0.1.1 → streambricks-0.2.0}/src/streambricks/widgets/model_widget.py +848 -1123
  7. {streambricks-0.1.1 → streambricks-0.2.0}/src/streambricks/widgets/multi_select.py +91 -91
  8. streambricks-0.2.0/src/streambricks/widgets/type_helpers.py +213 -0
  9. {streambricks-0.1.1 → streambricks-0.2.0}/tests/test_widgets.py +7 -7
  10. {streambricks-0.1.1 → streambricks-0.2.0}/.copier-answers.yml +0 -0
  11. {streambricks-0.1.1 → streambricks-0.2.0}/.github/FUNDING.yml +0 -0
  12. {streambricks-0.1.1 → streambricks-0.2.0}/.github/copilot-instructions.md +0 -0
  13. {streambricks-0.1.1 → streambricks-0.2.0}/.github/dependabot.yml +0 -0
  14. {streambricks-0.1.1 → streambricks-0.2.0}/.github/workflows/build.yml +0 -0
  15. {streambricks-0.1.1 → streambricks-0.2.0}/.github/workflows/documentation.yml +0 -0
  16. {streambricks-0.1.1 → streambricks-0.2.0}/.gitignore +0 -0
  17. {streambricks-0.1.1 → streambricks-0.2.0}/.pre-commit-config.yaml +0 -0
  18. {streambricks-0.1.1 → streambricks-0.2.0}/LICENSE +0 -0
  19. {streambricks-0.1.1 → streambricks-0.2.0}/README.md +0 -0
  20. {streambricks-0.1.1 → streambricks-0.2.0}/docs/.empty +0 -0
  21. {streambricks-0.1.1 → streambricks-0.2.0}/duties.py +0 -0
  22. {streambricks-0.1.1 → streambricks-0.2.0}/mkdocs.yml +0 -0
  23. {streambricks-0.1.1 → streambricks-0.2.0}/overrides/_dummy.txt +0 -0
  24. {streambricks-0.1.1 → streambricks-0.2.0}/pyproject.toml +0 -0
  25. {streambricks-0.1.1 → streambricks-0.2.0}/src/streambricks/py.typed +0 -0
  26. {streambricks-0.1.1 → streambricks-0.2.0}/tests/__init__.py +0 -0
  27. {streambricks-0.1.1 → streambricks-0.2.0}/tests/conftest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streambricks
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Streamlit widgets and helpers
5
5
  Project-URL: Documentation, https://phil65.github.io/streambricks/
6
6
  Project-URL: Source, https://github.com/phil65/streambricks
@@ -1,8 +1,8 @@
1
- __version__ = "0.1.1"
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"]
1
+ __version__ = "0.2.0"
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"]
@@ -1,48 +1,48 @@
1
- """Utility functions for Streamlit applications."""
2
-
3
- from __future__ import annotations
4
-
5
- import asyncio
6
- import inspect
7
- import sys
8
- from typing import TYPE_CHECKING, Any, TypeVar
9
-
10
- from streamlit import runtime
11
- from streamlit.web.cli import main
12
-
13
-
14
- if TYPE_CHECKING:
15
- from collections.abc import Callable, Coroutine
16
-
17
-
18
- T = TypeVar("T")
19
-
20
-
21
- def run(
22
- fn: Callable[..., T | Coroutine[Any, Any, T]] | Coroutine[Any, Any, T],
23
- *args: Any,
24
- **kwargs: Any,
25
- ) -> None:
26
- """Run a function or coroutine with Streamlit.
27
-
28
- If Streamlit runtime exists, execute the function directly. Otherwise,
29
- start Streamlit with the current script.
30
-
31
- Args:
32
- fn: The function or coroutine to run
33
- args: Positional arguments to pass to the function
34
- kwargs: Keyword arguments to pass to the function
35
- """
36
- if runtime.exists():
37
- if inspect.iscoroutine(fn):
38
- asyncio.run(fn)
39
- # Handle coroutine function
40
- elif inspect.iscoroutinefunction(fn):
41
- coro = fn(*args, **kwargs)
42
- asyncio.run(coro)
43
- # Handle regular function
44
- else:
45
- fn(*args, **kwargs) # type: ignore
46
- else:
47
- sys.argv = ["streamlit", "run", sys.argv[0]]
48
- sys.exit(main())
1
+ """Utility functions for Streamlit applications."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import inspect
7
+ import sys
8
+ from typing import TYPE_CHECKING, Any, TypeVar
9
+
10
+ from streamlit import runtime
11
+ from streamlit.web.cli import main
12
+
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Callable, Coroutine
16
+
17
+
18
+ T = TypeVar("T")
19
+
20
+
21
+ def run(
22
+ fn: Callable[..., T | Coroutine[Any, Any, T]] | Coroutine[Any, Any, T],
23
+ *args: Any,
24
+ **kwargs: Any,
25
+ ) -> None:
26
+ """Run a function or coroutine with Streamlit.
27
+
28
+ If Streamlit runtime exists, execute the function directly. Otherwise,
29
+ start Streamlit with the current script.
30
+
31
+ Args:
32
+ fn: The function or coroutine to run
33
+ args: Positional arguments to pass to the function
34
+ kwargs: Keyword arguments to pass to the function
35
+ """
36
+ if runtime.exists():
37
+ if inspect.iscoroutine(fn):
38
+ asyncio.run(fn)
39
+ # Handle coroutine function
40
+ elif inspect.iscoroutinefunction(fn):
41
+ coro = fn(*args, **kwargs)
42
+ asyncio.run(coro)
43
+ # Handle regular function
44
+ else:
45
+ fn(*args, **kwargs) # type: ignore
46
+ else:
47
+ sys.argv = ["streamlit", "run", sys.argv[0]]
48
+ sys.exit(main())
@@ -1,6 +1,6 @@
1
- """Streamlit widgets."""
2
-
3
- from streambricks.widgets.model_widget import render_model_form
4
- from streambricks.widgets.multi_select import multiselect
5
-
6
- __all__ = ["multiselect", "render_model_form"]
1
+ """Streamlit widgets."""
2
+
3
+ from streambricks.widgets.model_widget import render_model_form
4
+ from streambricks.widgets.multi_select import multiselect
5
+
6
+ __all__ = ["multiselect", "render_model_form"]
@@ -0,0 +1,97 @@
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
+
36
+ # Get unique providers from models
37
+ available_providers = sorted({model.provider for model in models})
38
+
39
+ # Get current model info to set initial selections
40
+ current_model = None
41
+ current_provider = None
42
+
43
+ if initial_model:
44
+ current_model = next(
45
+ (m for m in models if m.pydantic_ai_id == initial_model),
46
+ None,
47
+ )
48
+ if current_model:
49
+ current_provider = current_model.provider
50
+
51
+ # Provider selection
52
+ if len(available_providers) > 1:
53
+ default_provider_idx = (
54
+ available_providers.index(current_provider)
55
+ if current_provider in available_providers
56
+ else 0
57
+ )
58
+ selected_provider = st.selectbox(
59
+ "Provider",
60
+ options=available_providers,
61
+ index=default_provider_idx,
62
+ )
63
+ else:
64
+ selected_provider = available_providers[0]
65
+
66
+ provider_models = [m for m in models if m.provider == selected_provider]
67
+ model_names = [m.name for m in provider_models]
68
+
69
+ # Determine initial model index
70
+ default_model_idx = 0
71
+ if current_model and current_model.provider == selected_provider:
72
+ try:
73
+ default_model_idx = model_names.index(current_model.name)
74
+ except ValueError:
75
+ default_model_idx = 0
76
+
77
+ selected_name = st.selectbox(
78
+ "Model",
79
+ options=model_names,
80
+ index=default_model_idx,
81
+ )
82
+
83
+ selected_model = next(
84
+ (m for m in provider_models if m.name == selected_name),
85
+ None,
86
+ )
87
+
88
+ if selected_model:
89
+ with st.expander("Model Details", expanded=expanded):
90
+ st.markdown(selected_model.format())
91
+ return selected_model
92
+
93
+
94
+ if __name__ == "__main__":
95
+ from streambricks.helpers import run
96
+
97
+ run(model_selector)