nucliadb 6.3.4.post3799__py3-none-any.whl → 6.3.4.post3812__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.
@@ -19,6 +19,7 @@
19
19
  #
20
20
  import base64
21
21
  import json
22
+ import logging
22
23
  import os
23
24
  import random
24
25
  from enum import Enum
@@ -216,13 +217,16 @@ class PredictEngine:
216
217
  else:
217
218
  return {"X-STF-KBID": kbid}
218
219
 
219
- async def check_response(self, resp: aiohttp.ClientResponse, expected_status: int = 200) -> None:
220
+ async def check_response(
221
+ self, kbid: str, resp: aiohttp.ClientResponse, expected_status: int = 200
222
+ ) -> None:
220
223
  if resp.status == expected_status:
221
224
  return
222
225
 
223
226
  if resp.status == 402:
224
227
  data = await resp.json()
225
228
  raise LimitsExceededError(402, data["detail"])
229
+
226
230
  try:
227
231
  data = await resp.json()
228
232
  try:
@@ -234,10 +238,22 @@ class PredictEngine:
234
238
  aiohttp.client_exceptions.ContentTypeError,
235
239
  ):
236
240
  detail = await resp.text()
237
- if str(resp.status).startswith("5"):
238
- logger.error(f"Predict API error at {resp.url}: {detail}")
239
- else:
240
- logger.info(f"Predict API error at {resp.url}: {detail}")
241
+
242
+ is_5xx_error = resp.status > 499
243
+ # NOTE: 512 is a special status code sent by learning predict api indicating that the error
244
+ # is related to an external generative model, so we don't want to log it as an error
245
+ is_external_generative_error = resp.status == 512
246
+ log_level = logging.ERROR if is_5xx_error and not is_external_generative_error else logging.INFO
247
+ logger.log(
248
+ log_level,
249
+ "Predict API error",
250
+ extra=dict(
251
+ kbid=kbid,
252
+ url=resp.url,
253
+ status_code=resp.status,
254
+ detail=detail,
255
+ ),
256
+ )
241
257
  raise ProxiedPredictAPIError(status=resp.status, detail=detail)
242
258
 
243
259
  @backoff.on_exception(
@@ -265,7 +281,7 @@ class PredictEngine:
265
281
  json=item.model_dump(),
266
282
  headers=self.get_predict_headers(kbid),
267
283
  )
268
- await self.check_response(resp, expected_status=200)
284
+ await self.check_response(kbid, resp, expected_status=200)
269
285
  return await _parse_rephrase_response(resp)
270
286
 
271
287
  @predict_observer.wrap({"type": "chat_ndjson"})
@@ -294,7 +310,7 @@ class PredictEngine:
294
310
  headers=headers,
295
311
  timeout=None,
296
312
  )
297
- await self.check_response(resp, expected_status=200)
313
+ await self.check_response(kbid, resp, expected_status=200)
298
314
  ident = resp.headers.get(NUCLIA_LEARNING_ID_HEADER)
299
315
  model = resp.headers.get(NUCLIA_LEARNING_MODEL_HEADER)
300
316
  return ident, model, get_chat_ndjson_generator(resp)
@@ -348,7 +364,7 @@ class PredictEngine:
348
364
  params=params,
349
365
  headers=self.get_predict_headers(kbid),
350
366
  )
351
- await self.check_response(resp, expected_status=200)
367
+ await self.check_response(kbid, resp, expected_status=200)
352
368
  data = await resp.json()
353
369
  return QueryInfo(**data)
354
370
 
@@ -368,7 +384,7 @@ class PredictEngine:
368
384
  params={"text": sentence},
369
385
  headers=self.get_predict_headers(kbid),
370
386
  )
371
- await self.check_response(resp, expected_status=200)
387
+ await self.check_response(kbid, resp, expected_status=200)
372
388
  data = await resp.json()
373
389
  return convert_relations(data)
374
390
 
@@ -387,7 +403,7 @@ class PredictEngine:
387
403
  headers=self.get_predict_headers(kbid),
388
404
  timeout=None,
389
405
  )
390
- await self.check_response(resp, expected_status=200)
406
+ await self.check_response(kbid, resp, expected_status=200)
391
407
  data = await resp.json()
392
408
  return SummarizedResponse.model_validate(data)
393
409
 
@@ -405,7 +421,7 @@ class PredictEngine:
405
421
  json=item.model_dump(),
406
422
  headers=self.get_predict_headers(kbid),
407
423
  )
408
- await self.check_response(resp, expected_status=200)
424
+ await self.check_response(kbid, resp, expected_status=200)
409
425
  data = await resp.json()
410
426
  return RerankResponse.model_validate(data)
411
427
 
@@ -423,7 +439,7 @@ class PredictEngine:
423
439
  json=item.model_dump(),
424
440
  headers=self.get_predict_headers(kbid),
425
441
  )
426
- await self.check_response(resp, expected_status=200)
442
+ await self.check_response(kbid, resp, expected_status=200)
427
443
  data = await resp.json()
428
444
  return RunAgentsResponse.model_validate(data)
429
445
 
@@ -66,7 +66,7 @@ async def create_kb_endpoint(request: Request, item: KnowledgeBoxConfig) -> Know
66
66
  except KnowledgeBoxConflict:
67
67
  raise HTTPException(status_code=419, detail="Knowledge box already exists")
68
68
  except ExternalIndexCreationError as exc:
69
- raise HTTPException(status_code=502, detail=str(exc))
69
+ raise HTTPException(status_code=512, detail=str(exc))
70
70
  except Exception:
71
71
  logger.exception("Could not create KB")
