nucliadb 6.5.1.post4504__py3-none-any.whl → 6.5.1.post4507__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.
- nucliadb/search/search/chat/prompt.py +40 -16
- {nucliadb-6.5.1.post4504.dist-info → nucliadb-6.5.1.post4507.dist-info}/METADATA +6 -6
- {nucliadb-6.5.1.post4504.dist-info → nucliadb-6.5.1.post4507.dist-info}/RECORD +6 -6
- {nucliadb-6.5.1.post4504.dist-info → nucliadb-6.5.1.post4507.dist-info}/WHEEL +0 -0
- {nucliadb-6.5.1.post4504.dist-info → nucliadb-6.5.1.post4507.dist-info}/entry_points.txt +0 -0
- {nucliadb-6.5.1.post4504.dist-info → nucliadb-6.5.1.post4507.dist-info}/top_level.txt +0 -0
@@ -100,33 +100,58 @@ class CappedPromptContext:
|
|
100
100
|
self.output: PromptContext = {}
|
101
101
|
self.images: PromptContextImages = {}
|
102
102
|
self.max_size = max_size
|
103
|
-
self._size = 0
|
104
103
|
|
105
104
|
def __setitem__(self, key: str, value: str) -> None:
|
106
|
-
|
107
|
-
if self.max_size is None:
|
108
|
-
# Unbounded size context
|
109
|
-
to_add = value
|
110
|
-
else:
|
111
|
-
# Make sure we don't exceed the max size
|
112
|
-
size_available = max(self.max_size - self._size + prev_value_len, 0)
|
113
|
-
to_add = value[:size_available]
|
114
|
-
self.output[key] = to_add
|
115
|
-
self._size = self._size - prev_value_len + len(to_add)
|
105
|
+
self.output.__setitem__(key, value)
|
116
106
|
|
117
107
|
def __getitem__(self, key: str) -> str:
|
118
108
|
return self.output.__getitem__(key)
|
119
109
|
|
120
110
|
def __delitem__(self, key: str) -> None:
|
121
|
-
|
122
|
-
|
111
|
+
try:
|
112
|
+
self.output.__delitem__(key)
|
113
|
+
except KeyError:
|
114
|
+
pass
|
123
115
|
|
124
116
|
def text_block_ids(self) -> list[str]:
|
125
117
|
return list(self.output.keys())
|
126
118
|
|
127
119
|
@property
|
128
120
|
def size(self) -> int:
|
129
|
-
|
121
|
+
"""
|
122
|
+
Returns the total size of the context in characters.
|
123
|
+
"""
|
124
|
+
return sum(len(text) for text in self.output.values())
|
125
|
+
|
126
|
+
def cap(self) -> dict[str, str]:
|
127
|
+
"""
|
128
|
+
This method will trim the context to the maximum size if it exceeds it.
|
129
|
+
It will remove text from the most recent entries first, until the size is below the limit.
|
130
|
+
"""
|
131
|
+
if self.max_size is None:
|
132
|
+
return self.output
|
133
|
+
|
134
|
+
if self.size <= self.max_size:
|
135
|
+
return self.output
|
136
|
+
|
137
|
+
logger.info("Removing text from context to fit within the max size limit")
|
138
|
+
# Iterate the dictionary in reverse order of insertion
|
139
|
+
for key in reversed(list(self.output.keys())):
|
140
|
+
current_size = self.size
|
141
|
+
if current_size <= self.max_size:
|
142
|
+
break
|
143
|
+
# Remove text from the value
|
144
|
+
text = self.output[key]
|
145
|
+
# If removing the whole text still keeps the total size above the limit, remove it
|
146
|
+
if current_size - len(text) >= self.max_size:
|
147
|
+
del self.output[key]
|
148
|
+
else:
|
149
|
+
# Otherwise, trim the text to fit within the limit
|
150
|
+
excess_size = current_size - self.max_size
|
151
|
+
if excess_size > 0:
|
152
|
+
trimmed_text = text[:-excess_size]
|
153
|
+
self.output[key] = trimmed_text
|
154
|
+
return self.output
|
130
155
|
|
131
156
|
|
132
157
|
async def get_next_conversation_messages(
|
@@ -1001,12 +1026,11 @@ class PromptContextBuilder:
|
|
1001
1026
|
self,
|
1002
1027
|
) -> tuple[PromptContext, PromptContextOrder, PromptContextImages, AugmentedContext]:
|
1003
1028
|
ccontext = CappedPromptContext(max_size=self.max_context_characters)
|
1004
|
-
print(".......................")
|
1005
1029
|
self.prepend_user_context(ccontext)
|
1006
1030
|
await self._build_context(ccontext)
|
1007
1031
|
if self.visual_llm:
|
1008
1032
|
await self._build_context_images(ccontext)
|
1009
|
-
context = ccontext.
|
1033
|
+
context = ccontext.cap()
|
1010
1034
|
context_images = ccontext.images
|
1011
1035
|
context_order = {text_block_id: order for order, text_block_id in enumerate(context.keys())}
|
1012
1036
|
return context, context_order, context_images, self.augmented_context
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nucliadb
|
3
|
-
Version: 6.5.1.
|
3
|
+
Version: 6.5.1.post4507
|
4
4
|
Summary: NucliaDB
|
5
5
|
Author-email: Nuclia <nucliadb@nuclia.com>
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
@@ -19,11 +19,11 @@ Classifier: Programming Language :: Python :: 3.12
|
|
19
19
|
Classifier: Programming Language :: Python :: 3 :: Only
|
20
20
|
Requires-Python: <4,>=3.9
|
21
21
|
Description-Content-Type: text/markdown
|
22
|
-
Requires-Dist: nucliadb-telemetry[all]>=6.5.1.
|
23
|
-
Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.5.1.
|
24
|
-
Requires-Dist: nucliadb-protos>=6.5.1.
|
25
|
-
Requires-Dist: nucliadb-models>=6.5.1.
|
26
|
-
Requires-Dist: nidx-protos>=6.5.1.
|
22
|
+
Requires-Dist: nucliadb-telemetry[all]>=6.5.1.post4507
|
23
|
+
Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.5.1.post4507
|
24
|
+
Requires-Dist: nucliadb-protos>=6.5.1.post4507
|
25
|
+
Requires-Dist: nucliadb-models>=6.5.1.post4507
|
26
|
+
Requires-Dist: nidx-protos>=6.5.1.post4507
|
27
27
|
Requires-Dist: nucliadb-admin-assets>=1.0.0.post1224
|
28
28
|
Requires-Dist: nuclia-models>=0.24.2
|
29
29
|
Requires-Dist: uvicorn[standard]
|
@@ -266,7 +266,7 @@ nucliadb/search/search/chat/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn
|
|
266
266
|
nucliadb/search/search/chat/ask.py,sha256=0sgfiCbNaCZrTvYaRGtf5xL6VnzRgzofINiEP4IvhWs,38278
|
267
267
|
nucliadb/search/search/chat/exceptions.py,sha256=Siy4GXW2L7oPhIR86H3WHBhE9lkV4A4YaAszuGGUf54,1356
|
268
268
|
nucliadb/search/search/chat/images.py,sha256=PA8VWxT5_HUGfW1ULhKTK46UBsVyINtWWqEM1ulzX1E,3095
|
269
|
-
nucliadb/search/search/chat/prompt.py,sha256=
|
269
|
+
nucliadb/search/search/chat/prompt.py,sha256=SNsCtB9mZTODjnUMAH8YfPxn05Kjl2d5xTIteNxyVcI,52783
|
270
270
|
nucliadb/search/search/chat/query.py,sha256=3jMPNbiFEOoS0ydMOPYkSx1qVlvAv51npzadWXDwkMs,16650
|
271
271
|
nucliadb/search/search/query_parser/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
|
272
272
|
nucliadb/search/search/query_parser/exceptions.py,sha256=sVl9gRNzhE-s480LBBVkiXzNRbKhYRQN5F3it5tNNp8,939
|
@@ -375,8 +375,8 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
|
|
375
375
|
nucliadb/writer/tus/s3.py,sha256=vF0NkFTXiXhXq3bCVXXVV-ED38ECVoUeeYViP8uMqcU,8357
|
376
376
|
nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
|
377
377
|
nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
|
378
|
-
nucliadb-6.5.1.
|
379
|
-
nucliadb-6.5.1.
|
380
|
-
nucliadb-6.5.1.
|
381
|
-
nucliadb-6.5.1.
|
382
|
-
nucliadb-6.5.1.
|
378
|
+
nucliadb-6.5.1.post4507.dist-info/METADATA,sha256=mXI1_xVFcW5gf0mv4h3PdH3RYyaqAUTt6UlvPEU2gb4,4158
|
379
|
+
nucliadb-6.5.1.post4507.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
380
|
+
nucliadb-6.5.1.post4507.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
|
381
|
+
nucliadb-6.5.1.post4507.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
|
382
|
+
nucliadb-6.5.1.post4507.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|