nucliadb 6.4.0.post4224__py3-none-any.whl → 6.4.0.post4241__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.
@@ -21,7 +21,7 @@ import json
21
21
  from typing import Union
22
22
 
23
23
  from fastapi import Request
24
- from fastapi.responses import JSONResponse, StreamingResponse
24
+ from fastapi.responses import Response, StreamingResponse
25
25
  from fastapi_versioning import version
26
26
 
27
27
  from nucliadb.common.datamanagers.exceptions import KnowledgeBoxNotFound
@@ -58,14 +58,19 @@ async def predict_proxy_endpoint(
58
58
  request: Request,
59
59
  kbid: str,
60
60
  endpoint: PredictProxiedEndpoints,
61
- ) -> Union[JSONResponse, StreamingResponse, HTTPClientError]:
61
+ ) -> Union[Response, StreamingResponse, HTTPClientError]:
62
62
  try:
63
63
  payload = await request.json()
64
64
  except json.JSONDecodeError:
65
65
  payload = None
66
66
  try:
67
67
  return await predict_proxy(
68
- kbid, endpoint, request.method, params=request.query_params, json=payload
68
+ kbid,
69
+ endpoint,
70
+ request.method,
71
+ params=request.query_params,
72
+ json=payload,
73
+ headers=dict(request.headers),
69
74
  )
70
75
  except KnowledgeBoxNotFound:
71
76
  return HTTPClientError(status_code=404, detail="Knowledge box not found")
@@ -262,7 +262,7 @@ class PredictEngine:
262
262
  jitter=backoff.random_jitter,
263
263
  max_tries=MAX_TRIES,
264
264
  )
265
- async def make_request(self, method: str, **request_args):
265
+ async def make_request(self, method: str, **request_args) -> aiohttp.ClientResponse:
266
266
  func = getattr(self.session, method.lower())
267
267
  return await func(**request_args)
268
268
 
@@ -311,8 +311,8 @@ class PredictEngine:
311
311
  timeout=None,
312
312
  )
313
313
  await self.check_response(kbid, resp, expected_status=200)
314
- ident = resp.headers.get(NUCLIA_LEARNING_ID_HEADER)
315
- model = resp.headers.get(NUCLIA_LEARNING_MODEL_HEADER)
314
+ ident = resp.headers.get(NUCLIA_LEARNING_ID_HEADER) or "unknown"
315
+ model = resp.headers.get(NUCLIA_LEARNING_MODEL_HEADER) or "unknown"
316
316
  return ident, model, get_chat_ndjson_generator(resp)
317
317
 
318
318
  @predict_observer.wrap({"type": "query"})
@@ -471,7 +471,9 @@ class DummyPredictEngine(PredictEngine):
471
471
 
472
472
  async def make_request(self, method: str, **request_args):
473
473
  response = Mock(status=200)
474
- response.json = AsyncMock(return_value={"foo": "bar"})
474
+ json_data = {"foo": "bar"}
475
+ response.json = AsyncMock(return_value=json_data)
476
+ response.read = AsyncMock(return_value=json.dumps(json_data).encode("utf-8"))
475
477
  response.headers = {NUCLIA_LEARNING_ID_HEADER: DUMMY_LEARNING_ID}
476
478
  return response
477
479
 
@@ -178,6 +178,7 @@ def add_resource_filter(request: Union[FindRequest, AskRequest], resources: list
178
178
 
179
179
  def find_request_from_ask_request(item: AskRequest, query: str) -> FindRequest:
180
180
  find_request = FindRequest()
181
+ find_request.filter_expression = item.filter_expression
181
182
  find_request.resource_filters = item.resource_filters
182
183
  find_request.features = []
183
184
  if ChatOptions.SEMANTIC in item.features:
@@ -21,7 +21,7 @@ from enum import Enum
21
21
  from typing import Any, Optional, Union
22
22
 
23
23
  from fastapi.datastructures import QueryParams
24
- from fastapi.responses import JSONResponse, StreamingResponse
24
+ from fastapi.responses import Response, StreamingResponse
25
25
 
26
26
  from nucliadb.common import datamanagers
27
27
  from nucliadb.search.predict import PredictEngine
@@ -42,20 +42,25 @@ class PredictProxiedEndpoints(str, Enum):
42
42
  REMI = "remi"
43
43
 
44
44
 
45
+ ALLOWED_HEADERS = [
46
+ "Accept", # To allow 'application/x-ndjson' on the /chat endpoint
47
+ ]
48
+
49
+
45
50
  async def predict_proxy(
46
51
  kbid: str,
47
52
  endpoint: PredictProxiedEndpoints,
48
53
  method: str,
49
54
  params: QueryParams,
50
55
  json: Optional[Any] = None,
51
- ) -> Union[JSONResponse, StreamingResponse]:
56
+ headers: dict[str, str] = {},
57
+ ) -> Union[Response, StreamingResponse]:
52
58
  if not await exists_kb(kbid=kbid):
