nuclia 4.9.2__py3-none-any.whl → 4.9.4__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.
- nuclia/lib/kb.py +25 -6
- nuclia/lib/nua.py +141 -21
- nuclia/lib/nua_responses.py +19 -0
- nuclia/sdk/kb.py +10 -2
- nuclia/sdk/predict.py +175 -28
- nuclia/sdk/search.py +68 -11
- nuclia/tests/test_kb/test_search.py +5 -1
- nuclia/tests/test_nua/test_predict.py +93 -5
- {nuclia-4.9.2.dist-info → nuclia-4.9.4.dist-info}/METADATA +4 -4
- {nuclia-4.9.2.dist-info → nuclia-4.9.4.dist-info}/RECORD +14 -14
- {nuclia-4.9.2.dist-info → nuclia-4.9.4.dist-info}/WHEEL +0 -0
- {nuclia-4.9.2.dist-info → nuclia-4.9.4.dist-info}/entry_points.txt +0 -0
- {nuclia-4.9.2.dist-info → nuclia-4.9.4.dist-info}/licenses/LICENSE +0 -0
- {nuclia-4.9.2.dist-info → nuclia-4.9.4.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,9 @@
|
|
1
|
-
from nuclia_models.predict.generative_responses import
|
1
|
+
from nuclia_models.predict.generative_responses import (
|
2
|
+
TextGenerativeResponse,
|
3
|
+
ConsumptionGenerative,
|
4
|
+
)
|
2
5
|
|
3
|
-
from nuclia.lib.nua_responses import ChatModel, UserPrompt
|
6
|
+
from nuclia.lib.nua_responses import ChatModel, RerankModel, UserPrompt
|
4
7
|
from nuclia.sdk.predict import AsyncNucliaPredict, NucliaPredict
|
5
8
|
import pytest
|
6
9
|
from nuclia_models.predict.remi import RemiRequest
|
@@ -8,9 +11,12 @@ from nuclia_models.predict.remi import RemiRequest
|
|
8
11
|
|
9
12
|
def test_predict(testing_config):
|
10
13
|
np = NucliaPredict()
|
11
|
-
embed = np.sentence(
|
14
|
+
embed = np.sentence(
|
15
|
+
text="This is my text", model="multilingual-2024-05-06", show_consumption=True
|
16
|
+
)
|
12
17
|
assert embed.time > 0
|
13
18
|
assert len(embed.data) == 1024
|
19
|
+
assert embed.consumption is not None
|
14
20
|
|
15
21
|
|
16
22
|
def test_predict_query(testing_config):
|
@@ -20,11 +26,14 @@ def test_predict_query(testing_config):
|
|
20
26
|
semantic_model="multilingual-2024-05-06",
|
21
27
|
token_model="multilingual",
|
22
28
|
generative_model="chatgpt-azure-4o-mini",
|
29
|
+
show_consumption=True,
|
23
30
|
)
|
24
31
|
assert query.language == "en"
|
25
32
|
assert query.visual_llm is True
|
26
33
|
assert query.entities and query.entities.tokens[0].text == "Ramon"
|
27
34
|
assert query.sentence and len(query.sentence.data) == 1024
|
35
|
+
assert query.entities.consumption is not None
|
36
|
+
assert query.sentence.consumption is not None
|
28
37
|
|
29
38
|
|
30
39
|
def test_rag(testing_config):
|
@@ -36,14 +45,34 @@ def test_rag(testing_config):
|
|
36
45
|
"Eudald Camprubí is CEO at the same company as Ramon Navarro",
|
37
46
|
],
|
38
47
|
model="chatgpt-azure-4o-mini",
|
48
|
+
show_consumption=True,
|
39
49
|
)
|
40
50
|
assert "Eudald" in generated.answer
|
51
|
+
assert generated.consumption is not None
|
41
52
|
|
42
53
|
|
43
54
|
def test_generative(testing_config):
|
44
55
|
np = NucliaPredict()
|
45
56
|
generated = np.generate(text="How much is 2 + 2?", model="chatgpt-azure-4o-mini")
|
46
57
|
assert "4" in generated.answer
|
58
|
+
assert generated.consumption is None
|
59
|
+
|
60
|
+
|
61
|
+
@pytest.mark.asyncio
|
62
|
+
async def test_generative_with_consumption(testing_config):
|
63
|
+
np = NucliaPredict()
|
64
|
+
generated = np.generate(
|
65
|
+
text="How much is 2 + 2?", model="chatgpt-azure-4o-mini", show_consumption=True
|
66
|
+
)
|
67
|
+
assert "4" in generated.answer
|
68
|
+
assert generated.consumption is not None
|
69
|
+
|
70
|
+
anp = AsyncNucliaPredict()
|
71
|
+
async_generated = await anp.generate(
|
72
|
+
text="How much is 2 + 2?", model="chatgpt-azure-4o-mini", show_consumption=True
|
73
|
+
)
|
74
|
+
assert "4" in async_generated.answer
|
75
|
+
assert async_generated.consumption is not None
|
47
76
|
|
48
77
|
|
49
78
|
@pytest.mark.asyncio
|
@@ -70,13 +99,18 @@ def test_stream_generative(testing_config):
|
|
70
99
|
@pytest.mark.asyncio
|
71
100
|
async def test_async_stream_generative(testing_config):
|
72
101
|
np = AsyncNucliaPredict()
|
102
|
+
consumption_found = False
|
103
|
+
found = False
|
73
104
|
async for stream in np.generate_stream(
|
74
|
-
text="How much is 2 + 2?", model="chatgpt-azure-4o-mini"
|
105
|
+
text="How much is 2 + 2?", model="chatgpt-azure-4o-mini", show_consumption=True
|
75
106
|
):
|
76
107
|
if isinstance(stream.chunk, TextGenerativeResponse) and stream.chunk.text:
|
77
108
|
if "4" in stream.chunk.text:
|
78
109
|
found = True
|
110
|
+
elif isinstance(stream.chunk, ConsumptionGenerative):
|
111
|
+
consumption_found = True
|
79
112
|
assert found
|
113
|
+
assert consumption_found
|
80
114
|
|
81
115
|
|
82
116
|
SCHEMA = {
|
@@ -148,6 +182,8 @@ def test_nua_remi(testing_config):
|
|
148
182
|
assert results.context_relevance[1] < 2
|
149
183
|
assert results.groundedness[1] < 2
|
150
184
|
|
185
|
+
assert results.consumption is None
|
186
|
+
|
151
187
|
|
152
188
|
@pytest.mark.asyncio
|
153
189
|
async def test_nua_async_remi(testing_config):
|
@@ -161,7 +197,8 @@ async def test_nua_async_remi(testing_config):
|
|
161
197
|
"Paris is the capital of France.",
|
162
198
|
"Berlin is the capital of Germany.",
|
163
199
|
],
|
164
|
-
)
|
200
|
+
),
|
201
|
+
show_consumption=True,
|
165
202
|
)
|
166
203
|
assert results.answer_relevance.score >= 4
|
167
204
|
|
@@ -170,3 +207,54 @@ async def test_nua_async_remi(testing_config):
|
|
170
207
|
|
171
208
|
assert results.context_relevance[1] < 2
|
172
209
|
assert results.groundedness[1] < 2
|
210
|
+
|
211
|
+
assert results.consumption is not None
|
212
|
+
|
213
|
+
|
214
|
+
def test_nua_rerank(testing_config):
|
215
|
+
np = NucliaPredict()
|
216
|
+
results = np.rerank(
|
217
|
+
RerankModel(
|
218
|
+
user_id="Nuclia PY CLI",
|
219
|
+
question="What is the capital of France?",
|
220
|
+
context={
|
221
|
+
"1": "Paris is the capital of France.",
|
222
|
+
"2": "Berlin is the capital of Germany.",
|
223
|
+
},
|
224
|
+
)
|
225
|
+
)
|
226
|
+
assert results.context_scores["1"] > results.context_scores["2"]
|
227
|
+
assert results.consumption is None
|
228
|
+
|
229
|
+
|
230
|
+
@pytest.mark.asyncio
|
231
|
+
async def test_nua_rerank_with_consumption(testing_config):
|
232
|
+
np = NucliaPredict()
|
233
|
+
results = np.rerank(
|
234
|
+
RerankModel(
|
235
|
+
user_id="Nuclia PY CLI",
|
236
|
+
question="What is the capital of France?",
|
237
|
+
context={
|
238
|
+
"1": "Paris is the capital of France.",
|
239
|
+
"2": "Berlin is the capital of Germany.",
|
240
|
+
},
|
241
|
+
),
|
242
|
+
show_consumption=True,
|
243
|
+
)
|
244
|
+
assert results.context_scores["1"] > results.context_scores["2"]
|
245
|
+
assert results.consumption is not None
|
246
|
+
|
247
|
+
anp = AsyncNucliaPredict()
|
248
|
+
async_results = await anp.rerank(
|
249
|
+
RerankModel(
|
250
|
+
user_id="Nuclia PY CLI",
|
251
|
+
question="What is the capital of France?",
|
252
|
+
context={
|
253
|
+
"1": "Paris is the capital of France.",
|
254
|
+
"2": "Berlin is the capital of Germany.",
|
255
|
+
},
|
256
|
+
),
|
257
|
+
show_consumption=True,
|
258
|
+
)
|
259
|
+
assert async_results.context_scores["1"] > async_results.context_scores["2"]
|
260
|
+
assert async_results.consumption is not None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nuclia
|
3
|
-
Version: 4.9.
|
3
|
+
Version: 4.9.4
|
4
4
|
Summary: Nuclia Python SDK
|
5
5
|
Author-email: Nuclia <info@nuclia.com>
|
6
6
|
License-Expression: MIT
|
@@ -24,9 +24,9 @@ Requires-Dist: requests
|
|
24
24
|
Requires-Dist: httpx
|
25
25
|
Requires-Dist: httpcore>=1.0.0
|
26
26
|
Requires-Dist: prompt_toolkit
|
27
|
-
Requires-Dist: nucliadb_sdk<7,>=6.
|
28
|
-
Requires-Dist: nucliadb_models<7,>=6.
|
29
|
-
Requires-Dist: nuclia-models>=0.
|
27
|
+
Requires-Dist: nucliadb_sdk<7,>=6.6.1
|
28
|
+
Requires-Dist: nucliadb_models<7,>=6.6.1
|
29
|
+
Requires-Dist: nuclia-models>=0.45.0
|
30
30
|
Requires-Dist: tqdm
|
31
31
|
Requires-Dist: aiofiles
|
32
32
|
Requires-Dist: backoff
|
@@ -9,11 +9,11 @@ nuclia/cli/run.py,sha256=B1hP0upSbSCqqT89WAwsd93ZxkAoF6ajVyLOdYmo8fU,1560
|
|
9
9
|
nuclia/cli/utils.py,sha256=iZ3P8juBdAGvaRUd2BGz7bpUXNDHdPrC5p876yyZ2Cs,1223
|
10
10
|
nuclia/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
11
|
nuclia/lib/conversations.py,sha256=M6qhL9NPEKroYF767S-Q2XWokRrjX02kpYTzRvZKwUE,149
|
12
|
-
nuclia/lib/kb.py,sha256=
|
12
|
+
nuclia/lib/kb.py,sha256=hbWg-0pX1OCt9ezUXYcOfyWHahgmZLUQe2nlSycHetU,31364
|
13
13
|
nuclia/lib/models.py,sha256=ekEQrVIFU3aFvt60yQh-zpWkGNORBMSc7c5Hd_VzPzI,1564
|
14
|
-
nuclia/lib/nua.py,sha256=
|
14
|
+
nuclia/lib/nua.py,sha256=qP6Gv9ck117kdqNuKVl_qHodrDE8CS8xdh_bdzeJMiQ,30631
|
15
15
|
nuclia/lib/nua_chat.py,sha256=ApL1Y1FWvAVUt-Y9a_8TUSJIhg8-UmBSy8TlDPn6tD8,3874
|
16
|
-
nuclia/lib/nua_responses.py,sha256=
|
16
|
+
nuclia/lib/nua_responses.py,sha256=KHAjoW3fu2QT7u4F4WfL4DQIM8lCE5W_14vuRtCmtZg,13970
|
17
17
|
nuclia/lib/utils.py,sha256=9l6DxBk-11WqUhXRn99cqeuVTUOJXj-1S6zckal7wOk,6312
|
18
18
|
nuclia/sdk/__init__.py,sha256=-nAw8i53XBdmbfTa1FJZ0FNRMNakimDVpD6W4OdES-c,1374
|
19
19
|
nuclia/sdk/accounts.py,sha256=7XQ3K9_jlSuk2Cez868FtazZ05xSGab6h3Mt1qMMwIE,647
|
@@ -22,17 +22,17 @@ nuclia/sdk/auth.py,sha256=o9CiWt3P_UHQW_L5Jq_9IOB-KpSCXFsVTouQcZp8BJM,25072
|
|
22
22
|
nuclia/sdk/backup.py,sha256=adbPcNEbHGZW698o028toXKfDkDrmk5QRIDSiN6SPys,6529
|
23
23
|
nuclia/sdk/export_import.py,sha256=y5cTOxhILwRPIvR2Ya12bk-ReGbeDzA3C9TPxgnOHD4,9756
|
24
24
|
nuclia/sdk/extract_strategy.py,sha256=NZBLLThdLyQYw8z1mT9iRhFjkE5sQP86-3QhsTiyV9o,2540
|
25
|
-
nuclia/sdk/kb.py,sha256=
|
25
|
+
nuclia/sdk/kb.py,sha256=rY1yVx_9S01twMXgrkpKSNpPChTupwYEw7EAIOwzLYA,27321
|
26
26
|
nuclia/sdk/kbs.py,sha256=nXEvg5ddZYdDS8Kie7TrN-s1meU9ecYLf9FlT5xr-ro,9131
|
27
27
|
nuclia/sdk/logger.py,sha256=UHB81eS6IGmLrsofKxLh8cmF2AsaTj_HXP0tGqMr_HM,57
|
28
28
|
nuclia/sdk/logs.py,sha256=3jfORpo8fzZiXFFSbGY0o3Bre1ZgJaKQCXgxP1keNHw,9614
|
29
29
|
nuclia/sdk/nua.py,sha256=6t0m0Sx-UhqNU2Hx9v6vTwy0m3a30K4T0KmP9G43MzY,293
|
30
30
|
nuclia/sdk/nucliadb.py,sha256=bOESIppPgY7IrNqrYY7T3ESoxwttbOSTm5zj1xUS1jI,1288
|
31
|
-
nuclia/sdk/predict.py,sha256=
|
31
|
+
nuclia/sdk/predict.py,sha256=ZQMtoeQBXaPuaJRxOmO23nnKkVKRpNCMi0JgXWSJ9lM,12836
|
32
32
|
nuclia/sdk/process.py,sha256=WuNnqaWprp-EABWDC_z7O2woesGIlYWnDUKozh7Ibr4,2241
|
33
33
|
nuclia/sdk/remi.py,sha256=BEb3O9R2jOFlOda4vjFucKKGO1c2eTkqYZdFlIy3Zmo,4357
|
34
34
|
nuclia/sdk/resource.py,sha256=0lSvD4e1FpN5iM9W295dOKLJ8hsXfIe8HKdo0HsVg20,13976
|
35
|
-
nuclia/sdk/search.py,sha256=
|
35
|
+
nuclia/sdk/search.py,sha256=tHpx0gwVwSepa3dn7AX2iWs7JO0pQkjJk7v8TEoL7Gg,27742
|
36
36
|
nuclia/sdk/task.py,sha256=UawH-7IneRIGVOiLdDQ2vDBwe5eI51UXRbLRRVeu3C4,6095
|
37
37
|
nuclia/sdk/upload.py,sha256=ZBzYROF3yP-77HcaR06OBsFjJAbTOCvF-nlxaqQZsT4,22720
|
38
38
|
nuclia/sdk/zones.py,sha256=1ARWrTsTuzj8zguanpX3OaIw-3Qq_ULS_g4GG2mHxOA,342
|
@@ -49,7 +49,7 @@ nuclia/tests/test_kb/test_labels.py,sha256=IUdTq4mzv0OrOkwBWWy4UwKGKyJybtoHrgvXr
|
|
49
49
|
nuclia/tests/test_kb/test_logs.py,sha256=Z9ELtiiU9NniITJzeWt92GCcERKYy9Nwc_fUVPboRU0,3121
|
50
50
|
nuclia/tests/test_kb/test_remi.py,sha256=OX5N-MHbgcwpLg6fBjrAK_KhqkMspJo_VKQHCBCayZ8,2080
|
51
51
|
nuclia/tests/test_kb/test_resource.py,sha256=05Xgmg5fwcPW2PZKnUSSjr6MPXp5w8XDgx8plfNcR68,1102
|
52
|
-
nuclia/tests/test_kb/test_search.py,sha256=
|
52
|
+
nuclia/tests/test_kb/test_search.py,sha256=8v3u-VcczBCTc-rHlWVM5mUtLJKNBZSM0V4v2I1uE3E,4751
|
53
53
|
nuclia/tests/test_kb/test_tasks.py,sha256=tfJl1js2o0_dKyXdOxiwdj929kbzMkfl5XjO8HVMInQ,3456
|
54
54
|
nuclia/tests/test_manage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
55
|
nuclia/tests/test_manage/test_account.py,sha256=u9NhRK8gJLS7BEY618aGoYoV2rgDLHZUeSsWWYkDhF8,289
|
@@ -57,15 +57,15 @@ nuclia/tests/test_manage/test_auth.py,sha256=I5ho9rKhrzCiP57cDVcs2zrXyy1uWlKxzfE
|
|
57
57
|
nuclia/tests/test_manage/test_kb.py,sha256=gqBMxmIuPUKC6kP2V_IapS9u72QR99V8CDQlJOa8sHU,1959
|
58
58
|
nuclia/tests/test_nua/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
59
59
|
nuclia/tests/test_nua/test_agent.py,sha256=iPA8lVw7CyONS-0fVG7rDzv8T-LnUlNPMNynTnP-2ic,334
|
60
|
-
nuclia/tests/test_nua/test_predict.py,sha256=
|
60
|
+
nuclia/tests/test_nua/test_predict.py,sha256=EKgpvHZHA4pf3ENE17j0B7CKewqHeJryR7D8JSTGJMo,8154
|
61
61
|
nuclia/tests/test_nucliadb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
62
62
|
nuclia/tests/test_nucliadb/test_crud.py,sha256=GuY76HRvt2DFaNgioKm5n0Aco1HnG7zzV_zKom5N8xc,1173
|
63
63
|
nuclia/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
64
64
|
nuclia/tests/unit/test_export_import.py,sha256=xo_wVbjUnNlVV65ZGH7LtZ38qy39EkJp2hjOuTHC1nU,980
|
65
65
|
nuclia/tests/unit/test_nua_responses.py,sha256=t_hIdVztTi27RWvpfTJUYcCL0lpKdZFegZIwLdaPNh8,319
|
66
|
-
nuclia-4.9.
|
67
|
-
nuclia-4.9.
|
68
|
-
nuclia-4.9.
|
69
|
-
nuclia-4.9.
|
70
|
-
nuclia-4.9.
|
71
|
-
nuclia-4.9.
|
66
|
+
nuclia-4.9.4.dist-info/licenses/LICENSE,sha256=Ops2LTti_HJtpmWcanuUTdTY3vKDR1myJ0gmGBKC0FA,1063
|
67
|
+
nuclia-4.9.4.dist-info/METADATA,sha256=2fk95GmG2Qa-GGAOPxWXWgA-gAGv-vEIHMRftKOsgA0,2341
|
68
|
+
nuclia-4.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
69
|
+
nuclia-4.9.4.dist-info/entry_points.txt,sha256=iZHOyXPNS54r3eQmdi5So20xO1gudI9K2oP4sQsCJRw,46
|
70
|
+
nuclia-4.9.4.dist-info/top_level.txt,sha256=cqn_EitXOoXOSUvZnd4q6QGrhm04pg8tLAZtem-Zfdo,7
|
71
|
+
nuclia-4.9.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|