72
72
  raise HTTPException(status_code=500, detail="Error creating knowledge box")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nucliadb
3
- Version: 6.3.4.post3799
3
+ Version: 6.3.4.post3812
4
4
  Summary: NucliaDB
5
5
  Author-email: Nuclia <nucliadb@nuclia.com>
6
6
  License: AGPL
@@ -20,11 +20,11 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3 :: Only
21
21
  Requires-Python: <4,>=3.9
22
22
  Description-Content-Type: text/markdown
23
- Requires-Dist: nucliadb-telemetry[all]>=6.3.4.post3799
24
- Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.3.4.post3799
25
- Requires-Dist: nucliadb-protos>=6.3.4.post3799
26
- Requires-Dist: nucliadb-models>=6.3.4.post3799
27
- Requires-Dist: nidx-protos>=6.3.4.post3799
23
+ Requires-Dist: nucliadb-telemetry[all]>=6.3.4.post3812
24
+ Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.3.4.post3812
25
+ Requires-Dist: nucliadb-protos>=6.3.4.post3812
26
+ Requires-Dist: nucliadb-models>=6.3.4.post3812
27
+ Requires-Dist: nidx-protos>=6.3.4.post3812
28
28
  Requires-Dist: nucliadb-admin-assets>=1.0.0.post1224
29
29
  Requires-Dist: nuclia-models>=0.24.2
30
30
  Requires-Dist: uvicorn
@@ -193,7 +193,7 @@ nucliadb/search/__init__.py,sha256=tnypbqcH4nBHbGpkINudhKgdLKpwXQCvDtPchUlsyY4,1
193
193
  nucliadb/search/app.py,sha256=-WEX1AZRA8R_9aeOo9ovOTwjXW_7VfwWN7N2ccSoqXg,3387
194
194
  nucliadb/search/lifecycle.py,sha256=V_Pj5PRP0yyDY8d5LytO4X8p9HhN7UomqRG6Ri0UaFA,2206
195
195
  nucliadb/search/openapi.py,sha256=t3Wo_4baTrfPftg2BHsyLWNZ1MYn7ZRdW7ht-wFOgRs,1016
196
- nucliadb/search/predict.py,sha256=z2-RkhMkH-5T6PtFkfESxNof07XiS5FxicLHPRyCUXc,22284
196
+ nucliadb/search/predict.py,sha256=VJr5Itx8FE7CZIGYcP-fRgd2YGxAnP9Qj9NxiwWiwcc,22819
197
197
  nucliadb/search/predict_models.py,sha256=ZAe0dneUsPmV9uBar57cCFADCGOrYDsJHuqKlA5zWag,5937
198
198
  nucliadb/search/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
199
199
  nucliadb/search/run.py,sha256=aFb-CXRi_C8YMpP_ivNj8KW1BYhADj88y8K9Lr_nUPI,1402
@@ -331,7 +331,7 @@ nucliadb/writer/api/utils.py,sha256=wIQHlU8RQiIGVLI72suvyVIKlCU44Unh0Ae0IiN6Qwo,
331
331
  nucliadb/writer/api/v1/__init__.py,sha256=akI9A_jloNLb0dU4T5zjfdyvmSAiDeIdjAlzNx74FlU,1128
332
332
  nucliadb/writer/api/v1/export_import.py,sha256=elf-EQY5DD3mhw8kWb9tQpDcbrF9sY6VFYqxQOjuVP0,8201
333
333
  nucliadb/writer/api/v1/field.py,sha256=FySCMpcruSAKGeepeAlOihjwxyUPcDO73Uilq5VDWRk,18514
334
- nucliadb/writer/api/v1/knowledgebox.py,sha256=MLeIuym4jPrJgfy1NTcN9CpUGwuBiqDHMcx0hY9DR7g,9530
334
+ nucliadb/writer/api/v1/knowledgebox.py,sha256=PHEYDFa-sN5JrI8-EiVVg5FDOsRuCLT43kyAB4xt-xA,9530
335
335
  nucliadb/writer/api/v1/learning_config.py,sha256=CKBjqcbewkfPwGUPLDWzZSpro6XkmCaVppe5Qtpu5Go,3117
336
336
  nucliadb/writer/api/v1/resource.py,sha256=jV9HM-ID1PPYypfy4Sl4_9aSPF87v7gSJZUSzHjHcQ4,19740
337
337
  nucliadb/writer/api/v1/router.py,sha256=RjuoWLpZer6Kl2BW_wznpNo6XL3BOpdTGqXZCn3QrrQ,1034
@@ -354,8 +354,8 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
354
354
  nucliadb/writer/tus/s3.py,sha256=vF0NkFTXiXhXq3bCVXXVV-ED38ECVoUeeYViP8uMqcU,8357
355
355
  nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
356
356
  nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
357
- nucliadb-6.3.4.post3799.dist-info/METADATA,sha256=uH02kQKeWrB090Tk5FIcFC7uOW1veqoU6D9BO4lY0os,4291
358
- nucliadb-6.3.4.post3799.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
359
- nucliadb-6.3.4.post3799.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
360
- nucliadb-6.3.4.post3799.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
361
- nucliadb-6.3.4.post3799.dist-info/RECORD,,
357
+ nucliadb-6.3.4.post3812.dist-info/METADATA,sha256=yjF1rSCHEhQiCv7vEdwAPyTtjrWrsKJgae-L39Y_zE8,4291
358
+ nucliadb-6.3.4.post3812.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
359
+ nucliadb-6.3.4.post3812.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
360
+ nucliadb-6.3.4.post3812.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
361
+ nucliadb-6.3.4.post3812.dist-info/RECORD,,