nucliadb 6.1.0.post2504__py3-none-any.whl → 6.1.0.post2507__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.
@@ -18,11 +18,14 @@
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  import base64
21
+ from io import BytesIO
21
22
  from typing import Optional
22
23
 
23
24
  from nucliadb.common.ids import ParagraphId
25
+ from nucliadb.ingest.fields.file import File
24
26
  from nucliadb.search import SERVICE_NAME
25
27
  from nucliadb_models.search import Image
28
+ from nucliadb_utils.storages.storage import Storage
26
29
  from nucliadb_utils.utilities import get_storage
27
30
 
28
31
 
@@ -64,14 +67,18 @@ async def get_paragraph_image(kbid: str, paragraph_id: ParagraphId, reference: s
64
67
  return image
65
68
 
66
69
 
67
- async def get_file_image(kbid: str, rid: str, field_id: str) -> Optional[Image]:
68
- storage = await get_storage(service_name=SERVICE_NAME)
69
- sf = storage.file_field(kbid, rid, field_id)
70
- image_bytes = (await sf.storage.downloadbytes(sf.bucket, sf.key)).read()
71
- if not image_bytes:
70
+ async def get_file_thumbnail_image(file: File) -> Optional[Image]:
71
+ fed = await file.get_file_extracted_data()
72
+ if fed is None or not fed.HasField("file_thumbnail"):
73
+ return None
74
+ storage: Storage = await get_storage(service_name=SERVICE_NAME)
75
+ image_bytes: BytesIO = await storage.downloadbytescf(fed.file_thumbnail)
76
+ value = image_bytes.getvalue()
77
+ if len(value) == 0:
72
78
  return None
73
79
  image = Image(
74
- b64encoded=base64.b64encode(image_bytes).decode(),
75
- content_type="image/png",
80
+ b64encoded=base64.b64encode(value).decode(),
81
+ # We assume the thumbnail is always generated as jpeg by Nuclia processing
82
+ content_type="image/jpeg",
76
83
  )
77
84
  return image
@@ -35,7 +35,7 @@ from nucliadb.ingest.orm.knowledgebox import KnowledgeBox as KnowledgeBoxORM
35
35
  from nucliadb.search import logger
36
36
  from nucliadb.search.search import cache
37
37
  from nucliadb.search.search.chat.images import (
38
- get_file_image,
38
+ get_file_thumbnail_image,
39
39
  get_page_image,
40
40
  get_paragraph_image,
41
41
  )
@@ -753,14 +753,10 @@ async def conversation_prompt_context(
753
753
  file_field: File = await resource.get_field(
754
754
  attachment.field_id, attachment.field_type, load=True
755
755
  ) # type: ignore
756
- field_metadata = await file_field.get_field_metadata()
757
- if field_metadata is not None and field_metadata.metadata.mime_type.startswith(
758
- "image"
759
- ):
760
- image = await get_file_image(kbid, rid, attachment.field_id)
761
- if image is not None:
762
- pid = f"{rid}/f/{attachment.field_id}/0-0"
763
- context.images[pid] = image
756
+ image = await get_file_thumbnail_image(file_field)
757
+ if image is not None:
758
+ pid = f"{rid}/f/{attachment.field_id}/0-0"
759
+ context.images[pid] = image
764
760
 
765
761
  analyzed_fields.append(field_unique_id)
766
762
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nucliadb
3
- Version: 6.1.0.post2504
3
+ Version: 6.1.0.post2507
4
4
  Home-page: https://docs.nuclia.dev/docs/management/nucliadb/intro
5
5
  Author: NucliaDB Community
6
6
  Author-email: nucliadb@nuclia.com
@@ -22,10 +22,10 @@ Classifier: Programming Language :: Python :: 3.12
22
22
  Classifier: Programming Language :: Python :: 3 :: Only
23
23
  Requires-Python: >=3.9, <4
24
24
  Description-Content-Type: text/markdown
25
- Requires-Dist: nucliadb-telemetry[all]>=6.1.0.post2504
26
- Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.1.0.post2504
27
- Requires-Dist: nucliadb-protos>=6.1.0.post2504
28
- Requires-Dist: nucliadb-models>=6.1.0.post2504
25
+ Requires-Dist: nucliadb-telemetry[all]>=6.1.0.post2507
26
+ Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.1.0.post2507
27
+ Requires-Dist: nucliadb-protos>=6.1.0.post2507
28
+ Requires-Dist: nucliadb-models>=6.1.0.post2507
29
29
  Requires-Dist: nucliadb-admin-assets>=1.0.0.post1224
30
30
  Requires-Dist: nucliadb-node-binding>=2.26.0
31
31
  Requires-Dist: uvicorn
@@ -229,8 +229,8 @@ nucliadb/search/search/utils.py,sha256=iF2tbBA56gRMJH1TlE2hMrqeXqjoeOPt4KgRdp2m9
229
229
  nucliadb/search/search/chat/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
230
230
  nucliadb/search/search/chat/ask.py,sha256=2ZIz3TbCG18X0eJZSfLc8nHyKToyrlv_SPFzOOcc5wU,33865
231
231
  nucliadb/search/search/chat/exceptions.py,sha256=Siy4GXW2L7oPhIR86H3WHBhE9lkV4A4YaAszuGGUf54,1356
232
- nucliadb/search/search/chat/images.py,sha256=2o5zimZF_YMa8Kkbugc5BxCBdmkCSILQuHHEEt49ilo,2791
233
- nucliadb/search/search/chat/prompt.py,sha256=ZQZZcrp911KKHmBOWfMRb4klbAHxn_bQl7nmVu74uws,46414
232
+ nucliadb/search/search/chat/images.py,sha256=PA8VWxT5_HUGfW1ULhKTK46UBsVyINtWWqEM1ulzX1E,3095
233
+ nucliadb/search/search/chat/prompt.py,sha256=mreHIjhIWCIGDlJ2CA7kv7KLgh8d09meoMX3-bvWje8,46152
234
234
  nucliadb/search/search/chat/query.py,sha256=gKtlj2ms81m417Id29-DtHFxE3M4TtJvYNB03gAgpYo,14402
235
235
  nucliadb/search/search/query_parser/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
236
236
  nucliadb/search/search/query_parser/exceptions.py,sha256=tuzl7ZyvVsRz6u0_3zMe60vx39nd3pi641prs-5nC0E,872
@@ -331,9 +331,9 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
331
331
  nucliadb/writer/tus/s3.py,sha256=vF0NkFTXiXhXq3bCVXXVV-ED38ECVoUeeYViP8uMqcU,8357
332
332
  nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
333
333
  nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
334
- nucliadb-6.1.0.post2504.dist-info/METADATA,sha256=vXm2SKesdaakWovns1MAt3f7inEItknaZKsAyBlkXTY,4390
335
- nucliadb-6.1.0.post2504.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
336
- nucliadb-6.1.0.post2504.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
337
- nucliadb-6.1.0.post2504.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
338
- nucliadb-6.1.0.post2504.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
339
- nucliadb-6.1.0.post2504.dist-info/RECORD,,
334
+ nucliadb-6.1.0.post2507.dist-info/METADATA,sha256=gKMwO_dELa98uXILkFVpuVeT4F-lVyO0FZ_yg47Qja8,4390
335
+ nucliadb-6.1.0.post2507.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
336
+ nucliadb-6.1.0.post2507.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
337
+ nucliadb-6.1.0.post2507.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
338
+ nucliadb-6.1.0.post2507.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
339
+ nucliadb-6.1.0.post2507.dist-info/RECORD,,