53
59
  raise datamanagers.exceptions.KnowledgeBoxNotFound()
54
60
 
55
61
  predict: PredictEngine = get_predict()
56
-
57
- # Add KB configuration headers
58
- headers = predict.get_predict_headers(kbid)
62
+ predict_headers = predict.get_predict_headers(kbid)
63
+ user_headers = {k: v for k, v in headers.items() if k.capitalize() in ALLOWED_HEADERS}
59
64
 
60
65
  # Proxy the request to predict API
61
66
  predict_response = await predict.make_request(
@@ -63,22 +68,24 @@ async def predict_proxy(
63
68
  url=predict.get_predict_url(endpoint, kbid),
64
69
  json=json,
65
70
  params=params,
66
- headers=headers,
71
+ headers={**user_headers, **predict_headers},
67
72
  )
68
73
 
69
74
  # Proxy the response back to the client
70
75
  status_code = predict_response.status
71
- response: Union[JSONResponse, StreamingResponse]
76
+ media_type = predict_response.headers.get("Content-Type")
77
+ response: Union[Response, StreamingResponse]
72
78
  if predict_response.headers.get("Transfer-Encoding") == "chunked":
73
79
  response = StreamingResponse(
74
80
  content=predict_response.content.iter_any(),
75
81
  status_code=status_code,
76
- media_type=predict_response.headers.get("Content-Type"),
82
+ media_type=media_type,
77
83
  )
78
84
  else:
79
- response = JSONResponse(
80
- content=await predict_response.json(),
85
+ response = Response(
86
+ content=await predict_response.read(),
81
87
  status_code=status_code,
88
+ media_type=media_type,
82
89
  )
83
90
  nuclia_learning_id = predict_response.headers.get("NUCLIA-LEARNING-ID")
84
91
  if nuclia_learning_id:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nucliadb
3
- Version: 6.4.0.post4224
3
+ Version: 6.4.0.post4241
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.4.0.post4224
24
- Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.4.0.post4224
25
- Requires-Dist: nucliadb-protos>=6.4.0.post4224
26
- Requires-Dist: nucliadb-models>=6.4.0.post4224
27
- Requires-Dist: nidx-protos>=6.4.0.post4224
23
+ Requires-Dist: nucliadb-telemetry[all]>=6.4.0.post4241
24
+ Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.4.0.post4241
25
+ Requires-Dist: nucliadb-protos>=6.4.0.post4241
26
+ Requires-Dist: nucliadb-models>=6.4.0.post4241
27
+ Requires-Dist: nidx-protos>=6.4.0.post4241
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[standard]
@@ -204,7 +204,7 @@ nucliadb/search/__init__.py,sha256=tnypbqcH4nBHbGpkINudhKgdLKpwXQCvDtPchUlsyY4,1
204
204
  nucliadb/search/app.py,sha256=-WEX1AZRA8R_9aeOo9ovOTwjXW_7VfwWN7N2ccSoqXg,3387
205
205
  nucliadb/search/lifecycle.py,sha256=hiylV-lxsAWkqTCulXBg0EIfMQdejSr8Zar0L_GLFT8,2218
206
206
  nucliadb/search/openapi.py,sha256=t3Wo_4baTrfPftg2BHsyLWNZ1MYn7ZRdW7ht-wFOgRs,1016
207
- nucliadb/search/predict.py,sha256=VJr5Itx8FE7CZIGYcP-fRgd2YGxAnP9Qj9NxiwWiwcc,22819
207
+ nucliadb/search/predict.py,sha256=BYkKL2-3-MNT8JnE7y7XTEMKMnynUm2y4VJZP1jRjdQ,22987
208
208
  nucliadb/search/predict_models.py,sha256=ZAe0dneUsPmV9uBar57cCFADCGOrYDsJHuqKlA5zWag,5937
209
209
  nucliadb/search/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
210
210
  nucliadb/search/run.py,sha256=aFb-CXRi_C8YMpP_ivNj8KW1BYhADj88y8K9Lr_nUPI,1402
@@ -218,7 +218,7 @@ nucliadb/search/api/v1/feedback.py,sha256=kNLc4dHz2SXHzV0PwC1WiRAwY88fDptPcP-kO0
218
218
  nucliadb/search/api/v1/find.py,sha256=JFbGDRFBHBTApYR1qHp9RngbE_QDb96fXORMdjcN6lg,10654
219
219
  nucliadb/search/api/v1/graph.py,sha256=ItVpzJbqfDLjoIo2fTb2mKGCM1Z34sx7CBb3gNmj6IQ,4274
220
220
  nucliadb/search/api/v1/knowledgebox.py,sha256=e9xeLPUqnQTx33i4A8xuV93ENvtJGrpjPlLRbGJtAI8,8415
221
- nucliadb/search/api/v1/predict_proxy.py,sha256=QrGzo0hKjtmyGZ6pjlJHYAh4hxwVUIOTcVcerRCw7eE,3047
221
+ nucliadb/search/api/v1/predict_proxy.py,sha256=Q03ZTvWp7Sq0x71t5Br4LHxTiYsRd6-GCb4YuKqhynM,3131
222
222
  nucliadb/search/api/v1/router.py,sha256=mtT07rBZcVfpa49doaw9b1tj3sdi3qLH0gn9Io6NYM0,988
223
223
  nucliadb/search/api/v1/search.py,sha256=Or-mUvmBAyh0Y55NqTYNXe_BWR0lLLaTSL2ChjJaE2M,12402
224
224
  nucliadb/search/api/v1/suggest.py,sha256=Em7ApddZNHMHjL_ZfXmUIVUk504f58J96JlxJXnIxaM,6438
@@ -247,7 +247,7 @@ nucliadb/search/search/merge.py,sha256=Abg9YblQJvH2jDvXVT45MNxaIpNa7TTpsiUSJqb3N
247
247
  nucliadb/search/search/metrics.py,sha256=HJVQPLOIwLuc733G4keqEgx1-Dcg97hyWGKZQTojiSE,2973
248
248
  nucliadb/search/search/paragraphs.py,sha256=pNAEiYqJGGUVcEf7xf-PFMVqz0PX4Qb-WNG-_zPGN2o,7799
249
249
  nucliadb/search/search/pgcatalog.py,sha256=s_J98fsX_RuFXwpejpkGqG-tD9ELuzz4YQ6U3ew5h2g,9313
250
- nucliadb/search/search/predict_proxy.py,sha256=IFI3v_ODz2_UU1XZnyaD391fE7-2C0npSmj_HmDvzS4,3123
250
+ nucliadb/search/search/predict_proxy.py,sha256=JwgBeEg1j4LnCjPCvTUrnmOd9LceJAt3iAu4m9cmJBo,3390
251
251
  nucliadb/search/search/query.py,sha256=-gvKsyGmKYpsoEVzKkq3HJUMcs_3LD3TYUueOcJsTec,11511
252
252
  nucliadb/search/search/rank_fusion.py,sha256=xZtXhbmKb_56gs73u6KkFm2efvTATOSMmpOV2wrAIqE,9613
253
253
  nucliadb/search/search/rerankers.py,sha256=PvhExUb8zZYghiFHRgGotw6h6bU--Rft09wE8arvtAw,7424
@@ -259,7 +259,7 @@ nucliadb/search/search/chat/ask.py,sha256=jYOGh2rySV4aFx_D2KlNVbPXHBsbkcy0Ve-eBS
259
259
  nucliadb/search/search/chat/exceptions.py,sha256=Siy4GXW2L7oPhIR86H3WHBhE9lkV4A4YaAszuGGUf54,1356
260
260
  nucliadb/search/search/chat/images.py,sha256=PA8VWxT5_HUGfW1ULhKTK46UBsVyINtWWqEM1ulzX1E,3095
261
261
  nucliadb/search/search/chat/prompt.py,sha256=Jnja-Ss7skgnnDY8BymVfdeYsFPnIQFL8tEvcRXTKUE,47356
262
- nucliadb/search/search/chat/query.py,sha256=S6bRvCWcvU5sxsbUdamNAc8JFpuLAo7mggXm0MQ0p8g,16818
262
+ nucliadb/search/search/chat/query.py,sha256=IdVPeKLUbq4hWJ81LePWdUrljeyehnIXg-Ars-37msQ,16878
263
263
  nucliadb/search/search/query_parser/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
264
264
  nucliadb/search/search/query_parser/exceptions.py,sha256=szAOXUZ27oNY-OSa9t2hQ5HHkQQC0EX1FZz_LluJHJE,1224
265
265
  nucliadb/search/search/query_parser/fetcher.py,sha256=SkvBRDfSKmuz-QygNKLAU4AhZhhDo1dnOZmt1zA28RA,16851
@@ -368,8 +368,8 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
368
368
  nucliadb/writer/tus/s3.py,sha256=vF0NkFTXiXhXq3bCVXXVV-ED38ECVoUeeYViP8uMqcU,8357
369
369
  nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
370
370
  nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
371
- nucliadb-6.4.0.post4224.dist-info/METADATA,sha256=G9L1810f7GDMjI54RDmZj-ZcpBD3_duqsGRR2q3c6yY,4223
372
- nucliadb-6.4.0.post4224.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
373
- nucliadb-6.4.0.post4224.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
374
- nucliadb-6.4.0.post4224.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
375
- nucliadb-6.4.0.post4224.dist-info/RECORD,,
371
+ nucliadb-6.4.0.post4241.dist-info/METADATA,sha256=twJEtMMEkGzMqaXb2hvjgRRgPmvl4ESDTJuUw3ObLuk,4223
372
+ nucliadb-6.4.0.post4241.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
373
+ nucliadb-6.4.0.post4241.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
374
+ nucliadb-6.4.0.post4241.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
375
+ nucliadb-6.4.0.post4241.dist-info/RECORD,,