Skip to content

Commit 83d3ed1

Browse files
HumeStreamClient improvements (#44)
1 parent 6d2373b commit 83d3ed1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+887
-791
lines changed

docs/config/burst-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: hume.models.config.burst_config.BurstConfig

docs/config/face-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: hume.models.config.face_config.FaceConfig

docs/config/facemesh-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: hume.models.config.facemesh_config.FacemeshConfig

docs/config/language-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: hume.models.config.language_config.LanguageConfig

docs/config/ner-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: hume.models.config.ner_config.NerConfig

docs/config/prosody-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: hume.models.config.prosody_config.ProsodyConfig

docs/index.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Python versions 3.8 and 3.9 are supported
99
Basic installation:
1010

1111
```bash
12-
$ pip install hume
12+
pip install hume
1313
```
1414

1515
Websocket and streaming features can be enabled with:
1616

1717
```bash
18-
$ pip install hume[stream]
18+
pip install hume[stream]
1919
```
2020

2121
## Basic Usage
@@ -26,10 +26,12 @@ $ pip install hume[stream]
2626
2727
```python
2828
from hume import HumeBatchClient
29+
from hume.models.config import FaceConfig
2930

3031
client = HumeBatchClient("<your-api-key>")
3132
urls = ["https://tinyurl.com/hume-img"]
32-
job = client.submit_face(urls)
33+
config = FaceConfig(identify_faces=True)
34+
job = client.submit_job(urls, [config])
3335

3436
print(job)
3537
print("Running...")
@@ -60,14 +62,13 @@ print(job)
6062
```python
6163
import asyncio
6264

63-
from hume import HumeStreamClient, StreamSocket
64-
from hume.config import FaceConfig
65+
from hume import HumeStreamClient
66+
from hume.models.config import FaceConfig
6567

6668
async def main():
6769
client = HumeStreamClient("<your-api-key>")
68-
configs = [FaceConfig(identify_faces=True)]
69-
async with client.connect(configs) as socket:
70-
socket: StreamSocket
70+
config = FaceConfig(identify_faces=True)
71+
async with client.connect([config]) as socket:
7172
result = await socket.send_file("<your-image-filepath>")
7273
print(result)
7374

hume/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
"""Module init."""
2-
import importlib.metadata
2+
from importlib.metadata import version
33

44
from hume._batch import BatchJob, BatchJobResult, BatchJobStatus, HumeBatchClient
55
from hume._stream import HumeStreamClient, StreamSocket
6-
from hume._common.hume_client_error import HumeClientError
7-
from hume._common.model_type import ModelType
6+
from hume.error.hume_client_exception import HumeClientException
87

9-
__version__ = importlib.metadata.version("hume")
8+
__version__ = version("hume")
109

1110
__all__ = [
1211
"__version__",
1312
"BatchJob",
1413
"BatchJobResult",
1514
"BatchJobStatus",
1615
"HumeBatchClient",
17-
"HumeClientError",
16+
"HumeClientException",
1817
"HumeStreamClient",
19-
"ModelType",
2018
"StreamSocket",
2119
]

hume/_batch/batch_job.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Batch job."""
2-
import logging
32
from typing import TYPE_CHECKING
43

54
from hume._batch.batch_job_result import BatchJobResult
@@ -9,8 +8,6 @@
98
if TYPE_CHECKING:
109
from hume._batch.hume_batch_client import HumeBatchClient
1110

12-
logger = logging.getLogger(__name__)
13-
1411

1512
class BatchJob:
1613
"""Batch job."""
@@ -51,7 +48,7 @@ def await_complete(self, timeout: int = 300) -> BatchJobResult:
5148
Args:
5249
timeout (int): Maximum time in seconds to await. If the timeout is reached
5350
before the job reaches a terminal state the job will continue to be processed,
54-
but a `HumeClientError` will be raised to the caller of `await_complete`.
51+
but a `HumeClientException` will be raised to the caller of `await_complete`.
5552
5653
Raises:
5754
ValueError: If the timeout is not valid.

hume/_batch/batch_job_result.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from urllib.request import urlretrieve
77

88
from hume._batch.batch_job_status import BatchJobStatus
9-
from hume._common.model_type import ModelType
10-
from hume._common.config.job_config_base import JobConfigBase
11-
from hume._common.config.config_utils import config_from_model_type
12-
from hume._common.hume_client_error import HumeClientError
9+
from hume._common.config_utils import config_from_model_type
10+
from hume.error.hume_client_exception import HumeClientException
11+
from hume.models import ModelType
12+
from hume.models.config.model_config_base import ModelConfigBase
1313

1414

1515
class BatchJobResult:
@@ -18,7 +18,7 @@ class BatchJobResult:
1818
def __init__(
1919
self,
2020
*,
21-
configs: Dict[ModelType, JobConfigBase],
21+
configs: Dict[ModelType, ModelConfigBase],
2222
urls: List[str],
2323
status: BatchJobStatus,
2424
predictions_url: Optional[str] = None,
@@ -31,7 +31,7 @@ def __init__(
3131
"""Construct a BatchJobResult.
3232
3333
Args:
34-
configs (Dict[ModelType, JobConfigBase]): Configurations for the `BatchJob`.
34+
configs (Dict[ModelType, ModelConfigBase]): Configurations for the `BatchJob`.
3535
urls (List[str]): URLs processed in the `BatchJob`.
3636
status (BatchJobStatus): Status of `BatchJob`.
3737
predictions_url (Optional[str]): URL to predictions file.
@@ -58,7 +58,7 @@ def download_predictions(self, filepath: Optional[Union[str, Path]] = None) -> N
5858
filepath (Optional[Union[str, Path]]): Filepath where predictions will be downloaded.
5959
"""
6060
if self.predictions_url is None:
61-
raise HumeClientError("Could not download job predictions. No predictions found on job result.")
61+
raise HumeClientException("Could not download job predictions. No predictions found on job result.")
6262
urlretrieve(self.predictions_url, filepath)
6363

6464
def download_artifacts(self, filepath: Optional[Union[str, Path]] = None) -> None:
@@ -68,7 +68,7 @@ def download_artifacts(self, filepath: Optional[Union[str, Path]] = None) -> Non
6868
filepath (Optional[Union[str, Path]]): Filepath where artifacts zip archive will be downloaded.
6969
"""
7070
if self.artifacts_url is None:
71-
raise HumeClientError("Could not download job artifacts. No artifacts found on job result.")
71+
raise HumeClientException("Could not download job artifacts. No artifacts found on job result.")
7272
urlretrieve(self.artifacts_url, filepath)
7373

7474
def download_errors(self, filepath: Optional[Union[str, Path]] = None) -> None:
@@ -78,7 +78,7 @@ def download_errors(self, filepath: Optional[Union[str, Path]] = None) -> None:
7878
filepath (Optional[Union[str, Path]]): Filepath where errors will be downloaded.
7979
"""
8080
if self.errors_url is None:
81-
raise HumeClientError("Could not download job errors. No errors found on job result.")
81+
raise HumeClientException("Could not download job errors. No errors found on job result.")
8282
urlretrieve(self.errors_url, filepath)
8383

8484
def get_error_message(self) -> Optional[str]:
@@ -137,7 +137,7 @@ def from_response(cls, response: Any) -> "BatchJobResult":
137137
configs = {}
138138
for model_name, config_dict in request["models"].items():
139139
model_type = ModelType.from_str(model_name)
140-
config = config_from_model_type(model_type).deserialize(config_dict)
140+
config = config_from_model_type(model_type).from_dict(config_dict)
141141
configs[model_type] = config
142142

143143
kwargs = {}
@@ -167,7 +167,7 @@ def from_response(cls, response: Any) -> "BatchJobResult":
167167
# pylint: disable=broad-except
168168
except Exception as exc:
169169
message = cls._get_invalid_response_message(response)
170-
raise HumeClientError(message) from exc
170+
raise HumeClientException(message) from exc
171171

172172
@classmethod
173173
def _get_invalid_response_message(cls, response: Any) -> str:
@@ -178,6 +178,6 @@ def _get_invalid_response_message(cls, response: Any) -> str:
178178
if "fault" in response and "faultstring" in response["fault"]:
179179
fault_string = response["fault"]["faultstring"]
180180
if fault_string == "Invalid ApiKey":
181-
message = "Client initialized with invalid API key"
181+
message = "HumeBatchClient initialized with invalid API key."
182182

183183
return message

0 commit comments

Comments
 (0)