wavespeed 0.0.3__tar.gz → 0.0.4__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.
- {wavespeed-0.0.3 → wavespeed-0.0.4}/PKG-INFO +1 -1
- {wavespeed-0.0.3 → wavespeed-0.0.4}/pyproject.toml +1 -1
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed/client.py +18 -21
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed.egg-info/PKG-INFO +1 -1
- {wavespeed-0.0.3 → wavespeed-0.0.4}/LICENSE +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/README.md +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/setup.cfg +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/tests/test_client.py +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed/__init__.py +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed/schemas/__init__.py +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed/schemas/prediction.py +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed.egg-info/SOURCES.txt +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed.egg-info/dependency_links.txt +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed.egg-info/requires.txt +0 -0
- {wavespeed-0.0.3 → wavespeed-0.0.4}/wavespeed.egg-info/top_level.txt +0 -0
|
@@ -11,28 +11,29 @@ class WaveSpeed:
|
|
|
11
11
|
A client for interacting with the Wavespeed AI API.
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def __init__(self, api_key: str):
|
|
14
|
+
def __init__(self, api_key: str="", base_url: str = "https://api.wavespeed.ai/api/v2/", timeout: int | None = None):
|
|
17
15
|
"""
|
|
18
|
-
Initialize the
|
|
16
|
+
Initialize the WaveSpeed client.
|
|
19
17
|
|
|
20
18
|
Args:
|
|
21
|
-
api_key: Your
|
|
19
|
+
api_key: Your WaveSpeed API key
|
|
20
|
+
base_url: Base URL for the API
|
|
21
|
+
timeout: Timeout in seconds for http client send request
|
|
22
22
|
"""
|
|
23
23
|
self.api_key = api_key
|
|
24
|
-
if not api_key:
|
|
25
|
-
api_key = os.environ.get("WAVESPEED_API_KEY", '')
|
|
26
|
-
if not api_key:
|
|
24
|
+
if not self.api_key:
|
|
25
|
+
self.api_key = os.environ.get("WAVESPEED_API_KEY", '')
|
|
26
|
+
if not self.api_key:
|
|
27
27
|
raise ValueError("API key is required.")
|
|
28
28
|
self.headers = {
|
|
29
29
|
"Content-Type": "application/json",
|
|
30
|
-
"Authorization": f"Bearer {api_key}"
|
|
30
|
+
"Authorization": f"Bearer {self.api_key}"
|
|
31
31
|
}
|
|
32
|
-
self.async_client = httpx.AsyncClient(headers=self.headers)
|
|
33
|
-
self.client = httpx.Client(headers=self.headers)
|
|
34
|
-
self.
|
|
35
|
-
self.timeout =
|
|
32
|
+
self.async_client = httpx.AsyncClient(headers=self.headers, timeout=timeout)
|
|
33
|
+
self.client = httpx.Client(headers=self.headers, timeout=timeout)
|
|
34
|
+
self.base_url = base_url
|
|
35
|
+
self.timeout = timeout
|
|
36
|
+
self.poll_interval = float(os.environ.get("WAVESPEED_POLL_INTERVAL", 1))
|
|
36
37
|
|
|
37
38
|
async def async_run(
|
|
38
39
|
self,
|
|
@@ -51,7 +52,7 @@ class WaveSpeed:
|
|
|
51
52
|
Returns:
|
|
52
53
|
The API response as a dictionary
|
|
53
54
|
"""
|
|
54
|
-
url = urljoin(self.
|
|
55
|
+
url = urljoin(self.base_url, modelId)
|
|
55
56
|
|
|
56
57
|
payload = input
|
|
57
58
|
|
|
@@ -63,7 +64,6 @@ class WaveSpeed:
|
|
|
63
64
|
url,
|
|
64
65
|
headers=self.headers,
|
|
65
66
|
json=payload,
|
|
66
|
-
timeout=self.timeout
|
|
67
67
|
)
|
|
68
68
|
|
|
69
69
|
# Raise an exception for HTTP errors
|
|
@@ -90,7 +90,7 @@ class WaveSpeed:
|
|
|
90
90
|
Returns:
|
|
91
91
|
The API response as a dictionary
|
|
92
92
|
"""
|
|
93
|
-
url = urljoin(self.
|
|
93
|
+
url = urljoin(self.base_url, modelId)
|
|
94
94
|
|
|
95
95
|
payload = input
|
|
96
96
|
|
|
@@ -98,7 +98,6 @@ class WaveSpeed:
|
|
|
98
98
|
url,
|
|
99
99
|
headers=self.headers,
|
|
100
100
|
json=payload,
|
|
101
|
-
timeout=self.timeout
|
|
102
101
|
)
|
|
103
102
|
|
|
104
103
|
# Raise an exception for HTTP errors
|
|
@@ -109,13 +108,12 @@ class WaveSpeed:
|
|
|
109
108
|
return prediction.wait()
|
|
110
109
|
|
|
111
110
|
async def async_create(self, modelId: str, input: Dict[str, Any], **kwargs) -> Prediction:
|
|
112
|
-
url = urljoin(self.
|
|
111
|
+
url = urljoin(self.base_url, modelId)
|
|
113
112
|
payload = input
|
|
114
113
|
response = await self.async_client.post(
|
|
115
114
|
url,
|
|
116
115
|
headers=self.headers,
|
|
117
116
|
json=payload,
|
|
118
|
-
timeout=self.timeout
|
|
119
117
|
)
|
|
120
118
|
# Raise an exception for HTTP errors
|
|
121
119
|
response.raise_for_status()
|
|
@@ -125,13 +123,12 @@ class WaveSpeed:
|
|
|
125
123
|
return prediction
|
|
126
124
|
|
|
127
125
|
def create(self, modelId: str, input: Dict[str, Any], **kwargs) -> Prediction:
|
|
128
|
-
url = urljoin(self.
|
|
126
|
+
url = urljoin(self.base_url, modelId)
|
|
129
127
|
payload = input
|
|
130
128
|
response = self.client.post(
|
|
131
129
|
url,
|
|
132
130
|
headers=self.headers,
|
|
133
131
|
json=payload,
|
|
134
|
-
timeout=self.timeout
|
|
135
132
|
)
|
|
136
133
|
# Raise an exception for HTTP errors
|
|
137
134
|
response.raise_for_status()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|