hammad-python 0.0.14__py3-none-any.whl → 0.0.16__py3-none-any.whl
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.
- hammad/__init__.py +177 -0
- hammad/{performance/imports.py → _internal.py} +7 -1
- hammad/cache/__init__.py +1 -1
- hammad/cli/__init__.py +3 -1
- hammad/cli/_runner.py +265 -0
- hammad/cli/animations.py +1 -1
- hammad/cli/plugins.py +133 -78
- hammad/cli/styles/__init__.py +1 -1
- hammad/cli/styles/utils.py +149 -3
- hammad/data/__init__.py +56 -29
- hammad/data/collections/__init__.py +27 -17
- hammad/data/collections/collection.py +205 -383
- hammad/data/collections/indexes/__init__.py +37 -0
- hammad/data/collections/indexes/qdrant/__init__.py +1 -0
- hammad/data/collections/indexes/qdrant/index.py +735 -0
- hammad/data/collections/indexes/qdrant/settings.py +94 -0
- hammad/data/collections/indexes/qdrant/utils.py +220 -0
- hammad/data/collections/indexes/tantivy/__init__.py +1 -0
- hammad/data/collections/indexes/tantivy/index.py +428 -0
- hammad/data/collections/indexes/tantivy/settings.py +51 -0
- hammad/data/collections/indexes/tantivy/utils.py +200 -0
- hammad/data/configurations/__init__.py +2 -2
- hammad/data/configurations/configuration.py +2 -2
- hammad/data/models/__init__.py +20 -9
- hammad/data/models/extensions/__init__.py +4 -0
- hammad/data/models/{pydantic → extensions/pydantic}/__init__.py +6 -19
- hammad/data/models/{pydantic → extensions/pydantic}/converters.py +143 -16
- hammad/data/models/{base/fields.py → fields.py} +1 -1
- hammad/data/models/{base/model.py → model.py} +1 -1
- hammad/data/models/{base/utils.py → utils.py} +1 -1
- hammad/data/sql/__init__.py +23 -0
- hammad/data/sql/database.py +578 -0
- hammad/data/sql/types.py +141 -0
- hammad/data/types/__init__.py +1 -3
- hammad/data/types/file.py +3 -3
- hammad/data/types/multimodal/__init__.py +2 -2
- hammad/data/types/multimodal/audio.py +2 -2
- hammad/data/types/multimodal/image.py +2 -2
- hammad/formatting/__init__.py +9 -27
- hammad/formatting/json/__init__.py +8 -2
- hammad/formatting/json/converters.py +7 -1
- hammad/formatting/text/__init__.py +1 -1
- hammad/formatting/yaml/__init__.py +1 -1
- hammad/genai/__init__.py +78 -0
- hammad/genai/agents/__init__.py +1 -0
- hammad/genai/agents/types/__init__.py +35 -0
- hammad/genai/agents/types/history.py +277 -0
- hammad/genai/agents/types/tool.py +490 -0
- hammad/genai/embedding_models/__init__.py +41 -0
- hammad/{ai/embeddings/client/litellm_embeddings_client.py → genai/embedding_models/embedding_model.py} +47 -142
- hammad/genai/embedding_models/embedding_model_name.py +77 -0
- hammad/genai/embedding_models/embedding_model_request.py +65 -0
- hammad/{ai/embeddings/types.py → genai/embedding_models/embedding_model_response.py} +3 -3
- hammad/genai/embedding_models/run.py +161 -0
- hammad/genai/language_models/__init__.py +35 -0
- hammad/genai/language_models/_streaming.py +622 -0
- hammad/genai/language_models/_types.py +276 -0
- hammad/genai/language_models/_utils/__init__.py +31 -0
- hammad/genai/language_models/_utils/_completions.py +131 -0
- hammad/genai/language_models/_utils/_messages.py +89 -0
- hammad/genai/language_models/_utils/_requests.py +202 -0
- hammad/genai/language_models/_utils/_structured_outputs.py +124 -0
- hammad/genai/language_models/language_model.py +734 -0
- hammad/genai/language_models/language_model_request.py +135 -0
- hammad/genai/language_models/language_model_response.py +219 -0
- hammad/genai/language_models/language_model_response_chunk.py +53 -0
- hammad/genai/language_models/run.py +530 -0
- hammad/genai/multimodal_models.py +48 -0
- hammad/genai/rerank_models.py +26 -0
- hammad/logging/__init__.py +1 -1
- hammad/logging/decorators.py +1 -1
- hammad/logging/logger.py +2 -2
- hammad/mcp/__init__.py +1 -1
- hammad/mcp/client/__init__.py +35 -0
- hammad/mcp/client/client.py +105 -4
- hammad/mcp/client/client_service.py +10 -3
- hammad/mcp/servers/__init__.py +24 -0
- hammad/{performance/runtime → runtime}/__init__.py +2 -2
- hammad/{performance/runtime → runtime}/decorators.py +1 -1
- hammad/{performance/runtime → runtime}/run.py +1 -1
- hammad/service/__init__.py +1 -1
- hammad/service/create.py +3 -8
- hammad/service/decorators.py +8 -8
- hammad/typing/__init__.py +28 -0
- hammad/web/__init__.py +3 -3
- hammad/web/http/client.py +1 -1
- hammad/web/models.py +53 -21
- hammad/web/search/client.py +99 -52
- hammad/web/utils.py +13 -13
- hammad_python-0.0.16.dist-info/METADATA +191 -0
- hammad_python-0.0.16.dist-info/RECORD +110 -0
- hammad/ai/__init__.py +0 -1
- hammad/ai/_utils.py +0 -142
- hammad/ai/completions/__init__.py +0 -45
- hammad/ai/completions/client.py +0 -684
- hammad/ai/completions/create.py +0 -710
- hammad/ai/completions/settings.py +0 -100
- hammad/ai/completions/types.py +0 -792
- hammad/ai/completions/utils.py +0 -486
- hammad/ai/embeddings/__init__.py +0 -35
- hammad/ai/embeddings/client/__init__.py +0 -1
- hammad/ai/embeddings/client/base_embeddings_client.py +0 -26
- hammad/ai/embeddings/client/fastembed_text_embeddings_client.py +0 -200
- hammad/ai/embeddings/create.py +0 -159
- hammad/data/collections/base_collection.py +0 -58
- hammad/data/collections/searchable_collection.py +0 -556
- hammad/data/collections/vector_collection.py +0 -596
- hammad/data/databases/__init__.py +0 -21
- hammad/data/databases/database.py +0 -902
- hammad/data/models/base/__init__.py +0 -35
- hammad/data/models/pydantic/models/__init__.py +0 -28
- hammad/data/models/pydantic/models/arbitrary_model.py +0 -46
- hammad/data/models/pydantic/models/cacheable_model.py +0 -79
- hammad/data/models/pydantic/models/fast_model.py +0 -318
- hammad/data/models/pydantic/models/function_model.py +0 -176
- hammad/data/models/pydantic/models/subscriptable_model.py +0 -63
- hammad/performance/__init__.py +0 -36
- hammad/py.typed +0 -0
- hammad_python-0.0.14.dist-info/METADATA +0 -70
- hammad_python-0.0.14.dist-info/RECORD +0 -99
- {hammad_python-0.0.14.dist-info → hammad_python-0.0.16.dist-info}/WHEEL +0 -0
- {hammad_python-0.0.14.dist-info → hammad_python-0.0.16.dist-info}/licenses/LICENSE +0 -0
hammad/cli/plugins.py
CHANGED
@@ -26,7 +26,13 @@ from typing import (
|
|
26
26
|
|
27
27
|
if TYPE_CHECKING:
|
28
28
|
from rich import get_console
|
29
|
-
from rich.console import
|
29
|
+
from rich.console import (
|
30
|
+
JustifyMethod,
|
31
|
+
OverflowMethod,
|
32
|
+
Console,
|
33
|
+
RenderableType,
|
34
|
+
)
|
35
|
+
from rich.panel import PaddingDimensions
|
30
36
|
from rich.prompt import Prompt, Confirm
|
31
37
|
from prompt_toolkit import prompt as pt_prompt
|
32
38
|
from prompt_toolkit.completion import WordCompleter
|
@@ -43,6 +49,7 @@ if TYPE_CHECKING:
|
|
43
49
|
CLIStyleType,
|
44
50
|
CLIStyleBackgroundType,
|
45
51
|
CLIStyleColorName,
|
52
|
+
CLIStyleBoxName,
|
46
53
|
)
|
47
54
|
from .styles.settings import (
|
48
55
|
CLIStyleRenderableSettings,
|
@@ -129,31 +136,6 @@ def _get_animation_classes():
|
|
129
136
|
return _IMPORT_CACHE["animations"]
|
130
137
|
|
131
138
|
|
132
|
-
@overload
|
133
|
-
def print(
|
134
|
-
*values: object,
|
135
|
-
sep: str = " ",
|
136
|
-
end: str = "\n",
|
137
|
-
file: Optional[IO[str]] = None,
|
138
|
-
flush: bool = False,
|
139
|
-
) -> None: ...
|
140
|
-
|
141
|
-
|
142
|
-
@overload
|
143
|
-
def print(
|
144
|
-
*values: object,
|
145
|
-
sep: str = " ",
|
146
|
-
end: str = "\n",
|
147
|
-
file: Optional[IO[str]] = None,
|
148
|
-
flush: bool = False,
|
149
|
-
style: "CLIStyleType | None" = None,
|
150
|
-
style_settings: "CLIStyleRenderableSettings | None" = None,
|
151
|
-
bg: "CLIStyleBackgroundType | None" = None,
|
152
|
-
bg_settings: "CLIStyleBackgroundSettings | None" = None,
|
153
|
-
live: "CLIStyleLiveSettings | int | None" = None,
|
154
|
-
) -> None: ...
|
155
|
-
|
156
|
-
|
157
139
|
def print(
|
158
140
|
*values: object,
|
159
141
|
sep: str = " ",
|
@@ -164,7 +146,21 @@ def print(
|
|
164
146
|
style_settings: "CLIStyleRenderableSettings | None" = None,
|
165
147
|
bg: "CLIStyleBackgroundType | None" = None,
|
166
148
|
bg_settings: "CLIStyleBackgroundSettings | None" = None,
|
149
|
+
justify: Optional["JustifyMethod"] = None,
|
150
|
+
overflow: Optional["OverflowMethod"] = None,
|
151
|
+
no_wrap: Optional[bool] = None,
|
152
|
+
emoji: Optional[bool] = None,
|
153
|
+
markup: Optional[bool] = None,
|
154
|
+
highlight: Optional[bool] = None,
|
155
|
+
width: Optional[int] = None,
|
156
|
+
height: Optional[int] = None,
|
157
|
+
border: Optional["CLIStyleBoxName"] = None,
|
158
|
+
padding: Optional["PaddingDimensions"] = None,
|
159
|
+
title: Optional[str] = None,
|
160
|
+
expand: Optional[bool] = None,
|
167
161
|
live: "CLIStyleLiveSettings | int | None" = None,
|
162
|
+
transient: bool = False,
|
163
|
+
new_line_start: bool = False,
|
168
164
|
) -> None:
|
169
165
|
"""
|
170
166
|
Stylized print function built with `rich`. This method maintains
|
@@ -181,7 +177,21 @@ def print(
|
|
181
177
|
style_settings : A dictionary of style settings to apply to the content.
|
182
178
|
bg : A color or box name to apply to the background.
|
183
179
|
bg_settings : A dictionary of background settings to apply to the content.
|
180
|
+
justify : Text justification method ("left", "center", "right", "full").
|
181
|
+
overflow : Text overflow method ("fold", "crop", "ellipsis", "ignore").
|
182
|
+
no_wrap : Disable text wrapping.
|
183
|
+
emoji : Enable/disable emoji rendering.
|
184
|
+
markup : Enable/disable Rich markup rendering.
|
185
|
+
highlight : Enable/disable automatic highlighting.
|
186
|
+
width : Override the width of the output.
|
187
|
+
height : Override the height of the output.
|
188
|
+
border : Border style for panel rendering.
|
189
|
+
padding : Padding dimensions for panel rendering.
|
190
|
+
title : Title for panel rendering.
|
191
|
+
expand : Whether to expand panel to full width.
|
184
192
|
live : A dictionary of live settings or an integer in seconds to run the print in a live renderable.
|
193
|
+
transient : Whether to clear the output after completion.
|
194
|
+
new_line_start : Start with a new line before printing.
|
185
195
|
|
186
196
|
NOTE: If `live` is set as an integer, transient is True.
|
187
197
|
|
@@ -199,6 +209,18 @@ def print(
|
|
199
209
|
and bg is None
|
200
210
|
and bg_settings is None
|
201
211
|
and live is None
|
212
|
+
and justify is None
|
213
|
+
and overflow is None
|
214
|
+
and no_wrap is None
|
215
|
+
and emoji is None
|
216
|
+
and markup is None
|
217
|
+
and highlight is None
|
218
|
+
and width is None
|
219
|
+
and height is None
|
220
|
+
and border is None
|
221
|
+
and padding is None
|
222
|
+
and title is None
|
223
|
+
and expand is None
|
202
224
|
):
|
203
225
|
builtins.print(*values, sep=sep, end=end, file=file, flush=flush)
|
204
226
|
return
|
@@ -214,6 +236,10 @@ def print(
|
|
214
236
|
style_settings=style_settings,
|
215
237
|
bg=bg,
|
216
238
|
bg_settings=bg_settings,
|
239
|
+
border=border,
|
240
|
+
padding=padding,
|
241
|
+
title=title,
|
242
|
+
expand=expand,
|
217
243
|
)
|
218
244
|
|
219
245
|
# Handle live rendering
|
@@ -235,7 +261,19 @@ def print(
|
|
235
261
|
get_console = _get_rich_console()
|
236
262
|
Console, _ = _get_rich_console_classes()
|
237
263
|
console = get_console() if file is None else Console(file=file)
|
238
|
-
console.print(
|
264
|
+
console.print(
|
265
|
+
styled_content,
|
266
|
+
end=end,
|
267
|
+
justify=justify,
|
268
|
+
overflow=overflow,
|
269
|
+
no_wrap=no_wrap,
|
270
|
+
emoji=emoji,
|
271
|
+
markup=markup,
|
272
|
+
highlight=highlight,
|
273
|
+
width=width,
|
274
|
+
height=height,
|
275
|
+
new_line_start=new_line_start,
|
276
|
+
)
|
239
277
|
else:
|
240
278
|
live_render(styled_content, live_settings)
|
241
279
|
else:
|
@@ -243,7 +281,19 @@ def print(
|
|
243
281
|
get_console = _get_rich_console()
|
244
282
|
Console, _ = _get_rich_console_classes()
|
245
283
|
console = get_console() if file is None else Console(file=file)
|
246
|
-
console.print(
|
284
|
+
console.print(
|
285
|
+
styled_content,
|
286
|
+
end=end,
|
287
|
+
justify=justify,
|
288
|
+
overflow=overflow,
|
289
|
+
no_wrap=no_wrap,
|
290
|
+
emoji=emoji,
|
291
|
+
markup=markup,
|
292
|
+
highlight=highlight,
|
293
|
+
width=width,
|
294
|
+
height=height,
|
295
|
+
new_line_start=new_line_start,
|
296
|
+
)
|
247
297
|
|
248
298
|
|
249
299
|
class InputError(Exception):
|
@@ -494,10 +544,6 @@ def _collect_fields_sequentially(schema: Any, console) -> Dict[str, Any]:
|
|
494
544
|
return result
|
495
545
|
|
496
546
|
|
497
|
-
@overload
|
498
|
-
def input(prompt: str = "") -> str: ...
|
499
|
-
|
500
|
-
|
501
547
|
@overload
|
502
548
|
def input(
|
503
549
|
prompt: str = "",
|
@@ -665,24 +711,20 @@ def animate(
|
|
665
711
|
renderable: "RenderableType | str",
|
666
712
|
type: Literal["flashing", "pulsing", "shaking", "typing", "spinning", "rainbow"],
|
667
713
|
duration: Optional[float] = None,
|
668
|
-
#
|
669
|
-
speed: float =
|
714
|
+
# Animation parameters (defaults are handled by the specific animation classes)
|
715
|
+
speed: Optional[float] = None,
|
670
716
|
colors: "Optional[List[CLIStyleColorName]]" = None,
|
671
|
-
on_color: "CLIStyleColorName" =
|
672
|
-
off_color: "CLIStyleColorName" =
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
# Shaking animation parameters
|
678
|
-
intensity: int = 1,
|
679
|
-
# Typing animation parameters
|
717
|
+
on_color: "Optional[CLIStyleColorName]" = None,
|
718
|
+
off_color: "Optional[CLIStyleColorName]" = None,
|
719
|
+
min_opacity: Optional[float] = None,
|
720
|
+
max_opacity: Optional[float] = None,
|
721
|
+
color: "Optional[CLIStyleColorName]" = None,
|
722
|
+
intensity: Optional[int] = None,
|
680
723
|
typing_speed: Optional[float] = None,
|
681
|
-
cursor: str =
|
682
|
-
show_cursor: bool =
|
683
|
-
# Spinning animation parameters
|
724
|
+
cursor: Optional[str] = None,
|
725
|
+
show_cursor: Optional[bool] = None,
|
684
726
|
frames: Optional[List[str]] = None,
|
685
|
-
prefix: bool =
|
727
|
+
prefix: Optional[bool] = None,
|
686
728
|
# Rich.Live parameters
|
687
729
|
refresh_rate: int = 20,
|
688
730
|
transient: bool = True,
|
@@ -697,19 +739,19 @@ def animate(
|
|
697
739
|
renderable: The object to animate (text, panel, etc.)
|
698
740
|
type: The type of animation to create
|
699
741
|
duration: Duration of the animation in seconds (defaults to 2.0)
|
700
|
-
speed: Animation speed (
|
701
|
-
colors: Color list (used by flashing, rainbow)
|
702
|
-
on_color: Color when flashing "on" (used by flashing)
|
703
|
-
off_color: Color when flashing "off" (used by flashing)
|
704
|
-
min_opacity: Minimum opacity for pulsing animation
|
705
|
-
max_opacity: Maximum opacity for pulsing animation
|
706
|
-
color: Color for pulsing animation
|
707
|
-
intensity: Shaking intensity for shaking animation
|
708
|
-
typing_speed: Speed for typing animation (used by typing)
|
709
|
-
cursor: Cursor character for typing animation (used by typing)
|
710
|
-
show_cursor: Whether to show cursor for typing animation (used by typing)
|
711
|
-
frames: Custom frames for spinning animation
|
712
|
-
prefix: Whether to show spinner as prefix for spinning animation
|
742
|
+
speed: Animation speed (defaults to the specific animation class's default)
|
743
|
+
colors: Color list (used by flashing, rainbow) (defaults to the specific animation class's default)
|
744
|
+
on_color: Color when flashing "on" (used by flashing) (defaults to the specific animation class's default)
|
745
|
+
off_color: Color when flashing "off" (used by flashing) (defaults to the specific animation class's default)
|
746
|
+
min_opacity: Minimum opacity for pulsing animation (defaults to the specific animation class's default)
|
747
|
+
max_opacity: Maximum opacity for pulsing animation (defaults to the specific animation class's default)
|
748
|
+
color: Color for pulsing animation (defaults to the specific animation class's default)
|
749
|
+
intensity: Shaking intensity for shaking animation (defaults to the specific animation class's default)
|
750
|
+
typing_speed: Speed for typing animation (used by typing) (defaults to the specific animation class's default)
|
751
|
+
cursor: Cursor character for typing animation (used by typing) (defaults to the specific animation class's default)
|
752
|
+
show_cursor: Whether to show cursor for typing animation (used by typing) (defaults to the specific animation class's default)
|
753
|
+
frames: Custom frames for spinning animation (defaults to the specific animation class's default)
|
754
|
+
prefix: Whether to show spinner as prefix for spinning animation (defaults to the specific animation class's default)
|
713
755
|
refresh_rate: Refresh rate per second for Live rendering
|
714
756
|
transient: Whether to clear animation after completion
|
715
757
|
auto_refresh: Whether to auto-refresh the display
|
@@ -728,45 +770,58 @@ def animate(
|
|
728
770
|
if type == "flashing":
|
729
771
|
animation = animations["CLIFlashingAnimation"](
|
730
772
|
renderable,
|
731
|
-
speed=speed,
|
732
|
-
colors=colors,
|
733
|
-
on_color=on_color,
|
734
|
-
off_color=off_color,
|
735
|
-
duration=duration,
|
773
|
+
speed=speed if speed is not None else 0.5,
|
774
|
+
colors=colors, # Class handles default if None
|
775
|
+
on_color=on_color if on_color is not None else "white",
|
776
|
+
off_color=off_color if off_color is not None else "dim white",
|
777
|
+
duration=duration, # Base class handles default if None
|
736
778
|
)
|
737
779
|
elif type == "pulsing":
|
738
780
|
animation = animations["CLIPulsingAnimation"](
|
739
781
|
renderable,
|
740
|
-
speed=speed,
|
741
|
-
min_opacity=min_opacity,
|
742
|
-
max_opacity=max_opacity,
|
743
|
-
color=color,
|
744
|
-
duration=duration,
|
782
|
+
speed=speed if speed is not None else 2.0,
|
783
|
+
min_opacity=min_opacity if min_opacity is not None else 0.3,
|
784
|
+
max_opacity=max_opacity if max_opacity is not None else 1.0,
|
785
|
+
color=color if color is not None else "white",
|
786
|
+
duration=duration, # Base class handles default if None
|
745
787
|
)
|
746
788
|
elif type == "shaking":
|
747
789
|
animation = animations["CLIShakingAnimation"](
|
748
|
-
renderable,
|
790
|
+
renderable,
|
791
|
+
intensity=intensity if intensity is not None else 1,
|
792
|
+
speed=speed if speed is not None else 0.1,
|
793
|
+
duration=duration, # Base class handles default if None
|
749
794
|
)
|
750
795
|
elif type == "typing":
|
796
|
+
# Note: CLITypingAnimation expects 'text', assuming renderable is a string here.
|
751
797
|
animation = animations["CLITypingAnimation"](
|
752
798
|
renderable,
|
753
|
-
speed=speed,
|
754
|
-
typing_speed=typing_speed,
|
755
|
-
cursor=cursor,
|
756
|
-
show_cursor=show_cursor,
|
757
|
-
duration=duration,
|
799
|
+
speed=speed if speed is not None else 0.05, # Pass animate's speed, using CLITypingAnimation's speed default
|
800
|
+
typing_speed=typing_speed, # Pass animate's typing_speed, CLITypingAnimation handles its None default
|
801
|
+
cursor=cursor if cursor is not None else "█",
|
802
|
+
show_cursor=show_cursor if show_cursor is not None else True,
|
803
|
+
duration=duration, # Base class handles default if None
|
758
804
|
)
|
759
805
|
elif type == "spinning":
|
760
806
|
animation = animations["CLISpinningAnimation"](
|
761
|
-
renderable,
|
807
|
+
renderable,
|
808
|
+
frames=frames, # Class handles default if None
|
809
|
+
speed=speed if speed is not None else 0.1,
|
810
|
+
prefix=prefix if prefix is not None else True,
|
811
|
+
duration=duration, # Base class handles default if None
|
762
812
|
)
|
763
813
|
elif type == "rainbow":
|
764
814
|
animation = animations["CLIRainbowAnimation"](
|
765
|
-
renderable,
|
815
|
+
renderable,
|
816
|
+
speed=speed if speed is not None else 0.5,
|
817
|
+
colors=colors, # Class handles default if None
|
818
|
+
duration=duration, # Base class handles default if None
|
766
819
|
)
|
767
820
|
else:
|
768
821
|
raise ValueError(f"Unknown animation type: {type}")
|
769
822
|
|
823
|
+
# The animation object's animate method handles its own duration default
|
824
|
+
# and the Live parameters are passed directly from the function args
|
770
825
|
animation.animate(
|
771
826
|
duration=duration,
|
772
827
|
refresh_rate=refresh_rate,
|
hammad/cli/styles/__init__.py
CHANGED
@@ -5,7 +5,7 @@ styling rendered content in the CLI. Most resources within this
|
|
5
5
|
submodule are not meant for direct use."""
|
6
6
|
|
7
7
|
from typing import TYPE_CHECKING
|
8
|
-
from ...
|
8
|
+
from ..._internal import create_getattr_importer
|
9
9
|
|
10
10
|
if TYPE_CHECKING:
|
11
11
|
from .settings import (
|
hammad/cli/styles/utils.py
CHANGED
@@ -119,6 +119,10 @@ def style_renderable(
|
|
119
119
|
style_settings: CLIStyleRenderableSettings | None = None,
|
120
120
|
bg: CLIStyleBackgroundType | None = None,
|
121
121
|
bg_settings: CLIStyleBackgroundSettings | None = None,
|
122
|
+
border = None,
|
123
|
+
padding = None,
|
124
|
+
title: str | None = None,
|
125
|
+
expand: bool | None = None,
|
122
126
|
):
|
123
127
|
"""Styles a renderable with a rich string tag or settings.
|
124
128
|
|
@@ -128,6 +132,10 @@ def style_renderable(
|
|
128
132
|
style_settings : The settings to apply to the renderable.
|
129
133
|
bg : The rich string tag to apply to the background.
|
130
134
|
bg_settings : The settings to apply to the background.
|
135
|
+
border : Border style for panel rendering.
|
136
|
+
padding : Padding dimensions for panel rendering.
|
137
|
+
title : Title for panel rendering.
|
138
|
+
expand : Whether to expand panel to full width.
|
131
139
|
"""
|
132
140
|
|
133
141
|
try:
|
@@ -309,8 +317,8 @@ def style_renderable(
|
|
309
317
|
# Fallback to original renderable if dict processing fails
|
310
318
|
styled_renderable = r
|
311
319
|
|
312
|
-
# Handle background settings (from bg or bg_settings parameter)
|
313
|
-
if bg or bg_settings:
|
320
|
+
# Handle background settings (from bg or bg_settings parameter) or panel parameters
|
321
|
+
if bg or bg_settings or border or padding or title or expand:
|
314
322
|
try:
|
315
323
|
if bg_settings:
|
316
324
|
# Full background configuration
|
@@ -375,6 +383,48 @@ def style_renderable(
|
|
375
383
|
except Exception:
|
376
384
|
# Skip property if processing fails
|
377
385
|
continue
|
386
|
+
|
387
|
+
# Handle direct panel parameters
|
388
|
+
if title is not None:
|
389
|
+
panel_kwargs["title"] = title
|
390
|
+
if padding is not None:
|
391
|
+
panel_kwargs["padding"] = padding
|
392
|
+
if expand is not None:
|
393
|
+
panel_kwargs["expand"] = expand
|
394
|
+
if border is not None:
|
395
|
+
try:
|
396
|
+
from rich import box as rich_box_module
|
397
|
+
box_map = {
|
398
|
+
"ascii": rich_box_module.ASCII,
|
399
|
+
"ascii2": rich_box_module.ASCII2,
|
400
|
+
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
401
|
+
"square": rich_box_module.SQUARE,
|
402
|
+
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
403
|
+
"minimal": rich_box_module.MINIMAL,
|
404
|
+
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
405
|
+
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
406
|
+
"simple": rich_box_module.SIMPLE,
|
407
|
+
"simple_head": rich_box_module.SIMPLE_HEAD,
|
408
|
+
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
409
|
+
"horizontals": rich_box_module.HORIZONTALS,
|
410
|
+
"rounded": rich_box_module.ROUNDED,
|
411
|
+
"heavy": rich_box_module.HEAVY,
|
412
|
+
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
413
|
+
"heavy_head": rich_box_module.HEAVY_HEAD,
|
414
|
+
"double": rich_box_module.DOUBLE,
|
415
|
+
"double_edge": rich_box_module.DOUBLE_EDGE,
|
416
|
+
"markdown": getattr(
|
417
|
+
rich_box_module,
|
418
|
+
"MARKDOWN",
|
419
|
+
rich_box_module.ROUNDED,
|
420
|
+
),
|
421
|
+
}
|
422
|
+
panel_kwargs["box"] = box_map.get(
|
423
|
+
border, rich_box_module.ROUNDED
|
424
|
+
)
|
425
|
+
except Exception:
|
426
|
+
# Use default box if box processing fails
|
427
|
+
pass
|
378
428
|
|
379
429
|
# Handle background style
|
380
430
|
if "style" in bg_settings:
|
@@ -463,11 +513,107 @@ def style_renderable(
|
|
463
513
|
elif bg:
|
464
514
|
# Simple background color (string from bg parameter)
|
465
515
|
try:
|
516
|
+
panel_kwargs = {}
|
466
517
|
bg_style = Style(bgcolor=bg)
|
467
|
-
|
518
|
+
panel_kwargs["style"] = bg_style
|
519
|
+
|
520
|
+
# Handle direct panel parameters even with simple bg
|
521
|
+
if title is not None:
|
522
|
+
panel_kwargs["title"] = title
|
523
|
+
if padding is not None:
|
524
|
+
panel_kwargs["padding"] = padding
|
525
|
+
if expand is not None:
|
526
|
+
panel_kwargs["expand"] = expand
|
527
|
+
if border is not None:
|
528
|
+
try:
|
529
|
+
from rich import box as rich_box_module
|
530
|
+
box_map = {
|
531
|
+
"ascii": rich_box_module.ASCII,
|
532
|
+
"ascii2": rich_box_module.ASCII2,
|
533
|
+
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
534
|
+
"square": rich_box_module.SQUARE,
|
535
|
+
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
536
|
+
"minimal": rich_box_module.MINIMAL,
|
537
|
+
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
538
|
+
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
539
|
+
"simple": rich_box_module.SIMPLE,
|
540
|
+
"simple_head": rich_box_module.SIMPLE_HEAD,
|
541
|
+
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
542
|
+
"horizontals": rich_box_module.HORIZONTALS,
|
543
|
+
"rounded": rich_box_module.ROUNDED,
|
544
|
+
"heavy": rich_box_module.HEAVY,
|
545
|
+
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
546
|
+
"heavy_head": rich_box_module.HEAVY_HEAD,
|
547
|
+
"double": rich_box_module.DOUBLE,
|
548
|
+
"double_edge": rich_box_module.DOUBLE_EDGE,
|
549
|
+
"markdown": getattr(
|
550
|
+
rich_box_module,
|
551
|
+
"MARKDOWN",
|
552
|
+
rich_box_module.ROUNDED,
|
553
|
+
),
|
554
|
+
}
|
555
|
+
panel_kwargs["box"] = box_map.get(
|
556
|
+
border, rich_box_module.ROUNDED
|
557
|
+
)
|
558
|
+
except Exception:
|
559
|
+
# Use default box if box processing fails
|
560
|
+
pass
|
561
|
+
|
562
|
+
return Panel(styled_renderable, **panel_kwargs)
|
468
563
|
except Exception:
|
469
564
|
# Fallback to styled renderable if panel creation fails
|
470
565
|
return styled_renderable
|
566
|
+
else:
|
567
|
+
# Handle panel parameters without background
|
568
|
+
if title is not None or padding is not None or expand is not None or border is not None:
|
569
|
+
try:
|
570
|
+
panel_kwargs = {}
|
571
|
+
|
572
|
+
if title is not None:
|
573
|
+
panel_kwargs["title"] = title
|
574
|
+
if padding is not None:
|
575
|
+
panel_kwargs["padding"] = padding
|
576
|
+
if expand is not None:
|
577
|
+
panel_kwargs["expand"] = expand
|
578
|
+
if border is not None:
|
579
|
+
try:
|
580
|
+
from rich import box as rich_box_module
|
581
|
+
box_map = {
|
582
|
+
"ascii": rich_box_module.ASCII,
|
583
|
+
"ascii2": rich_box_module.ASCII2,
|
584
|
+
"ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
|
585
|
+
"square": rich_box_module.SQUARE,
|
586
|
+
"square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
|
587
|
+
"minimal": rich_box_module.MINIMAL,
|
588
|
+
"minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
|
589
|
+
"minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
|
590
|
+
"simple": rich_box_module.SIMPLE,
|
591
|
+
"simple_head": rich_box_module.SIMPLE_HEAD,
|
592
|
+
"simple_heavy": rich_box_module.SIMPLE_HEAVY,
|
593
|
+
"horizontals": rich_box_module.HORIZONTALS,
|
594
|
+
"rounded": rich_box_module.ROUNDED,
|
595
|
+
"heavy": rich_box_module.HEAVY,
|
596
|
+
"heavy_edge": rich_box_module.HEAVY_EDGE,
|
597
|
+
"heavy_head": rich_box_module.HEAVY_HEAD,
|
598
|
+
"double": rich_box_module.DOUBLE,
|
599
|
+
"double_edge": rich_box_module.DOUBLE_EDGE,
|
600
|
+
"markdown": getattr(
|
601
|
+
rich_box_module,
|
602
|
+
"MARKDOWN",
|
603
|
+
rich_box_module.ROUNDED,
|
604
|
+
),
|
605
|
+
}
|
606
|
+
panel_kwargs["box"] = box_map.get(
|
607
|
+
border, rich_box_module.ROUNDED
|
608
|
+
)
|
609
|
+
except Exception:
|
610
|
+
# Use default box if box processing fails
|
611
|
+
pass
|
612
|
+
|
613
|
+
return Panel(styled_renderable, **panel_kwargs)
|
614
|
+
except Exception:
|
615
|
+
# Fallback to styled renderable if panel creation fails
|
616
|
+
return styled_renderable
|
471
617
|
except Exception:
|
472
618
|
# Skip background processing if it fails
|
473
619
|
pass
|
hammad/data/__init__.py
CHANGED
@@ -1,9 +1,38 @@
|
|
1
1
|
"""hammad.data"""
|
2
2
|
|
3
3
|
from typing import TYPE_CHECKING
|
4
|
-
from ..
|
4
|
+
from .._internal import create_getattr_importer
|
5
5
|
|
6
6
|
if TYPE_CHECKING:
|
7
|
+
from .types import (
|
8
|
+
BaseText,
|
9
|
+
Text,
|
10
|
+
)
|
11
|
+
from .models import (
|
12
|
+
Model,
|
13
|
+
model_settings,
|
14
|
+
field,
|
15
|
+
validator,
|
16
|
+
is_field,
|
17
|
+
is_model,
|
18
|
+
convert_to_pydantic_model,
|
19
|
+
convert_to_pydantic_field,
|
20
|
+
is_pydantic_model_class,
|
21
|
+
)
|
22
|
+
from .collections import (
|
23
|
+
Collection,
|
24
|
+
TantivyCollectionIndex,
|
25
|
+
QdrantCollectionIndex,
|
26
|
+
TantivyCollectionIndexSettings,
|
27
|
+
TantivyCollectionIndexQuerySettings,
|
28
|
+
QdrantCollectionIndexSettings,
|
29
|
+
QdrantCollectionIndexQuerySettings,
|
30
|
+
)
|
31
|
+
from .sql import (
|
32
|
+
DatabaseItemType,
|
33
|
+
DatabaseItem,
|
34
|
+
Database,
|
35
|
+
)
|
7
36
|
from .configurations import (
|
8
37
|
Configuration,
|
9
38
|
read_configuration_from_file,
|
@@ -12,39 +41,37 @@ if TYPE_CHECKING:
|
|
12
41
|
read_configuration_from_os_prefix,
|
13
42
|
read_configuration_from_dotenv,
|
14
43
|
)
|
15
|
-
from .collections import (
|
16
|
-
Collection,
|
17
|
-
BaseCollection,
|
18
|
-
VectorCollection,
|
19
|
-
VectorCollectionSettings,
|
20
|
-
SearchableCollection,
|
21
|
-
SearchableCollectionSettings,
|
22
|
-
create_collection,
|
23
|
-
)
|
24
|
-
from .databases import Database, create_database
|
25
44
|
|
26
45
|
|
27
46
|
__all__ = (
|
28
|
-
# hammad.data.
|
29
|
-
"
|
30
|
-
"
|
31
|
-
|
32
|
-
|
33
|
-
"
|
34
|
-
"
|
47
|
+
# hammad.data.types
|
48
|
+
"BaseText",
|
49
|
+
"Text",
|
50
|
+
|
51
|
+
# hammad.data.models
|
52
|
+
"Model",
|
53
|
+
"model_settings",
|
54
|
+
"field",
|
55
|
+
"validator",
|
56
|
+
"is_field",
|
57
|
+
"is_model",
|
35
58
|
|
36
59
|
# hammad.data.collections
|
37
60
|
"Collection",
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
|
45
|
-
# hammad.data.
|
61
|
+
"TantivyCollectionIndex",
|
62
|
+
"QdrantCollectionIndex",
|
63
|
+
"TantivyCollectionIndexSettings",
|
64
|
+
"TantivyCollectionIndexQuerySettings",
|
65
|
+
"QdrantCollectionIndexSettings",
|
66
|
+
"QdrantCollectionIndexQuerySettings",
|
67
|
+
|
68
|
+
# hammad.data.sql
|
69
|
+
"DatabaseItemType",
|
70
|
+
"DatabaseItem",
|
46
71
|
"Database",
|
47
|
-
|
72
|
+
|
73
|
+
# hammad.data.configurations
|
74
|
+
"Configuration",
|
48
75
|
)
|
49
76
|
|
50
77
|
|
@@ -52,5 +79,5 @@ __getattr__ = create_getattr_importer(__all__)
|
|
52
79
|
|
53
80
|
|
54
81
|
def __dir__() -> list[str]:
|
55
|
-
"""Get the attributes of the data module."""
|
56
|
-
return list(__all__)
|
82
|
+
"""Get the attributes of the hammad.data module."""
|
83
|
+
return list(__all__)
|