wavespeed 0.0.1__tar.gz → 0.0.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wavespeed
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Python client for Wavespeed
5
5
  Author: Wavespeed, Inc.
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wavespeed"
7
- version = "0.0.1"
7
+ version = "0.0.2"
8
8
  description = "Python client for Wavespeed"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -37,7 +37,7 @@ asyncio_mode = "auto"
37
37
  testpaths = "tests/"
38
38
 
39
39
  [tool.setuptools]
40
- packages = ["wavespeed"]
40
+ packages = ["wavespeed", "wavespeed.schemas"]
41
41
 
42
42
  [tool.setuptools.package-data]
43
43
  "wavespeed" = ["py.typed"]
@@ -0,0 +1,7 @@
1
+ """
2
+ Schemas for the Wavespeed API.
3
+ """
4
+
5
+ from .prediction import PredictionUrls, Prediction, PredictionResponse
6
+
7
+ __all__ = [ "PredictionUrls", "Prediction", "PredictionResponse"]
@@ -0,0 +1,76 @@
1
+ import asyncio
2
+ import logging
3
+ import time
4
+ from typing import List, Dict, Any, Optional
5
+ from datetime import datetime
6
+ from pydantic import BaseModel, Field
7
+ import pydantic
8
+ from typing import TYPE_CHECKING
9
+ if TYPE_CHECKING:
10
+ from wavespeed.client import Wavespeed
11
+
12
+ class PredictionUrls(BaseModel):
13
+ """URLs associated with a prediction."""
14
+ get: str
15
+
16
+
17
+ class Prediction(BaseModel):
18
+ """Response from a prediction API call."""
19
+ _client: "Wavespeed" = pydantic.PrivateAttr()
20
+
21
+ id: str
22
+ model: str
23
+ input: Dict[str, Any] | None = None
24
+ outputs: List[str]
25
+ urls: PredictionUrls
26
+ has_nsfw_contents: List[bool]
27
+ status: str
28
+ created_at: datetime
29
+ error: str = ""
30
+ executionTime: int
31
+
32
+ def wait(self) -> "Prediction":
33
+ while self.status not in ['completed', 'failed']:
34
+ time.sleep(self._client.poll_interval)
35
+ print('Waiting for prediction to complete: ', self.urls.get, type(self.urls.get))
36
+ response = self._client.client.get(self.urls.get)
37
+ response.raise_for_status()
38
+ data = response.json()['data']
39
+ self._update_from_dict(data)
40
+ return self
41
+
42
+ async def async_wait(self) -> "Prediction":
43
+ while self.status not in ['completed', 'failed']:
44
+ await asyncio.sleep(self._client.poll_interval)
45
+ response = await self._client.async_client.get(self.urls.get)
46
+ response.raise_for_status()
47
+ data = response.json()['data']
48
+ self._update_from_dict(data)
49
+ return self
50
+
51
+ async def async_reload(self) -> "Prediction":
52
+ response = await self._client.async_client.get(self.urls.get)
53
+ response.raise_for_status()
54
+ data = response.json()['data']
55
+ self._update_from_dict(data)
56
+ return self
57
+
58
+ def reload(self) -> "Prediction":
59
+ response = self._client.client.get(self.urls.get)
60
+ response.raise_for_status()
61
+ data = response.json()['data']
62
+ self._update_from_dict(data)
63
+ return self
64
+
65
+ def _update_from_dict(self, data: Dict[str, Any]) -> None:
66
+ """Update the object from a dictionary, handling nested objects properly."""
67
+ for key, value in data.items():
68
+ if key == 'urls' and isinstance(value, dict):
69
+ self.urls = PredictionUrls(**value)
70
+ elif hasattr(self, key):
71
+ setattr(self, key, value)
72
+
73
+ class PredictionResponse(BaseModel):
74
+ code: int
75
+ message: str
76
+ data: Prediction
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wavespeed
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Python client for Wavespeed
5
5
  Author: Wavespeed, Inc.
6
6
  License: MIT License
@@ -8,4 +8,6 @@ wavespeed.egg-info/PKG-INFO
8
8
  wavespeed.egg-info/SOURCES.txt
9
9
  wavespeed.egg-info/dependency_links.txt
10
10
  wavespeed.egg-info/requires.txt
11
- wavespeed.egg-info/top_level.txt
11
+ wavespeed.egg-info/top_level.txt
12
+ wavespeed/schemas/__init__.py
13
+ wavespeed/schemas/prediction.py
File without changes
File without changes
File without changes
File without changes