hammad-python 0.0.13__tar.gz → 0.0.15__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.13 → hammad_python-0.0.15}/.gitignore +0 -1
- hammad_python-0.0.15/PKG-INFO +184 -0
- hammad_python-0.0.15/README.md +136 -0
- hammad_python-0.0.15/deprecated/hammad/__init__.py +1 -0
- hammad_python-0.0.15/deprecated/hammad/ai/__init__.py +1 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/completions/__init__.py +3 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/completions/client.py +84 -129
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/completions/create.py +33 -9
- hammad_python-0.0.15/deprecated/hammad/ai/completions/settings.py +100 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/completions/types.py +86 -5
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/completions/utils.py +112 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/client/fastembed_text_embeddings_client.py +1 -1
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/client/litellm_embeddings_client.py +1 -1
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/types.py +4 -4
- hammad_python-0.0.15/deprecated/hammad/cache/__init__.py +40 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/animations.py +8 -39
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/plugins.py +0 -4
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/styles/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/__init__.py +17 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/collections/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/collections/base_collection.py +1 -1
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/collections/collection.py +1 -1
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/collections/searchable_collection.py +8 -8
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/collections/vector_collection.py +0 -7
- {hammad_python-0.0.13/hammad/configuration → hammad_python-0.0.15/deprecated/hammad/data/configurations}/__init__.py +2 -2
- {hammad_python-0.0.13/hammad/configuration → hammad_python-0.0.15/deprecated/hammad/data/configurations}/configuration.py +1 -1
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/databases/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/data/databases/database.py +27 -13
- hammad_python-0.0.15/deprecated/hammad/data/models/__init__.py +33 -0
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/base/__init__.py +3 -3
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/__init__.py +28 -16
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/converters.py +11 -2
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/models/__init__.py +3 -3
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/models/arbitrary_model.py +1 -1
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/models/cacheable_model.py +1 -1
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/models/fast_model.py +1 -1
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/models/function_model.py +1 -1
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/pydantic/models/subscriptable_model.py +1 -1
- hammad_python-0.0.15/deprecated/hammad/data/types/__init__.py +39 -0
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data}/types/file.py +2 -2
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/types}/multimodal/__init__.py +2 -2
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/types}/multimodal/audio.py +2 -2
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/types}/multimodal/image.py +2 -2
- {hammad_python-0.0.13/hammad/text → hammad_python-0.0.15/deprecated/hammad/data/types}/text.py +4 -4
- hammad_python-0.0.15/deprecated/hammad/formatting/__init__.py +38 -0
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/formatting}/json/__init__.py +3 -3
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/formatting}/json/converters.py +2 -2
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/formatting}/text/__init__.py +5 -24
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/formatting}/text/converters.py +2 -2
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/formatting}/text/markdown.py +1 -1
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/formatting}/yaml/__init__.py +3 -7
- hammad_python-0.0.15/deprecated/hammad/formatting/yaml/converters.py +5 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/logging/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/logging/logger.py +2 -2
- hammad_python-0.0.15/deprecated/hammad/mcp/__init__.py +50 -0
- hammad_python-0.0.15/deprecated/hammad/mcp/client/__init__.py +1 -0
- hammad_python-0.0.15/deprecated/hammad/mcp/client/client.py +523 -0
- hammad_python-0.0.15/deprecated/hammad/mcp/client/client_service.py +393 -0
- hammad_python-0.0.15/deprecated/hammad/mcp/client/settings.py +178 -0
- hammad_python-0.0.15/deprecated/hammad/mcp/servers/__init__.py +1 -0
- hammad_python-0.0.15/deprecated/hammad/mcp/servers/launcher.py +1161 -0
- hammad_python-0.0.15/deprecated/hammad/performance/__init__.py +36 -0
- hammad_python-0.0.13/hammad/_core/_utils/_import_utils.py → hammad_python-0.0.15/deprecated/hammad/performance/imports.py +125 -76
- hammad_python-0.0.15/deprecated/hammad/performance/runtime/__init__.py +32 -0
- hammad_python-0.0.15/deprecated/hammad/performance/runtime/decorators.py +142 -0
- hammad_python-0.0.15/deprecated/hammad/performance/runtime/run.py +299 -0
- hammad_python-0.0.15/deprecated/hammad/service/__init__.py +49 -0
- hammad_python-0.0.15/deprecated/hammad/service/create.py +532 -0
- hammad_python-0.0.15/deprecated/hammad/service/decorators.py +285 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/__init__.py +2 -2
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/http/client.py +1 -1
- hammad_python-0.0.15/deprecated/hammad/web/openapi/__init__.py +1 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/ai/completions/test_ai_completions_create.py +4 -1
- hammad_python-0.0.13/tests/cache/test_cache_cache.py → hammad_python-0.0.15/deprecated/tests/cache/test_performance_cache.py +1 -1
- {hammad_python-0.0.13/tests/data → hammad_python-0.0.15/deprecated/tests/data/collections}/test_data_collections_searchable_collection.py +10 -10
- hammad_python-0.0.13/tests/base/test_base_fields.py → hammad_python-0.0.15/deprecated/tests/data/models/base/test_data_models_base_fields.py +3 -3
- hammad_python-0.0.13/tests/base/test_base_model.py → hammad_python-0.0.15/deprecated/tests/data/models/base/test_data_models_base_model.py +1 -1
- hammad_python-0.0.13/tests/pydantic/test_pydantic_converters.py → hammad_python-0.0.15/deprecated/tests/data/models/pydantic/test_models_pydantic_converters.py +37 -36
- hammad_python-0.0.13/tests/pydantic/test_pydantic_models.py → hammad_python-0.0.15/deprecated/tests/data/models/pydantic/test_models_pydantic_models.py +1 -1
- hammad_python-0.0.13/tests/text/test_text_text.py → hammad_python-0.0.15/deprecated/tests/data/types/test_data_types_text.py +1 -1
- {hammad_python-0.0.13/tests → hammad_python-0.0.15/deprecated/tests/formatting}/json/test_json_converters.py +1 -1
- {hammad_python-0.0.13/tests → hammad_python-0.0.15/deprecated/tests/formatting}/text/test_text_utils_converters.py +1 -1
- {hammad_python-0.0.13/tests → hammad_python-0.0.15/deprecated/tests/formatting}/text/test_text_utils_markdown_converters.py +1 -1
- hammad_python-0.0.15/deprecated/tests/mcp/test_mcp_client_services.py +404 -0
- hammad_python-0.0.15/deprecated/tests/mcp/test_mcp_server_services.py +555 -0
- hammad_python-0.0.15/deprecated/tests/performance/runtime/test_performance_runtime_decorators.py +66 -0
- hammad_python-0.0.15/deprecated/tests/performance/runtime/test_performance_runtime_run.py +98 -0
- hammad_python-0.0.15/deprecated/tests/service/test_service_create_service.py +177 -0
- hammad_python-0.0.15/deprecated/tests/service/test_service_serve_decorator.py +175 -0
- hammad_python-0.0.15/deprecated/tests/service/test_service_serve_mcp_decorator.py +204 -0
- hammad_python-0.0.15/hammad/__init__.py +178 -0
- hammad_python-0.0.15/hammad/_internal.py +237 -0
- hammad_python-0.0.15/hammad/cache/__init__.py +40 -0
- hammad_python-0.0.15/hammad/cache/base_cache.py +181 -0
- hammad_python-0.0.15/hammad/cache/cache.py +169 -0
- hammad_python-0.0.15/hammad/cache/decorators.py +261 -0
- hammad_python-0.0.15/hammad/cache/file_cache.py +80 -0
- hammad_python-0.0.15/hammad/cache/ttl_cache.py +74 -0
- hammad_python-0.0.15/hammad/cli/__init__.py +35 -0
- hammad_python-0.0.15/hammad/cli/_runner.py +265 -0
- hammad_python-0.0.15/hammad/cli/animations.py +573 -0
- hammad_python-0.0.15/hammad/cli/plugins.py +836 -0
- hammad_python-0.0.15/hammad/cli/styles/__init__.py +55 -0
- hammad_python-0.0.15/hammad/cli/styles/settings.py +139 -0
- hammad_python-0.0.15/hammad/cli/styles/types.py +358 -0
- hammad_python-0.0.15/hammad/cli/styles/utils.py +626 -0
- hammad_python-0.0.15/hammad/data/__init__.py +83 -0
- hammad_python-0.0.15/hammad/data/collections/__init__.py +44 -0
- hammad_python-0.0.15/hammad/data/collections/collection.py +260 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/__init__.py +37 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/qdrant/__init__.py +1 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/qdrant/index.py +539 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/qdrant/settings.py +94 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/qdrant/utils.py +220 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/tantivy/__init__.py +1 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/tantivy/index.py +428 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/tantivy/settings.py +51 -0
- hammad_python-0.0.15/hammad/data/collections/indexes/tantivy/utils.py +200 -0
- hammad_python-0.0.15/hammad/data/configurations/__init__.py +35 -0
- hammad_python-0.0.15/hammad/data/configurations/configuration.py +564 -0
- hammad_python-0.0.15/hammad/data/models/__init__.py +55 -0
- hammad_python-0.0.15/hammad/data/models/extensions/__init__.py +4 -0
- hammad_python-0.0.15/hammad/data/models/extensions/pydantic/__init__.py +42 -0
- hammad_python-0.0.15/hammad/data/models/extensions/pydantic/converters.py +759 -0
- hammad_python-0.0.15/hammad/data/models/fields.py +546 -0
- hammad_python-0.0.15/hammad/data/models/model.py +1078 -0
- hammad_python-0.0.15/hammad/data/models/utils.py +280 -0
- hammad_python-0.0.15/hammad/data/sql/__init__.py +23 -0
- hammad_python-0.0.15/hammad/data/sql/database.py +578 -0
- hammad_python-0.0.15/hammad/data/sql/types.py +136 -0
- hammad_python-0.0.15/hammad/data/types/__init__.py +39 -0
- hammad_python-0.0.15/hammad/data/types/file.py +358 -0
- hammad_python-0.0.15/hammad/data/types/multimodal/__init__.py +24 -0
- hammad_python-0.0.15/hammad/data/types/multimodal/audio.py +96 -0
- hammad_python-0.0.15/hammad/data/types/multimodal/image.py +80 -0
- hammad_python-0.0.15/hammad/data/types/text.py +1066 -0
- hammad_python-0.0.15/hammad/formatting/__init__.py +20 -0
- hammad_python-0.0.15/hammad/formatting/json/__init__.py +27 -0
- hammad_python-0.0.15/hammad/formatting/json/converters.py +158 -0
- hammad_python-0.0.15/hammad/formatting/text/__init__.py +63 -0
- hammad_python-0.0.15/hammad/formatting/text/converters.py +723 -0
- hammad_python-0.0.15/hammad/formatting/text/markdown.py +131 -0
- hammad_python-0.0.15/hammad/formatting/yaml/__init__.py +26 -0
- hammad_python-0.0.15/hammad/formatting/yaml/converters.py +5 -0
- hammad_python-0.0.15/hammad/genai/__init__.py +45 -0
- hammad_python-0.0.15/hammad/genai/embedding_models/__init__.py +41 -0
- hammad_python-0.0.15/hammad/genai/embedding_models/embedding_model.py +193 -0
- hammad_python-0.0.15/hammad/genai/embedding_models/embedding_model_name.py +77 -0
- hammad_python-0.0.15/hammad/genai/embedding_models/embedding_model_request.py +65 -0
- hammad_python-0.0.15/hammad/genai/embedding_models/embedding_model_response.py +69 -0
- hammad_python-0.0.15/hammad/genai/embedding_models/run.py +161 -0
- hammad_python-0.0.15/hammad/genai/language_models/__init__.py +35 -0
- hammad_python-0.0.15/hammad/genai/language_models/_streaming.py +368 -0
- hammad_python-0.0.15/hammad/genai/language_models/_types.py +276 -0
- hammad_python-0.0.15/hammad/genai/language_models/_utils/__init__.py +31 -0
- hammad_python-0.0.15/hammad/genai/language_models/_utils/_completions.py +131 -0
- hammad_python-0.0.15/hammad/genai/language_models/_utils/_messages.py +89 -0
- hammad_python-0.0.15/hammad/genai/language_models/_utils/_requests.py +180 -0
- hammad_python-0.0.15/hammad/genai/language_models/_utils/_structured_outputs.py +122 -0
- hammad_python-0.0.15/hammad/genai/language_models/language_model.py +596 -0
- hammad_python-0.0.15/hammad/genai/language_models/language_model_request.py +122 -0
- hammad_python-0.0.15/hammad/genai/language_models/language_model_response.py +220 -0
- hammad_python-0.0.15/hammad/genai/language_models/language_model_response_chunk.py +53 -0
- hammad_python-0.0.15/hammad/genai/language_models/run.py +498 -0
- hammad_python-0.0.15/hammad/logging/__init__.py +35 -0
- hammad_python-0.0.15/hammad/logging/decorators.py +834 -0
- hammad_python-0.0.15/hammad/logging/logger.py +954 -0
- hammad_python-0.0.15/hammad/mcp/__init__.py +50 -0
- hammad_python-0.0.15/hammad/mcp/client/__init__.py +36 -0
- hammad_python-0.0.15/hammad/mcp/client/client.py +624 -0
- hammad_python-0.0.15/hammad/mcp/client/client_service.py +400 -0
- hammad_python-0.0.15/hammad/mcp/client/settings.py +178 -0
- hammad_python-0.0.15/hammad/mcp/servers/__init__.py +25 -0
- hammad_python-0.0.15/hammad/mcp/servers/launcher.py +1161 -0
- hammad_python-0.0.15/hammad/runtime/__init__.py +32 -0
- hammad_python-0.0.15/hammad/runtime/decorators.py +142 -0
- hammad_python-0.0.15/hammad/runtime/run.py +299 -0
- hammad_python-0.0.15/hammad/service/__init__.py +49 -0
- hammad_python-0.0.15/hammad/service/create.py +527 -0
- hammad_python-0.0.15/hammad/service/decorators.py +285 -0
- hammad_python-0.0.15/hammad/typing/__init__.py +435 -0
- hammad_python-0.0.15/hammad/web/__init__.py +43 -0
- hammad_python-0.0.15/hammad/web/http/__init__.py +1 -0
- hammad_python-0.0.15/hammad/web/http/client.py +944 -0
- hammad_python-0.0.15/hammad/web/models.py +277 -0
- hammad_python-0.0.15/hammad/web/openapi/__init__.py +1 -0
- hammad_python-0.0.15/hammad/web/openapi/client.py +740 -0
- hammad_python-0.0.15/hammad/web/search/__init__.py +1 -0
- hammad_python-0.0.15/hammad/web/search/client.py +1035 -0
- hammad_python-0.0.15/hammad/web/utils.py +472 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15}/mkdocs.yml +7 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15}/pyproject.toml +47 -42
- {hammad_python-0.0.13 → hammad_python-0.0.15}/uv.lock +78 -630
- hammad_python-0.0.13/PKG-INFO +0 -38
- hammad_python-0.0.13/README.md +0 -2
- hammad_python-0.0.13/hammad/__init__.py +0 -180
- hammad_python-0.0.13/hammad/_core/__init__.py +0 -1
- hammad_python-0.0.13/hammad/_core/_utils/__init__.py +0 -4
- hammad_python-0.0.13/hammad/ai/__init__.py +0 -59
- hammad_python-0.0.13/hammad/cache/__init__.py +0 -48
- hammad_python-0.0.13/hammad/multithreading/__init__.py +0 -304
- hammad_python-0.0.13/hammad/types/__init__.py +0 -11
- hammad_python-0.0.13/hammad/yaml/converters.py +0 -19
- hammad_python-0.0.13/tests/configuration/test_configuration.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15}/.python-version +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15}/LICENSE +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/_utils.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/client/__init__.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/client/base_embeddings_client.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/ai/embeddings/create.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cache/base_cache.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cache/cache.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cache/decorators.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cache/file_cache.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cache/ttl_cache.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/styles/settings.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/styles/types.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/cli/styles/utils.py +0 -0
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/base/fields.py +0 -0
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/base/model.py +0 -0
- {hammad_python-0.0.13/hammad → hammad_python-0.0.15/deprecated/hammad/data/models}/base/utils.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/logging/decorators.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/py.typed +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/typing/__init__.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/http/__init__.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/models.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/openapi/client.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/search/__init__.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/search/client.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/hammad/web/utils.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/ai/completions/test_ai_completions_types.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/cli/test_cli_plugins_animate.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/cli/test_cli_plugins_input.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/cli/test_cli_plugins_print.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/cli/test_cli_styles_utils.py +0 -0
- {hammad_python-0.0.13/tests/data → hammad_python-0.0.15/deprecated/tests/data/collections}/test_data_collections_vector_collection.py +0 -0
- /hammad_python-0.0.13/hammad/web/openapi/__init__.py → /hammad_python-0.0.15/deprecated/tests/data/configuration/test_data_configuration.py +0 -0
- {hammad_python-0.0.13/tests/data → hammad_python-0.0.15/deprecated/tests/data/databases}/test_data_databases_database.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/logging/test_logging_decorators.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/logging/test_logging_logger.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/typing/test_typing_utils.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/web/test_web_toolkits_http_toolkit.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/web/test_web_toolkits_openapi_toolkit.py +0 -0
- {hammad_python-0.0.13 → hammad_python-0.0.15/deprecated}/tests/web/test_web_utils.py +0 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: hammad-python
|
3
|
+
Version: 0.0.15
|
4
|
+
Author-email: Hammad Saeed <hammadaidev@gmail.com>
|
5
|
+
License: MIT License
|
6
|
+
|
7
|
+
Copyright (c) 2025 Hammad Saeed
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
11
|
+
in the Software without restriction, including without limitation the rights
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
14
|
+
furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
17
|
+
copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
|
+
SOFTWARE.
|
26
|
+
License-File: LICENSE
|
27
|
+
Requires-Python: >=3.11
|
28
|
+
Requires-Dist: ddgs>=9.0.0
|
29
|
+
Requires-Dist: httpx>=0.28.1
|
30
|
+
Requires-Dist: msgspec>=0.19.0
|
31
|
+
Requires-Dist: pydantic>=2.11.7
|
32
|
+
Requires-Dist: rich>=14.0.0
|
33
|
+
Requires-Dist: selectolax>=0.3.31
|
34
|
+
Requires-Dist: sqlalchemy>=2.0.41
|
35
|
+
Requires-Dist: tantivy>=0.24.0
|
36
|
+
Requires-Dist: tenacity>=9.1.2
|
37
|
+
Requires-Dist: typing-inspect>=0.9.0
|
38
|
+
Provides-Extra: ai
|
39
|
+
Requires-Dist: instructor>=1.9.0; extra == 'ai'
|
40
|
+
Requires-Dist: litellm>=1.73.6; extra == 'ai'
|
41
|
+
Requires-Dist: qdrant-client>=1.14.3; extra == 'ai'
|
42
|
+
Provides-Extra: mcp
|
43
|
+
Requires-Dist: mcp>=1.10.1; extra == 'mcp'
|
44
|
+
Provides-Extra: serve
|
45
|
+
Requires-Dist: fastapi>=0.115.6; extra == 'serve'
|
46
|
+
Requires-Dist: uvicorn>=0.34.0; extra == 'serve'
|
47
|
+
Description-Content-Type: text/markdown
|
48
|
+
|
49
|
+
## hammad-python
|
50
|
+
|
51
|
+
> __Happily Accelerated Micro-Modules (_for_) Application Development__
|
52
|
+
|
53
|
+
## Introduction
|
54
|
+
|
55
|
+
The `hammad-python` library, is a mix of a love letter and collection of mixed resources for
|
56
|
+
developing Python applications. This library is meant to be used for rapid prototyping and
|
57
|
+
development, and is focused on providing styled placeholder tools for common patterns, tasks
|
58
|
+
and workflows.
|
59
|
+
|
60
|
+
The package is currently built into the following structures:
|
61
|
+
|
62
|
+
- `hammad-python` : Contains most core functionality and resources.
|
63
|
+
- `hammad-python[ai]` : Contains easy to use resources for Generative AI related tasks such as
|
64
|
+
generating completions with language models, or creating embeddings.
|
65
|
+
- `hammad-python[serve]` : Contains FastAPI / Uvicorn based resources for serving and running applications.
|
66
|
+
|
67
|
+
## Installation
|
68
|
+
|
69
|
+
You can install the package using `pip` or `uv`:
|
70
|
+
|
71
|
+
```bash
|
72
|
+
pip install hammad-python
|
73
|
+
|
74
|
+
# or install the `ai` extension
|
75
|
+
# pip install 'hammad-python[ai]'
|
76
|
+
|
77
|
+
# or install the `serve` extension
|
78
|
+
# pip install 'hammad-python[serve]'
|
79
|
+
```
|
80
|
+
|
81
|
+
```bash
|
82
|
+
uv pip install hammad-python
|
83
|
+
|
84
|
+
# or install the `ai` extension
|
85
|
+
# uv pip install 'hammad-python[ai]'
|
86
|
+
|
87
|
+
# or install the `serve` extension
|
88
|
+
# uv pip install 'hammad-python[serve]'
|
89
|
+
```
|
90
|
+
|
91
|
+
## Basic Usage
|
92
|
+
|
93
|
+
### Data Structures, Databases and Other Data Related Resources
|
94
|
+
|
95
|
+
#### Collections
|
96
|
+
|
97
|
+
Using `hammad.data.collections` is a simple way to create searchable collections of
|
98
|
+
data using both `bm25` and `vector` based search.
|
99
|
+
|
100
|
+
```python
|
101
|
+
from hammad.data.collections import create_collection
|
102
|
+
|
103
|
+
# Create either a `vector` or `searchable` collection
|
104
|
+
col = create_collection(type = "searchable")
|
105
|
+
|
106
|
+
# add anything to the collection
|
107
|
+
col.add("This is some text")
|
108
|
+
col.add(5)
|
109
|
+
col.add({'text' : "this is a dictionary"})
|
110
|
+
|
111
|
+
# search the collection
|
112
|
+
print(col.query("text"))
|
113
|
+
```
|
114
|
+
|
115
|
+
#### Databases
|
116
|
+
|
117
|
+
Any collection can be either used as a standalone database, or can be added as one
|
118
|
+
of the collections within a database. Databases provide a unified interface for handling
|
119
|
+
both `Searchable` and `Vector` based collections.
|
120
|
+
|
121
|
+
```python
|
122
|
+
from hammad.data.collections import create_collection
|
123
|
+
from hammad.data.databases import Database
|
124
|
+
|
125
|
+
# Create either a `vector` or `searchable` collection
|
126
|
+
col = create_collection(type = "searchable")
|
127
|
+
|
128
|
+
col.add("This is some text")
|
129
|
+
|
130
|
+
# Databases can either be created on memory or using a path
|
131
|
+
db = Database(location = "memory")
|
132
|
+
|
133
|
+
db.add_collection(col)
|
134
|
+
|
135
|
+
# search globally or within a single collection
|
136
|
+
print(db.query("text"))
|
137
|
+
```
|
138
|
+
|
139
|
+
### Styling / Introspection Resources
|
140
|
+
|
141
|
+
The `hammad-python` package contains a variety of components that can be used
|
142
|
+
to easily style, or run introspection (logging) on your code.
|
143
|
+
|
144
|
+
```python
|
145
|
+
from hammad.cli import print, input, animate
|
146
|
+
|
147
|
+
# Use extended `rich` styling easily
|
148
|
+
print("Hello, World", bg_settings = {"title" : "This is a title"})
|
149
|
+
|
150
|
+
# Easily collect various forms of input in a single function
|
151
|
+
class User(BaseModel):
|
152
|
+
name : str
|
153
|
+
age : int
|
154
|
+
|
155
|
+
# TIP:
|
156
|
+
# you can style this the same way with `print`
|
157
|
+
user = input("Enter some information about yourself: ", schema = User)
|
158
|
+
|
159
|
+
# easily run a collection of prebuilt animations
|
160
|
+
animate("This is a rainbow!", type = "rainbow", duration = 2, refresh_rate = 20)
|
161
|
+
```
|
162
|
+
|
163
|
+
Using the various `hammad.logging` resources, you can both create custom & styled
|
164
|
+
loggers, as well as easily inspect various aspects of your code during runtime.
|
165
|
+
|
166
|
+
```python
|
167
|
+
from hammad.logging import Logger
|
168
|
+
|
169
|
+
# create standard / file based loggers easily
|
170
|
+
logger = Logger("hammad", level = "info", rich = Trues)
|
171
|
+
|
172
|
+
file_logger = Logger("hammad-file", level = "info", file = "hammad.log")
|
173
|
+
|
174
|
+
# log to the console
|
175
|
+
logger.info("This is an info message")
|
176
|
+
|
177
|
+
# Use the various `trace_` methods to run various introspection tasks
|
178
|
+
from hammad.logging import (
|
179
|
+
trace,
|
180
|
+
trace_cls,
|
181
|
+
trace_function,
|
182
|
+
trace_http
|
183
|
+
)
|
184
|
+
```
|
@@ -0,0 +1,136 @@
|
|
1
|
+
## hammad-python
|
2
|
+
|
3
|
+
> __Happily Accelerated Micro-Modules (_for_) Application Development__
|
4
|
+
|
5
|
+
## Introduction
|
6
|
+
|
7
|
+
The `hammad-python` library, is a mix of a love letter and collection of mixed resources for
|
8
|
+
developing Python applications. This library is meant to be used for rapid prototyping and
|
9
|
+
development, and is focused on providing styled placeholder tools for common patterns, tasks
|
10
|
+
and workflows.
|
11
|
+
|
12
|
+
The package is currently built into the following structures:
|
13
|
+
|
14
|
+
- `hammad-python` : Contains most core functionality and resources.
|
15
|
+
- `hammad-python[ai]` : Contains easy to use resources for Generative AI related tasks such as
|
16
|
+
generating completions with language models, or creating embeddings.
|
17
|
+
- `hammad-python[serve]` : Contains FastAPI / Uvicorn based resources for serving and running applications.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
You can install the package using `pip` or `uv`:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
pip install hammad-python
|
25
|
+
|
26
|
+
# or install the `ai` extension
|
27
|
+
# pip install 'hammad-python[ai]'
|
28
|
+
|
29
|
+
# or install the `serve` extension
|
30
|
+
# pip install 'hammad-python[serve]'
|
31
|
+
```
|
32
|
+
|
33
|
+
```bash
|
34
|
+
uv pip install hammad-python
|
35
|
+
|
36
|
+
# or install the `ai` extension
|
37
|
+
# uv pip install 'hammad-python[ai]'
|
38
|
+
|
39
|
+
# or install the `serve` extension
|
40
|
+
# uv pip install 'hammad-python[serve]'
|
41
|
+
```
|
42
|
+
|
43
|
+
## Basic Usage
|
44
|
+
|
45
|
+
### Data Structures, Databases and Other Data Related Resources
|
46
|
+
|
47
|
+
#### Collections
|
48
|
+
|
49
|
+
Using `hammad.data.collections` is a simple way to create searchable collections of
|
50
|
+
data using both `bm25` and `vector` based search.
|
51
|
+
|
52
|
+
```python
|
53
|
+
from hammad.data.collections import create_collection
|
54
|
+
|
55
|
+
# Create either a `vector` or `searchable` collection
|
56
|
+
col = create_collection(type = "searchable")
|
57
|
+
|
58
|
+
# add anything to the collection
|
59
|
+
col.add("This is some text")
|
60
|
+
col.add(5)
|
61
|
+
col.add({'text' : "this is a dictionary"})
|
62
|
+
|
63
|
+
# search the collection
|
64
|
+
print(col.query("text"))
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Databases
|
68
|
+
|
69
|
+
Any collection can be either used as a standalone database, or can be added as one
|
70
|
+
of the collections within a database. Databases provide a unified interface for handling
|
71
|
+
both `Searchable` and `Vector` based collections.
|
72
|
+
|
73
|
+
```python
|
74
|
+
from hammad.data.collections import create_collection
|
75
|
+
from hammad.data.databases import Database
|
76
|
+
|
77
|
+
# Create either a `vector` or `searchable` collection
|
78
|
+
col = create_collection(type = "searchable")
|
79
|
+
|
80
|
+
col.add("This is some text")
|
81
|
+
|
82
|
+
# Databases can either be created on memory or using a path
|
83
|
+
db = Database(location = "memory")
|
84
|
+
|
85
|
+
db.add_collection(col)
|
86
|
+
|
87
|
+
# search globally or within a single collection
|
88
|
+
print(db.query("text"))
|
89
|
+
```
|
90
|
+
|
91
|
+
### Styling / Introspection Resources
|
92
|
+
|
93
|
+
The `hammad-python` package contains a variety of components that can be used
|
94
|
+
to easily style, or run introspection (logging) on your code.
|
95
|
+
|
96
|
+
```python
|
97
|
+
from hammad.cli import print, input, animate
|
98
|
+
|
99
|
+
# Use extended `rich` styling easily
|
100
|
+
print("Hello, World", bg_settings = {"title" : "This is a title"})
|
101
|
+
|
102
|
+
# Easily collect various forms of input in a single function
|
103
|
+
class User(BaseModel):
|
104
|
+
name : str
|
105
|
+
age : int
|
106
|
+
|
107
|
+
# TIP:
|
108
|
+
# you can style this the same way with `print`
|
109
|
+
user = input("Enter some information about yourself: ", schema = User)
|
110
|
+
|
111
|
+
# easily run a collection of prebuilt animations
|
112
|
+
animate("This is a rainbow!", type = "rainbow", duration = 2, refresh_rate = 20)
|
113
|
+
```
|
114
|
+
|
115
|
+
Using the various `hammad.logging` resources, you can both create custom & styled
|
116
|
+
loggers, as well as easily inspect various aspects of your code during runtime.
|
117
|
+
|
118
|
+
```python
|
119
|
+
from hammad.logging import Logger
|
120
|
+
|
121
|
+
# create standard / file based loggers easily
|
122
|
+
logger = Logger("hammad", level = "info", rich = Trues)
|
123
|
+
|
124
|
+
file_logger = Logger("hammad-file", level = "info", file = "hammad.log")
|
125
|
+
|
126
|
+
# log to the console
|
127
|
+
logger.info("This is an info message")
|
128
|
+
|
129
|
+
# Use the various `trace_` methods to run various introspection tasks
|
130
|
+
from hammad.logging import (
|
131
|
+
trace,
|
132
|
+
trace_cls,
|
133
|
+
trace_function,
|
134
|
+
trace_http
|
135
|
+
)
|
136
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
"""hammad-python"""
|
@@ -0,0 +1 @@
|
|
1
|
+
"""hammad.ai"""
|
@@ -4,7 +4,7 @@ Contains types and model like objects for working with language model
|
|
4
4
|
completions."""
|
5
5
|
|
6
6
|
from typing import TYPE_CHECKING
|
7
|
-
from ...
|
7
|
+
from ...performance.imports import create_getattr_importer
|
8
8
|
|
9
9
|
if TYPE_CHECKING:
|
10
10
|
from .client import CompletionsClient
|
@@ -17,6 +17,7 @@ if TYPE_CHECKING:
|
|
17
17
|
CompletionsModelName,
|
18
18
|
CompletionsOutputType,
|
19
19
|
)
|
20
|
+
from .settings import CompletionsSettings, CompletionsModelSettings
|
20
21
|
from .create import create_completion, async_create_completion
|
21
22
|
|
22
23
|
|
@@ -37,7 +38,7 @@ __all__ = (
|
|
37
38
|
)
|
38
39
|
|
39
40
|
|
40
|
-
__getattr__ =
|
41
|
+
__getattr__ = create_getattr_importer(__all__)
|
41
42
|
|
42
43
|
|
43
44
|
def __dir__() -> list[str]:
|
@@ -22,9 +22,8 @@ except ImportError:
|
|
22
22
|
"`pip install 'hammad-python[ai]'"
|
23
23
|
)
|
24
24
|
|
25
|
-
from ...pydantic.converters import convert_to_pydantic_model
|
25
|
+
from ...data.models.pydantic.converters import convert_to_pydantic_model
|
26
26
|
from .._utils import get_litellm, get_instructor
|
27
|
-
from ...base.model import Model
|
28
27
|
from ...typing import is_pydantic_basemodel
|
29
28
|
from .utils import (
|
30
29
|
format_tool_calls,
|
@@ -32,117 +31,23 @@ from .utils import (
|
|
32
31
|
convert_response_to_completion,
|
33
32
|
create_async_completion_stream,
|
34
33
|
create_completion_stream,
|
34
|
+
InstructorStreamWrapper,
|
35
|
+
AsyncInstructorStreamWrapper,
|
36
|
+
)
|
37
|
+
from .settings import (
|
38
|
+
CompletionsSettings,
|
39
|
+
OpenAIWebSearchOptions,
|
40
|
+
AnthropicThinkingParam,
|
35
41
|
)
|
36
42
|
from .types import (
|
43
|
+
CompletionsInstructorModeParam,
|
37
44
|
CompletionsInputParam,
|
38
45
|
CompletionsOutputType,
|
39
46
|
Completion,
|
40
|
-
CompletionChunk,
|
41
|
-
CompletionStream,
|
42
|
-
AsyncCompletionStream,
|
43
47
|
)
|
44
48
|
|
45
49
|
|
46
|
-
|
47
|
-
city: str
|
48
|
-
country: str
|
49
|
-
region: str
|
50
|
-
timezone: str
|
51
|
-
|
52
|
-
|
53
|
-
class OpenAIWebSearchUserLocation(TypedDict):
|
54
|
-
approximate: OpenAIWebSearchUserLocationApproximate
|
55
|
-
type: Literal["approximate"]
|
56
|
-
|
57
|
-
|
58
|
-
class OpenAIWebSearchOptions(TypedDict, total=False):
|
59
|
-
search_context_size: Optional[Literal["low", "medium", "high"]]
|
60
|
-
user_location: Optional[OpenAIWebSearchUserLocation]
|
61
|
-
|
62
|
-
|
63
|
-
class AnthropicThinkingParam(TypedDict, total=False):
|
64
|
-
type: Literal["enabled"]
|
65
|
-
budget_tokens: int
|
66
|
-
|
67
|
-
|
68
|
-
InstructorModeParam = Literal[
|
69
|
-
"function_call",
|
70
|
-
"parallel_tool_call",
|
71
|
-
"tool_call",
|
72
|
-
"tools_strict",
|
73
|
-
"json_mode",
|
74
|
-
"json_o1",
|
75
|
-
"markdown_json_mode",
|
76
|
-
"json_schema_mode",
|
77
|
-
"anthropic_tools",
|
78
|
-
"anthropic_reasoning_tools",
|
79
|
-
"anthropic_json",
|
80
|
-
"mistral_tools",
|
81
|
-
"mistral_structured_outputs",
|
82
|
-
"vertexai_tools",
|
83
|
-
"vertexai_json",
|
84
|
-
"vertexai_parallel_tools",
|
85
|
-
"gemini_json",
|
86
|
-
"gemini_tools",
|
87
|
-
"genai_tools",
|
88
|
-
"genai_structured_outputs",
|
89
|
-
"cohere_tools",
|
90
|
-
"cohere_json_object",
|
91
|
-
"cerebras_tools",
|
92
|
-
"cerebras_json",
|
93
|
-
"fireworks_tools",
|
94
|
-
"fireworks_json",
|
95
|
-
"writer_tools",
|
96
|
-
"bedrock_tools",
|
97
|
-
"bedrock_json",
|
98
|
-
"perplexity_json",
|
99
|
-
"openrouter_structured_outputs",
|
100
|
-
]
|
101
|
-
"""Instructor prompt/parsing mode for structured outputs."""
|
102
|
-
|
103
|
-
|
104
|
-
class CompletionsSettings(TypedDict):
|
105
|
-
"""Accepted settings for the `litellm` completion function."""
|
106
|
-
|
107
|
-
model: str
|
108
|
-
messages: List
|
109
|
-
timeout: Optional[Union[float, str, Timeout]]
|
110
|
-
temperature: Optional[float]
|
111
|
-
top_p: Optional[float]
|
112
|
-
n: Optional[int]
|
113
|
-
stream: Optional[bool]
|
114
|
-
stream_options: Optional[Dict[str, Any]]
|
115
|
-
stop: Optional[str]
|
116
|
-
max_completion_tokens: Optional[int]
|
117
|
-
max_tokens: Optional[int]
|
118
|
-
modalities: Optional[List[ChatCompletionModality]]
|
119
|
-
prediction: Optional[ChatCompletionPredictionContentParam]
|
120
|
-
audio: Optional[ChatCompletionAudioParam]
|
121
|
-
presence_penalty: Optional[float]
|
122
|
-
frequency_penalty: Optional[float]
|
123
|
-
logit_bias: Optional[Dict[str, float]]
|
124
|
-
user: Optional[str]
|
125
|
-
reasoning_effort: Optional[Literal["low", "medium", "high"]]
|
126
|
-
# NOTE: response_format is not used within the `completions` resource
|
127
|
-
# in place of `instructor` and the `type` parameter
|
128
|
-
seed: Optional[int]
|
129
|
-
tools: Optional[List]
|
130
|
-
tool_choice: Optional[Union[str, Dict[str, Any]]]
|
131
|
-
logprobs: Optional[bool]
|
132
|
-
top_logprobs: Optional[int]
|
133
|
-
parallel_tool_calls: Optional[bool]
|
134
|
-
web_search_options: Optional[OpenAIWebSearchOptions]
|
135
|
-
deployment_id: Optional[str]
|
136
|
-
extra_headers: Optional[Dict[str, str]]
|
137
|
-
base_url: Optional[str]
|
138
|
-
functions: Optional[List]
|
139
|
-
function_call: Optional[str]
|
140
|
-
# set api_base, api_version, api_key
|
141
|
-
api_version: Optional[str]
|
142
|
-
api_key: Optional[str]
|
143
|
-
model_list: Optional[list]
|
144
|
-
# Optional liteLLM function params
|
145
|
-
thinking: Optional[AnthropicThinkingParam]
|
50
|
+
__all__ = "CompletionsClient"
|
146
51
|
|
147
52
|
|
148
53
|
class CompletionsError(Exception):
|
@@ -372,7 +277,9 @@ class CompletionsClient(Generic[CompletionsOutputType]):
|
|
372
277
|
instructions: Optional[str] = None,
|
373
278
|
model: str = "openai/gpt-4o-mini",
|
374
279
|
type: CompletionsOutputType = str,
|
375
|
-
|
280
|
+
response_field_name: str = "content",
|
281
|
+
response_field_instruction: str = "A response in the correct type as requested by the user, or relevant content.",
|
282
|
+
instructor_mode: CompletionsInstructorModeParam = "tool_call",
|
376
283
|
max_retries: int = 3,
|
377
284
|
strict: bool = True,
|
378
285
|
*,
|
@@ -515,22 +422,30 @@ class CompletionsClient(Generic[CompletionsOutputType]):
|
|
515
422
|
response_model = convert_to_pydantic_model(
|
516
423
|
target=type,
|
517
424
|
name="Response",
|
518
|
-
field_name=
|
519
|
-
description=
|
425
|
+
field_name=response_field_name,
|
426
|
+
description=response_field_instruction,
|
520
427
|
)
|
521
428
|
else:
|
522
429
|
response_model = type
|
523
430
|
|
524
431
|
if stream:
|
525
|
-
|
432
|
+
# Create wrapper to capture raw content via hooks
|
433
|
+
wrapper = AsyncInstructorStreamWrapper(
|
434
|
+
client=client,
|
526
435
|
response_model=response_model,
|
527
|
-
|
528
|
-
|
529
|
-
|
436
|
+
params={
|
437
|
+
"max_retries": max_retries,
|
438
|
+
"strict": strict,
|
439
|
+
**{k: v for k, v in params.items() if v is not None},
|
440
|
+
},
|
441
|
+
output_type=type,
|
442
|
+
model=model,
|
443
|
+
)
|
444
|
+
return create_async_completion_stream(
|
445
|
+
wrapper, output_type=type, model=model
|
530
446
|
)
|
531
|
-
return create_async_completion_stream(stream, output_type=type, model=model)
|
532
447
|
else:
|
533
|
-
response = await client.chat.completions.
|
448
|
+
response, completion = await client.chat.completions.create_with_completion(
|
534
449
|
response_model=response_model,
|
535
450
|
max_retries=max_retries,
|
536
451
|
strict=strict,
|
@@ -538,13 +453,29 @@ class CompletionsClient(Generic[CompletionsOutputType]):
|
|
538
453
|
)
|
539
454
|
|
540
455
|
# Extract the actual value if using converted pydantic model
|
541
|
-
if not is_pydantic_basemodel(type) and hasattr(
|
542
|
-
|
456
|
+
if not is_pydantic_basemodel(type) and hasattr(
|
457
|
+
response, response_field_name
|
458
|
+
):
|
459
|
+
actual_output = getattr(response, response_field_name)
|
543
460
|
else:
|
544
461
|
actual_output = response
|
545
462
|
|
463
|
+
# Extract content and tool calls from the completion
|
464
|
+
content = None
|
465
|
+
tool_calls = None
|
466
|
+
if hasattr(completion, "choices") and completion.choices:
|
467
|
+
choice = completion.choices[0]
|
468
|
+
if hasattr(choice, "message"):
|
469
|
+
message = choice.message
|
470
|
+
content = getattr(message, "content", None)
|
471
|
+
tool_calls = getattr(message, "tool_calls", None)
|
472
|
+
|
546
473
|
return Completion(
|
547
|
-
output=actual_output,
|
474
|
+
output=actual_output,
|
475
|
+
model=model,
|
476
|
+
content=content,
|
477
|
+
tool_calls=tool_calls,
|
478
|
+
completion=completion,
|
548
479
|
)
|
549
480
|
|
550
481
|
@staticmethod
|
@@ -553,7 +484,9 @@ class CompletionsClient(Generic[CompletionsOutputType]):
|
|
553
484
|
instructions: Optional[str] = None,
|
554
485
|
model: str = "openai/gpt-4o-mini",
|
555
486
|
type: CompletionsOutputType = str,
|
556
|
-
|
487
|
+
response_field_name: str = "content",
|
488
|
+
response_field_instruction: str = "A response in the correct type as requested by the user, or relevant content.",
|
489
|
+
instructor_mode: CompletionsInstructorModeParam = "tool_call",
|
557
490
|
max_retries: int = 3,
|
558
491
|
strict: bool = True,
|
559
492
|
*,
|
@@ -696,22 +629,28 @@ class CompletionsClient(Generic[CompletionsOutputType]):
|
|
696
629
|
response_model = convert_to_pydantic_model(
|
697
630
|
target=type,
|
698
631
|
name="Response",
|
699
|
-
field_name=
|
700
|
-
description=
|
632
|
+
field_name=response_field_name,
|
633
|
+
description=response_field_instruction,
|
701
634
|
)
|
702
635
|
else:
|
703
636
|
response_model = type
|
704
637
|
|
705
638
|
if stream:
|
706
|
-
|
639
|
+
# Create wrapper to capture raw content via hooks
|
640
|
+
wrapper = InstructorStreamWrapper(
|
641
|
+
client=client,
|
707
642
|
response_model=response_model,
|
708
|
-
|
709
|
-
|
710
|
-
|
643
|
+
params={
|
644
|
+
"max_retries": max_retries,
|
645
|
+
"strict": strict,
|
646
|
+
**{k: v for k, v in params.items() if v is not None},
|
647
|
+
},
|
648
|
+
output_type=type,
|
649
|
+
model=model,
|
711
650
|
)
|
712
|
-
return create_completion_stream(
|
651
|
+
return create_completion_stream(wrapper, output_type=type, model=model)
|
713
652
|
else:
|
714
|
-
response = client.chat.completions.
|
653
|
+
response, completion = client.chat.completions.create_with_completion(
|
715
654
|
response_model=response_model,
|
716
655
|
max_retries=max_retries,
|
717
656
|
strict=strict,
|
@@ -719,11 +658,27 @@ class CompletionsClient(Generic[CompletionsOutputType]):
|
|
719
658
|
)
|
720
659
|
|
721
660
|
# Extract the actual value if using converted pydantic model
|
722
|
-
if not is_pydantic_basemodel(type) and hasattr(
|
723
|
-
|
661
|
+
if not is_pydantic_basemodel(type) and hasattr(
|
662
|
+
response, response_field_name
|
663
|
+
):
|
664
|
+
actual_output = getattr(response, response_field_name)
|
724
665
|
else:
|
725
666
|
actual_output = response
|
726
667
|
|
668
|
+
# Extract content and tool calls from the completion
|
669
|
+
content = None
|
670
|
+
tool_calls = None
|
671
|
+
if hasattr(completion, "choices") and completion.choices:
|
672
|
+
choice = completion.choices[0]
|
673
|
+
if hasattr(choice, "message"):
|
674
|
+
message = choice.message
|
675
|
+
content = getattr(message, "content", None)
|
676
|
+
tool_calls = getattr(message, "tool_calls", None)
|
677
|
+
|
727
678
|
return Completion(
|
728
|
-
output=actual_output,
|
679
|
+
output=actual_output,
|
680
|
+
model=model,
|
681
|
+
content=content,
|
682
|
+
tool_calls=tool_calls,
|
683
|
+
completion=completion,
|
729
684
|
)
|