embed-client 1.0.0__py3-none-any.whl → 1.0.0.1__py3-none-any.whl
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.
- embed_client/async_client.py +55 -4
- {embed_client-1.0.0.dist-info → embed_client-1.0.0.1.dist-info}/METADATA +1 -1
- embed_client-1.0.0.1.dist-info/RECORD +8 -0
- embed_client-1.0.0.dist-info/RECORD +0 -8
- {embed_client-1.0.0.dist-info → embed_client-1.0.0.1.dist-info}/WHEEL +0 -0
- {embed_client-1.0.0.dist-info → embed_client-1.0.0.1.dist-info}/top_level.txt +0 -0
embed_client/async_client.py
CHANGED
@@ -153,6 +153,37 @@ class EmbeddingServiceAsyncClient:
|
|
153
153
|
except Exception as e:
|
154
154
|
raise EmbeddingServiceError(f"Unexpected error: {e}") from e
|
155
155
|
|
156
|
+
def _validate_texts(self, texts: List[str]) -> None:
|
157
|
+
"""
|
158
|
+
Validate input texts before sending to the API.
|
159
|
+
Args:
|
160
|
+
texts (List[str]): List of texts to validate
|
161
|
+
Raises:
|
162
|
+
EmbeddingServiceAPIError: If texts are invalid
|
163
|
+
"""
|
164
|
+
if not texts:
|
165
|
+
raise EmbeddingServiceAPIError({
|
166
|
+
"code": -32602,
|
167
|
+
"message": "Empty texts list provided"
|
168
|
+
})
|
169
|
+
|
170
|
+
invalid_texts = []
|
171
|
+
for i, text in enumerate(texts):
|
172
|
+
if not isinstance(text, str):
|
173
|
+
invalid_texts.append(f"Text at index {i} is not a string")
|
174
|
+
continue
|
175
|
+
if not text or not text.strip():
|
176
|
+
invalid_texts.append(f"Text at index {i} is empty or contains only whitespace")
|
177
|
+
elif len(text.strip()) < 2: # Минимальная длина текста
|
178
|
+
invalid_texts.append(f"Text at index {i} is too short (minimum 2 characters)")
|
179
|
+
|
180
|
+
if invalid_texts:
|
181
|
+
raise EmbeddingServiceAPIError({
|
182
|
+
"code": -32602,
|
183
|
+
"message": "Invalid input texts",
|
184
|
+
"details": invalid_texts
|
185
|
+
})
|
186
|
+
|
156
187
|
async def cmd(self, command: str, params: Optional[Dict[str, Any]] = None, base_url: Optional[str] = None, port: Optional[int] = None) -> Dict[str, Any]:
|
157
188
|
"""
|
158
189
|
Execute a command via JSON-RPC protocol.
|
@@ -166,7 +197,8 @@ class EmbeddingServiceAsyncClient:
|
|
166
197
|
{
|
167
198
|
"error": {
|
168
199
|
"code": <код ошибки>,
|
169
|
-
"message": <сообщение об
|
200
|
+
"message": <сообщение об ошибке>,
|
201
|
+
"details": <опциональные детали ошибки>
|
170
202
|
}
|
171
203
|
}
|
172
204
|
или
|
@@ -180,31 +212,50 @@ class EmbeddingServiceAsyncClient:
|
|
180
212
|
}
|
181
213
|
"""
|
182
214
|
if not command:
|
183
|
-
raise EmbeddingServiceAPIError(
|
215
|
+
raise EmbeddingServiceAPIError({
|
216
|
+
"code": -32602,
|
217
|
+
"message": "Command is required"
|
218
|
+
})
|
219
|
+
|
220
|
+
# Валидация текстов для команды embed
|
221
|
+
if command == "embed" and params and "texts" in params:
|
222
|
+
self._validate_texts(params["texts"])
|
223
|
+
|
184
224
|
url = self._make_url("/cmd", base_url, port)
|
185
225
|
payload = {"command": command}
|
186
226
|
if params is not None:
|
187
227
|
payload["params"] = params
|
228
|
+
|
188
229
|
try:
|
189
230
|
async with self._session.post(url, json=payload) as resp:
|
190
231
|
await self._raise_for_status(resp)
|
191
232
|
data = await resp.json()
|
233
|
+
|
192
234
|
if "error" in data:
|
193
235
|
raise EmbeddingServiceAPIError(data["error"])
|
236
|
+
|
194
237
|
if "result" in data:
|
195
238
|
res = data["result"]
|
196
239
|
if isinstance(res, dict) and "success" in res and res["success"] is False:
|
197
240
|
if "error" in res:
|
198
241
|
raise EmbeddingServiceAPIError(res["error"])
|
242
|
+
|
199
243
|
return data
|
244
|
+
|
200
245
|
except aiohttp.ClientConnectionError as e:
|
201
|
-
raise EmbeddingServiceAPIError(
|
246
|
+
raise EmbeddingServiceAPIError({
|
247
|
+
"code": -32000,
|
248
|
+
"message": f"Connection error: {e}"
|
249
|
+
}) from e
|
202
250
|
except aiohttp.ClientResponseError as e:
|
203
251
|
raise EmbeddingServiceHTTPError(e.status, e.message) from e
|
204
252
|
except EmbeddingServiceHTTPError:
|
205
253
|
raise
|
206
254
|
except Exception as e:
|
207
|
-
raise EmbeddingServiceAPIError(
|
255
|
+
raise EmbeddingServiceAPIError({
|
256
|
+
"code": -32000,
|
257
|
+
"message": f"Unexpected error: {e}"
|
258
|
+
}) from e
|
208
259
|
|
209
260
|
async def _raise_for_status(self, resp: aiohttp.ClientResponse):
|
210
261
|
try:
|
@@ -0,0 +1,8 @@
|
|
1
|
+
embed_client/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
|
2
|
+
embed_client/async_client.py,sha256=sppZ8fPr4XNNLE3M6kLFTL6u5HE3nqo87bxAgt0S0zE,10589
|
3
|
+
embed_client/example_async_usage.py,sha256=df0RRwq2FtqVSL2MHVclfVIJj1wyQUuKZXB-lyVb3Kg,2538
|
4
|
+
embed_client/example_async_usage_ru.py,sha256=kZXQcbEFkx9tWXoCq-AoyvvUY4aCuW1XqPVb1ADWeAM,3558
|
5
|
+
embed_client-1.0.0.1.dist-info/METADATA,sha256=nFDbLecEwcLOuqhJe84hSdboS9vCEhmmX-Ajw9LYark,254
|
6
|
+
embed_client-1.0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
embed_client-1.0.0.1.dist-info/top_level.txt,sha256=uG00A4d9o9DFrhiN7goObpeig72Pniby0E7UpDRgyXY,13
|
8
|
+
embed_client-1.0.0.1.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
embed_client/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
|
2
|
-
embed_client/async_client.py,sha256=twSw-YhWdo1yeQLkfbi6ldCrq647TrEhEbPigpsAX6U,8802
|
3
|
-
embed_client/example_async_usage.py,sha256=df0RRwq2FtqVSL2MHVclfVIJj1wyQUuKZXB-lyVb3Kg,2538
|
4
|
-
embed_client/example_async_usage_ru.py,sha256=kZXQcbEFkx9tWXoCq-AoyvvUY4aCuW1XqPVb1ADWeAM,3558
|
5
|
-
embed_client-1.0.0.dist-info/METADATA,sha256=vsgnbBHhgvu1Mkj-NV-iUFs0w03aqSSe1Ju6kDECHk0,252
|
6
|
-
embed_client-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
-
embed_client-1.0.0.dist-info/top_level.txt,sha256=uG00A4d9o9DFrhiN7goObpeig72Pniby0E7UpDRgyXY,13
|
8
|
-
embed_client-1.0.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|