hammad-python 0.0.24__tar.gz → 0.0.26__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.
- {hammad_python-0.0.24 → hammad_python-0.0.26}/PKG-INFO +2 -1
- hammad_python-0.0.26/hammad/__init__.py +84 -0
- hammad_python-0.0.26/hammad/_main.py +226 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/__init__.py +0 -2
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/__init__.py +4 -5
- hammad_python-0.0.26/hammad/data/types/__init__.py +75 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/types/file.py +74 -1
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/types/multimodal/__init__.py +14 -2
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/types/multimodal/audio.py +106 -2
- hammad_python-0.0.26/hammad/data/types/multimodal/image.py +182 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/types/text.py +242 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/__init__.py +22 -0
- hammad_python-0.0.26/hammad/genai/a2a/__init__.py +32 -0
- hammad_python-0.0.26/hammad/genai/a2a/workers.py +552 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/__init__.py +2 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/agent.py +115 -9
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/run.py +379 -8
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/graphs/__init__.py +13 -1
- hammad_python-0.0.26/hammad/genai/graphs/_utils.py +190 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/graphs/base.py +850 -125
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/graphs/types.py +2 -2
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/__init__.py +6 -1
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/run.py +308 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_response.py +2 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/logging/logger.py +53 -8
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/__init__.py +3 -0
- hammad_python-0.0.26/hammad/types.py +288 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/mkdocs.yml +2 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/pyproject.toml +2 -1
- {hammad_python-0.0.24 → hammad_python-0.0.26}/uv.lock +30 -1
- hammad_python-0.0.24/hammad/__init__.py +0 -303
- hammad_python-0.0.24/hammad/cli/_runner.py +0 -265
- hammad_python-0.0.24/hammad/data/types/__init__.py +0 -39
- hammad_python-0.0.24/hammad/data/types/multimodal/image.py +0 -80
- {hammad_python-0.0.24 → hammad_python-0.0.26}/.gitignore +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/LICENSE +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/README.md +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/_internal.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cache/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cache/base_cache.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cache/cache.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cache/decorators.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cache/file_cache.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cache/ttl_cache.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/animations.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/plugins.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/styles/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/styles/settings.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/styles/types.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/cli/styles/utils.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/collection.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/qdrant/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/qdrant/index.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/qdrant/settings.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/qdrant/utils.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/tantivy/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/tantivy/index.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/tantivy/settings.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/collections/indexes/tantivy/utils.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/configurations/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/configurations/configuration.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/extensions/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/extensions/pydantic/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/extensions/pydantic/converters.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/fields.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/model.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/models/utils.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/sql/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/sql/database.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/data/sql/types.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/json/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/json/converters.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/text/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/text/converters.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/text/markdown.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/yaml/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/formatting/yaml/converters.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/agent_context.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/agent_event.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/agent_hooks.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/agent_messages.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/agent_response.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/agents/types/agent_stream.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/graphs/plugins.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/model.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/run.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/types/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/types/embedding_model_name.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/types/embedding_model_response.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/types/embedding_model_run_params.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/embeddings/types/embedding_model_settings.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/model.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_instructor_mode.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_messages.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_name.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_request.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_response_chunk.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_settings.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/types/language_model_stream.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/utils/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/utils/requests.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/language/utils/structured_outputs.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/model_provider.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/multimodal.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/models/reranking.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/types/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/types/base.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/types/history.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/genai/types/tools.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/logging/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/logging/decorators.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/client/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/client/client.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/client/client_service.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/client/settings.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/servers/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/mcp/servers/launcher.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/py.typed +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/runtime/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/runtime/decorators.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/runtime/run.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/service/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/service/create.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/service/decorators.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/typing/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/http/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/http/client.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/models.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/openapi/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/openapi/client.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/search/__init__.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/search/client.py +0 -0
- {hammad_python-0.0.24 → hammad_python-0.0.26}/hammad/web/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hammad-python
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.26
|
4
4
|
Author-email: Hammad Saeed <hammadaidev@gmail.com>
|
5
5
|
License: MIT License
|
6
6
|
|
@@ -26,6 +26,7 @@ License: MIT License
|
|
26
26
|
License-File: LICENSE
|
27
27
|
Requires-Python: >=3.11
|
28
28
|
Requires-Dist: ddgs>=9.0.0
|
29
|
+
Requires-Dist: fasta2a>=0.5.0
|
29
30
|
Requires-Dist: httpx>=0.28.1
|
30
31
|
Requires-Dist: msgspec>=0.19.0
|
31
32
|
Requires-Dist: nest-asyncio>=1.6.0
|
@@ -0,0 +1,84 @@
|
|
1
|
+
"""hammad-python
|
2
|
+
|
3
|
+
A vast ecosystem of ('nightly', dont trust literally any interface to stay the same
|
4
|
+
for more than a few days) resources, utilities and components for building applications
|
5
|
+
in Python."""
|
6
|
+
|
7
|
+
from typing import TYPE_CHECKING
|
8
|
+
from ._internal import create_getattr_importer as __hammad_importer__
|
9
|
+
|
10
|
+
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from . import types
|
13
|
+
|
14
|
+
# 'builtins'
|
15
|
+
from .cache import cached
|
16
|
+
from .cli import print, input, animate
|
17
|
+
from .genai import (
|
18
|
+
BaseGraph,
|
19
|
+
plugin,
|
20
|
+
action,
|
21
|
+
select,
|
22
|
+
agent_decorator as agent,
|
23
|
+
language_model_decorator as llm,
|
24
|
+
run_embedding_model as embedding,
|
25
|
+
define_tool as tool,
|
26
|
+
)
|
27
|
+
from .data.collections import create_collection as collection
|
28
|
+
from .formatting.text import convert_to_text as markdown
|
29
|
+
from .mcp import launch_mcp_servers
|
30
|
+
from .logging import create_logger as logger
|
31
|
+
from .service import serve, serve_mcp
|
32
|
+
from .web import (
|
33
|
+
run_web_search as web_search,
|
34
|
+
run_web_request as web_request,
|
35
|
+
)
|
36
|
+
|
37
|
+
from ._main import (
|
38
|
+
to,
|
39
|
+
run,
|
40
|
+
fn,
|
41
|
+
new,
|
42
|
+
read,
|
43
|
+
settings,
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
__all__ = (
|
48
|
+
# types
|
49
|
+
"types",
|
50
|
+
# -- 'builtins'
|
51
|
+
"cached",
|
52
|
+
"print",
|
53
|
+
"animate",
|
54
|
+
"input",
|
55
|
+
"llm",
|
56
|
+
"agent",
|
57
|
+
"embedding",
|
58
|
+
"tool",
|
59
|
+
"markdown",
|
60
|
+
"launch_mcp_servers",
|
61
|
+
"action",
|
62
|
+
"plugin",
|
63
|
+
"select",
|
64
|
+
"BaseGraph",
|
65
|
+
"collection",
|
66
|
+
"logger",
|
67
|
+
"serve",
|
68
|
+
"serve_mcp",
|
69
|
+
"web_search",
|
70
|
+
"web_request",
|
71
|
+
"to",
|
72
|
+
"run",
|
73
|
+
"fn",
|
74
|
+
"new",
|
75
|
+
"read",
|
76
|
+
"settings",
|
77
|
+
)
|
78
|
+
|
79
|
+
|
80
|
+
__getattr__ = __hammad_importer__(__all__)
|
81
|
+
|
82
|
+
|
83
|
+
def __dir__() -> list[str]:
|
84
|
+
return list(__all__)
|
@@ -0,0 +1,226 @@
|
|
1
|
+
"""hammad._main"""
|
2
|
+
|
3
|
+
|
4
|
+
class to:
|
5
|
+
"""Namespace for converters that can be used to convert objects to various formats.
|
6
|
+
|
7
|
+
The `to` class provides a collection of converters that can be used to convert objects
|
8
|
+
to various formats, such as pydantic models, text, markdown, json, and more.
|
9
|
+
"""
|
10
|
+
|
11
|
+
# ! CONVERTERS
|
12
|
+
from .data import (
|
13
|
+
convert_to_pydantic_field as pydantic_field,
|
14
|
+
convert_to_pydantic_model as pydantic_model,
|
15
|
+
)
|
16
|
+
from .data.types import (
|
17
|
+
convert_to_base_text as text,
|
18
|
+
convert_to_simple_text as simple_text,
|
19
|
+
convert_to_code_section as code_section,
|
20
|
+
convert_to_schema_section as schema_section,
|
21
|
+
convert_to_output_instructions as output_instructions,
|
22
|
+
)
|
23
|
+
from .formatting.json import (
|
24
|
+
convert_to_json_schema as json_schema,
|
25
|
+
)
|
26
|
+
from .formatting.text import (
|
27
|
+
convert_to_text as markdown,
|
28
|
+
)
|
29
|
+
|
30
|
+
|
31
|
+
class fn:
|
32
|
+
"""Namespace for decorators that can be used to modify functions, methods, and classes.
|
33
|
+
|
34
|
+
The `fn` class provides a collection of decorators that can be used to modify functions,
|
35
|
+
methods, and classes in various ways, such as caching results, tracing function calls,
|
36
|
+
and validating input parameters.
|
37
|
+
"""
|
38
|
+
|
39
|
+
# ! DECORATORS
|
40
|
+
from .cache import cached, auto_cached
|
41
|
+
from .logging import trace, trace_cls, trace_function, trace_http
|
42
|
+
from .data.models import validator
|
43
|
+
from .runtime import (
|
44
|
+
sequentialize_function as sequentialize,
|
45
|
+
parallelize_function as parallelize,
|
46
|
+
run_with_retry as retry,
|
47
|
+
)
|
48
|
+
from .service import serve, serve_mcp
|
49
|
+
|
50
|
+
|
51
|
+
class new:
|
52
|
+
"""Namespace for factory functions that create new objects, models, services, and clients.
|
53
|
+
|
54
|
+
The `new` class provides convenient access to a variety of factory functions for creating
|
55
|
+
commonly used objects in the hammad ecosystem, such as caches, collections, databases,
|
56
|
+
models, loggers, agents, services, and web clients.
|
57
|
+
|
58
|
+
Example usage:
|
59
|
+
cache = new.cache(...)
|
60
|
+
collection = new.collection(...)
|
61
|
+
model = new.model(...)
|
62
|
+
logger = new.logger(...)
|
63
|
+
agent = new.agent(...)
|
64
|
+
service = new.service(...)
|
65
|
+
http_client = new.http_client(...)
|
66
|
+
"""
|
67
|
+
|
68
|
+
# ! FACTORIES
|
69
|
+
from .cache import (
|
70
|
+
create_cache as cache,
|
71
|
+
)
|
72
|
+
from .data import (
|
73
|
+
create_collection as collection,
|
74
|
+
create_database as database,
|
75
|
+
create_model as model,
|
76
|
+
)
|
77
|
+
from .logging import create_logger as logger
|
78
|
+
from .genai import (
|
79
|
+
create_agent as agent,
|
80
|
+
create_embedding_model as embedding_model,
|
81
|
+
create_language_model as language_model,
|
82
|
+
)
|
83
|
+
from .service import (
|
84
|
+
create_service as service,
|
85
|
+
async_create_service as async_service,
|
86
|
+
)
|
87
|
+
from .mcp import (
|
88
|
+
MCPClient as mcp_client,
|
89
|
+
)
|
90
|
+
from .web import (
|
91
|
+
create_http_client as http_client,
|
92
|
+
create_openapi_client as openapi_client,
|
93
|
+
create_search_client as search_client,
|
94
|
+
)
|
95
|
+
|
96
|
+
|
97
|
+
class run:
|
98
|
+
"""Centeral namespace for 'one-off' runners, or functions that can be
|
99
|
+
executed directly, and standalone."""
|
100
|
+
|
101
|
+
# ! RUNNERS
|
102
|
+
from .genai import (
|
103
|
+
run_agent as agent,
|
104
|
+
run_agent_iter as agent_iter,
|
105
|
+
run_embedding_model as embedding_model,
|
106
|
+
run_image_edit_model as image_edit_model,
|
107
|
+
run_image_generation_model as image_generation_model,
|
108
|
+
run_image_variation_model as image_variation_model,
|
109
|
+
run_language_model as language_model,
|
110
|
+
run_reranking_model as reranking_model,
|
111
|
+
run_transcription_model as transcription_model,
|
112
|
+
run_tts_model as text_to_speech_model,
|
113
|
+
)
|
114
|
+
from .mcp import (
|
115
|
+
launch_mcp_servers as mcp_servers,
|
116
|
+
)
|
117
|
+
from .web import (
|
118
|
+
run_news_search as news_search,
|
119
|
+
run_web_search as web_search,
|
120
|
+
run_web_request as web_request,
|
121
|
+
)
|
122
|
+
|
123
|
+
|
124
|
+
class read:
|
125
|
+
"""Namespace for various resource, URL or other file-type readers."""
|
126
|
+
|
127
|
+
from .data.configurations import (
|
128
|
+
read_configuration_from_dotenv as configuration_from_dotenv,
|
129
|
+
read_configuration_from_file as configuration_from_file,
|
130
|
+
read_configuration_from_url as configuration_from_url,
|
131
|
+
read_configuration_from_os_prefix as configuration_from_os_prefix,
|
132
|
+
read_configuration_from_os_vars as configuration_from_os_vars,
|
133
|
+
)
|
134
|
+
from .data.types import (
|
135
|
+
read_file_from_bytes as file_from_bytes,
|
136
|
+
read_file_from_path as file_from_path,
|
137
|
+
read_file_from_url as file_from_url,
|
138
|
+
read_audio_from_path as audio_from_path,
|
139
|
+
read_audio_from_url as audio_from_url,
|
140
|
+
read_image_from_path as image_from_path,
|
141
|
+
read_image_from_url as image_from_url,
|
142
|
+
)
|
143
|
+
from .web import (
|
144
|
+
read_web_page as web_page,
|
145
|
+
read_web_pages as web_pages,
|
146
|
+
extract_web_page_links as extract_links,
|
147
|
+
)
|
148
|
+
|
149
|
+
|
150
|
+
class settings:
|
151
|
+
"""Namespace class for all settings definitions within the ecosystem. This is an
|
152
|
+
easy way to find the configuration settings for the component you are intending
|
153
|
+
to use."""
|
154
|
+
|
155
|
+
# NOTE:
|
156
|
+
# these are attached to the 'core/builtin' extensions imported at the very top
|
157
|
+
# hence the weird very very literal names
|
158
|
+
from .cli import (
|
159
|
+
CLIStyleLiveSettings as live,
|
160
|
+
CLIStyleBackgroundSettings as bg,
|
161
|
+
CLIStyleRenderableSettings as style,
|
162
|
+
)
|
163
|
+
|
164
|
+
from .data import (
|
165
|
+
QdrantCollectionIndexSettings as qdrant,
|
166
|
+
QdrantCollectionIndexQuerySettings as qdrant_query,
|
167
|
+
TantivyCollectionIndexSettings as tantivy,
|
168
|
+
TantivyCollectionIndexQuerySettings as tantivy_query,
|
169
|
+
)
|
170
|
+
from .logging.logger import LoggerLevelSettings as logger_level
|
171
|
+
from .genai import (
|
172
|
+
AgentSettings as agent,
|
173
|
+
LanguageModelSettings as language_model,
|
174
|
+
EmbeddingModelSettings as embedding_model,
|
175
|
+
)
|
176
|
+
from .mcp import (
|
177
|
+
MCPClientSseSettings as mcp_client_sse,
|
178
|
+
MCPClientStdioSettings as mcp_client_stdio,
|
179
|
+
MCPClientStreamableHttpSettings as mcp_client_streamable_http,
|
180
|
+
MCPServerSseSettings as mcp_server_sse,
|
181
|
+
MCPServerStdioSettings as mcp_server_stdio,
|
182
|
+
MCPServerStreamableHttpSettings as mcp_server_streamable_http,
|
183
|
+
)
|
184
|
+
|
185
|
+
|
186
|
+
__all__ = (
|
187
|
+
# hammad.cache
|
188
|
+
"cached",
|
189
|
+
# hammad.cli
|
190
|
+
"print",
|
191
|
+
"input",
|
192
|
+
"animate",
|
193
|
+
# hammad.logging
|
194
|
+
"logger",
|
195
|
+
# hammad.genai
|
196
|
+
"BaseGraph",
|
197
|
+
"plugin",
|
198
|
+
"action",
|
199
|
+
"agent",
|
200
|
+
"llm",
|
201
|
+
"tool",
|
202
|
+
# hammad.data.collections
|
203
|
+
"collection",
|
204
|
+
# hammad.formatting.text
|
205
|
+
"markdown",
|
206
|
+
# hammad.mcp
|
207
|
+
"launch_mcp_servers",
|
208
|
+
# hammad.service
|
209
|
+
"serve",
|
210
|
+
"serve_mcp",
|
211
|
+
# hammad.web
|
212
|
+
"web_search",
|
213
|
+
"web_request",
|
214
|
+
# hammad.to
|
215
|
+
"to",
|
216
|
+
# hammad.fn
|
217
|
+
"fn",
|
218
|
+
# hammad.new
|
219
|
+
"new",
|
220
|
+
# hammad.run
|
221
|
+
"run",
|
222
|
+
# hammad.read
|
223
|
+
"read",
|
224
|
+
# hammad.settings
|
225
|
+
"settings",
|
226
|
+
)
|
@@ -8,7 +8,6 @@ from .._internal import create_getattr_importer
|
|
8
8
|
|
9
9
|
if TYPE_CHECKING:
|
10
10
|
from .plugins import print, input, animate
|
11
|
-
from ._runner import CLIRunner
|
12
11
|
from .styles.settings import (
|
13
12
|
CLIStyleRenderableSettings,
|
14
13
|
CLIStyleBackgroundSettings,
|
@@ -20,7 +19,6 @@ __all__ = (
|
|
20
19
|
"print",
|
21
20
|
"input",
|
22
21
|
"animate",
|
23
|
-
"CLIRunner",
|
24
22
|
"CLIStyleRenderableSettings",
|
25
23
|
"CLIStyleBackgroundSettings",
|
26
24
|
"CLIStyleLiveSettings",
|
@@ -19,6 +19,7 @@ if TYPE_CHECKING:
|
|
19
19
|
convert_to_pydantic_field,
|
20
20
|
is_pydantic_model_class,
|
21
21
|
)
|
22
|
+
from .models.utils import create_model
|
22
23
|
from .collections import (
|
23
24
|
Collection,
|
24
25
|
create_collection,
|
@@ -29,11 +30,7 @@ if TYPE_CHECKING:
|
|
29
30
|
QdrantCollectionIndexSettings,
|
30
31
|
QdrantCollectionIndexQuerySettings,
|
31
32
|
)
|
32
|
-
from .sql import
|
33
|
-
DatabaseItemType,
|
34
|
-
DatabaseItem,
|
35
|
-
Database,
|
36
|
-
)
|
33
|
+
from .sql import DatabaseItemType, DatabaseItem, Database, create_database
|
37
34
|
from .configurations import (
|
38
35
|
Configuration,
|
39
36
|
read_configuration_from_file,
|
@@ -58,6 +55,7 @@ __all__ = (
|
|
58
55
|
"convert_to_pydantic_model",
|
59
56
|
"convert_to_pydantic_field",
|
60
57
|
"is_pydantic_model_class",
|
58
|
+
"create_model",
|
61
59
|
# hammad.data.collections
|
62
60
|
"Collection",
|
63
61
|
"create_collection",
|
@@ -71,6 +69,7 @@ __all__ = (
|
|
71
69
|
"DatabaseItemType",
|
72
70
|
"DatabaseItem",
|
73
71
|
"Database",
|
72
|
+
"create_database",
|
74
73
|
# hammad.data.configurations
|
75
74
|
"Configuration",
|
76
75
|
"read_configuration_from_file",
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"""hammad.data.types
|
2
|
+
|
3
|
+
Contains functional alias, or model-like objects that are meant to be used
|
4
|
+
by users as bases as well as for type hints. These objects define simple
|
5
|
+
interfaces for various types of common objects."""
|
6
|
+
|
7
|
+
from typing import TYPE_CHECKING
|
8
|
+
from ..._internal import create_getattr_importer
|
9
|
+
|
10
|
+
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from .text import (
|
13
|
+
BaseText,
|
14
|
+
Text,
|
15
|
+
SimpleText,
|
16
|
+
CodeSection,
|
17
|
+
SchemaSection,
|
18
|
+
OutputText,
|
19
|
+
convert_to_simple_text,
|
20
|
+
convert_to_output_text,
|
21
|
+
convert_to_output_instructions,
|
22
|
+
convert_to_code_section,
|
23
|
+
convert_to_schema_section,
|
24
|
+
convert_to_base_text,
|
25
|
+
)
|
26
|
+
from .file import (
|
27
|
+
File,
|
28
|
+
read_file_from_bytes,
|
29
|
+
read_file_from_path,
|
30
|
+
read_file_from_url,
|
31
|
+
)
|
32
|
+
from .multimodal import (
|
33
|
+
Audio,
|
34
|
+
Image,
|
35
|
+
read_audio_from_path,
|
36
|
+
read_audio_from_url,
|
37
|
+
read_image_from_path,
|
38
|
+
read_image_from_url,
|
39
|
+
)
|
40
|
+
|
41
|
+
|
42
|
+
__all__ = (
|
43
|
+
# hammad.data.types.text
|
44
|
+
"BaseText",
|
45
|
+
"Text",
|
46
|
+
"SimpleText",
|
47
|
+
"CodeSection",
|
48
|
+
"SchemaSection",
|
49
|
+
"OutputText",
|
50
|
+
"convert_to_simple_text",
|
51
|
+
"convert_to_output_text",
|
52
|
+
"convert_to_output_instructions",
|
53
|
+
"convert_to_code_section",
|
54
|
+
"convert_to_schema_section",
|
55
|
+
"convert_to_base_text",
|
56
|
+
# hammad.data.types.file
|
57
|
+
"File",
|
58
|
+
"read_file_from_bytes",
|
59
|
+
"read_file_from_path",
|
60
|
+
"read_file_from_url",
|
61
|
+
# hammad.data.types.multimodal
|
62
|
+
"Audio",
|
63
|
+
"Image",
|
64
|
+
"read_audio_from_path",
|
65
|
+
"read_audio_from_url",
|
66
|
+
"read_image_from_path",
|
67
|
+
"read_image_from_url",
|
68
|
+
)
|
69
|
+
|
70
|
+
|
71
|
+
__getattr__ = create_getattr_importer(__all__)
|
72
|
+
|
73
|
+
|
74
|
+
def __dir__() -> list[str]:
|
75
|
+
return list(__all__)
|
@@ -9,7 +9,13 @@ from urllib.parse import urlparse
|
|
9
9
|
from ..models.model import Model
|
10
10
|
from ..models.fields import field
|
11
11
|
|
12
|
-
__all__ = (
|
12
|
+
__all__ = (
|
13
|
+
"File",
|
14
|
+
"FileSource",
|
15
|
+
"read_file_from_path",
|
16
|
+
"read_file_from_url",
|
17
|
+
"read_file_from_bytes",
|
18
|
+
)
|
13
19
|
|
14
20
|
|
15
21
|
_FILE_SIGNATURES = {
|
@@ -356,3 +362,70 @@ class File(Model, kw_only=True, dict=True):
|
|
356
362
|
path=Path(name) if name else None,
|
357
363
|
),
|
358
364
|
)
|
365
|
+
|
366
|
+
|
367
|
+
def read_file_from_path(
|
368
|
+
path: str | Path,
|
369
|
+
*,
|
370
|
+
encoding: str | None = None,
|
371
|
+
) -> File:
|
372
|
+
"""Read a file from a filesystem path.
|
373
|
+
|
374
|
+
Args:
|
375
|
+
path: The path to the file to read.
|
376
|
+
encoding: Optional text encoding to use when reading the file.
|
377
|
+
If not provided, will attempt to detect automatically.
|
378
|
+
|
379
|
+
Returns:
|
380
|
+
A File instance containing the file data.
|
381
|
+
|
382
|
+
Raises:
|
383
|
+
FileNotFoundError: If the file does not exist.
|
384
|
+
PermissionError: If the file cannot be read due to permissions.
|
385
|
+
IsADirectoryError: If the path points to a directory.
|
386
|
+
"""
|
387
|
+
return File.from_path(path, encoding=encoding)
|
388
|
+
|
389
|
+
|
390
|
+
def read_file_from_url(
|
391
|
+
url: str,
|
392
|
+
*,
|
393
|
+
encoding: str | None = None,
|
394
|
+
timeout: float = 30.0,
|
395
|
+
) -> File:
|
396
|
+
"""Read a file from a URL.
|
397
|
+
|
398
|
+
Args:
|
399
|
+
url: The URL to fetch the file from.
|
400
|
+
encoding: Optional text encoding to use when reading the response.
|
401
|
+
If not provided, will attempt to detect automatically.
|
402
|
+
timeout: Request timeout in seconds. Defaults to 30.0.
|
403
|
+
|
404
|
+
Returns:
|
405
|
+
A File instance containing the downloaded data.
|
406
|
+
|
407
|
+
Raises:
|
408
|
+
httpx.RequestError: If the request fails.
|
409
|
+
httpx.HTTPStatusError: If the response has an error status code.
|
410
|
+
"""
|
411
|
+
return File.from_url(url, encoding=encoding, timeout=timeout)
|
412
|
+
|
413
|
+
|
414
|
+
def read_file_from_bytes(
|
415
|
+
data: bytes,
|
416
|
+
*,
|
417
|
+
type: str | None = None,
|
418
|
+
name: str | None = None,
|
419
|
+
) -> File:
|
420
|
+
"""Create a file from raw bytes data.
|
421
|
+
|
422
|
+
Args:
|
423
|
+
data: The bytes data to create the file from.
|
424
|
+
type: Optional MIME type of the data. If not provided,
|
425
|
+
will attempt to detect from content signatures.
|
426
|
+
name: Optional name for the file data.
|
427
|
+
|
428
|
+
Returns:
|
429
|
+
A File instance containing the bytes data.
|
430
|
+
"""
|
431
|
+
return File.from_bytes(data, type=type, name=name)
|
@@ -7,13 +7,25 @@ from typing import TYPE_CHECKING
|
|
7
7
|
from ...._internal import create_getattr_importer
|
8
8
|
|
9
9
|
if TYPE_CHECKING:
|
10
|
-
from .image import
|
11
|
-
|
10
|
+
from .image import (
|
11
|
+
Image,
|
12
|
+
read_image_from_path,
|
13
|
+
read_image_from_url,
|
14
|
+
)
|
15
|
+
from .audio import (
|
16
|
+
Audio,
|
17
|
+
read_audio_from_path,
|
18
|
+
read_audio_from_url,
|
19
|
+
)
|
12
20
|
|
13
21
|
|
14
22
|
__all__ = (
|
15
23
|
"Image",
|
16
24
|
"Audio",
|
25
|
+
"read_audio_from_path",
|
26
|
+
"read_audio_from_url",
|
27
|
+
"read_image_from_path",
|
28
|
+
"read_image_from_url",
|
17
29
|
)
|
18
30
|
|
19
31
|
|
@@ -1,12 +1,19 @@
|
|
1
1
|
"""hammad.data.types.multimodal.audio"""
|
2
2
|
|
3
3
|
import httpx
|
4
|
+
import mimetypes
|
5
|
+
from pathlib import Path
|
4
6
|
from typing import Self
|
5
7
|
|
6
|
-
from ...types.file import File, FileSource
|
8
|
+
from ...types.file import File, FileSource, _FILE_SIGNATURES
|
7
9
|
from ...models.fields import field
|
8
10
|
|
9
|
-
|
11
|
+
|
12
|
+
__all__ = (
|
13
|
+
"Audio",
|
14
|
+
"read_audio_from_path",
|
15
|
+
"read_audio_from_url",
|
16
|
+
)
|
10
17
|
|
11
18
|
|
12
19
|
class Audio(File):
|
@@ -94,3 +101,100 @@ class Audio(File):
|
|
94
101
|
size=size,
|
95
102
|
),
|
96
103
|
)
|
104
|
+
|
105
|
+
@classmethod
|
106
|
+
def from_path(
|
107
|
+
cls,
|
108
|
+
path: str | Path,
|
109
|
+
) -> Self:
|
110
|
+
"""Create an audio file from a file path.
|
111
|
+
|
112
|
+
Args:
|
113
|
+
path: The path to the audio file.
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
A new Audio instance.
|
117
|
+
|
118
|
+
Raises:
|
119
|
+
FileNotFoundError: If the file does not exist.
|
120
|
+
ValueError: If the file is not a valid audio file.
|
121
|
+
"""
|
122
|
+
path_obj = Path(path)
|
123
|
+
|
124
|
+
if not path_obj.exists():
|
125
|
+
raise FileNotFoundError(f"Audio file not found: {path}")
|
126
|
+
|
127
|
+
if not path_obj.is_file():
|
128
|
+
raise ValueError(f"Path is not a file: {path}")
|
129
|
+
|
130
|
+
# Read file data
|
131
|
+
data = path_obj.read_bytes()
|
132
|
+
|
133
|
+
# Determine MIME type
|
134
|
+
type = None
|
135
|
+
|
136
|
+
# Check file signature first
|
137
|
+
for signature, mime_type in _FILE_SIGNATURES.items():
|
138
|
+
if data.startswith(signature) and mime_type.startswith("audio/"):
|
139
|
+
type = mime_type
|
140
|
+
break
|
141
|
+
|
142
|
+
# Fall back to mimetypes module
|
143
|
+
if not type:
|
144
|
+
type, _ = mimetypes.guess_type(str(path))
|
145
|
+
|
146
|
+
# Validate it's an audio file
|
147
|
+
if type and not type.startswith("audio/"):
|
148
|
+
raise ValueError(f"File is not an audio file: {type}")
|
149
|
+
|
150
|
+
return cls(
|
151
|
+
data=data,
|
152
|
+
type=type,
|
153
|
+
source=FileSource(
|
154
|
+
is_file=True,
|
155
|
+
path=path_obj,
|
156
|
+
size=len(data),
|
157
|
+
),
|
158
|
+
)
|
159
|
+
|
160
|
+
|
161
|
+
def read_audio_from_url(
|
162
|
+
url: str,
|
163
|
+
*,
|
164
|
+
lazy: bool = True,
|
165
|
+
timeout: float = 30.0,
|
166
|
+
) -> Audio:
|
167
|
+
"""Download and create an audio file from a URL.
|
168
|
+
|
169
|
+
Args:
|
170
|
+
url: The URL to download from.
|
171
|
+
lazy: If True, defer loading content until needed.
|
172
|
+
timeout: Request timeout in seconds.
|
173
|
+
|
174
|
+
Returns:
|
175
|
+
A new Audio instance.
|
176
|
+
|
177
|
+
Raises:
|
178
|
+
httpx.RequestError: If the request fails.
|
179
|
+
httpx.HTTPStatusError: If the response has an error status code.
|
180
|
+
ValueError: If the URL does not point to an audio file.
|
181
|
+
"""
|
182
|
+
return Audio.from_url(url, lazy=lazy, timeout=timeout)
|
183
|
+
|
184
|
+
|
185
|
+
def read_audio_from_path(
|
186
|
+
path: str | Path,
|
187
|
+
) -> Audio:
|
188
|
+
"""Create an audio file from a file path.
|
189
|
+
|
190
|
+
Args:
|
191
|
+
path: The path to the audio file.
|
192
|
+
|
193
|
+
Returns:
|
194
|
+
A new Audio instance.
|
195
|
+
|
196
|
+
Raises:
|
197
|
+
FileNotFoundError: If the file does not exist.
|
198
|
+
ValueError: If the file is not a valid audio file.
|
199
|
+
"""
|
200
|
+
return Audio.from_path(path)
|