nuclia 4.9.1__py3-none-any.whl → 4.9.2__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 +65 -0
- nuclia/sdk/extract_strategy.py +98 -0
- nuclia/sdk/kb.py +6 -0
- nuclia/tests/test_kb/test_extract_strategies.py +16 -0
- {nuclia-4.9.1.dist-info → nuclia-4.9.2.dist-info}/METADATA +1 -1
- {nuclia-4.9.1.dist-info → nuclia-4.9.2.dist-info}/RECORD +10 -8
- {nuclia-4.9.1.dist-info → nuclia-4.9.2.dist-info}/WHEEL +0 -0
- {nuclia-4.9.1.dist-info → nuclia-4.9.2.dist-info}/entry_points.txt +0 -0
- {nuclia-4.9.1.dist-info → nuclia-4.9.2.dist-info}/licenses/LICENSE +0 -0
- {nuclia-4.9.1.dist-info → nuclia-4.9.2.dist-info}/top_level.txt +0 -0
nuclia/lib/kb.py
CHANGED
@@ -23,6 +23,7 @@ from nuclia_models.events.activity_logs import ( # type: ignore
|
|
23
23
|
)
|
24
24
|
from nuclia_models.events.remi import RemiQuery
|
25
25
|
from nuclia_models.worker.tasks import TaskStartKB
|
26
|
+
from nuclia_models.config.proto import ExtractConfig
|
26
27
|
from nuclia.exceptions import RateLimitError
|
27
28
|
from nuclia.lib.utils import handle_http_sync_errors, handle_http_async_errors
|
28
29
|
from datetime import datetime
|
@@ -58,6 +59,8 @@ STOP_TASK = "/task/{task_id}/stop"
|
|
58
59
|
DELETE_TASK = "/task/{task_id}"
|
59
60
|
GET_TASK = "/task/{task_id}/inspect"
|
60
61
|
RESTART_TASK = "/task/{task_id}/restart"
|
62
|
+
EXTRACT_STRATEGIES = "/extract_strategies"
|
63
|
+
DELETE_EXTRACT_STRATEGY = "/extract_strategies/strategy/{id}"
|
61
64
|
|
62
65
|
DOWNLOAD_FORMAT_HEADERS = {
|
63
66
|
DownloadFormat.CSV: "text/csv",
|
@@ -487,6 +490,37 @@ class NucliaDBClient(BaseNucliaDBClient):
|
|
487
490
|
handle_http_sync_errors(response)
|
488
491
|
return response
|
489
492
|
|
493
|
+
def list_extract_strategies(self) -> httpx.Response:
|
494
|
+
if self.reader_session is None:
|
495
|
+
raise Exception("KB not configured")
|
496
|
+
|
497
|
+
response: httpx.Response = self.reader_session.get(
|
498
|
+
f"{self.url}{EXTRACT_STRATEGIES}"
|
499
|
+
)
|
500
|
+
handle_http_sync_errors(response)
|
501
|
+
return response
|
502
|
+
|
503
|
+
def add_extract_strategy(self, config: ExtractConfig) -> httpx.Response:
|
504
|
+
if self.writer_session is None:
|
505
|
+
raise Exception("KB not configured")
|
506
|
+
|
507
|
+
response: httpx.Response = self.writer_session.post(
|
508
|
+
f"{self.url}{EXTRACT_STRATEGIES}",
|
509
|
+
json=config.model_dump(mode="json", exclude_unset=True),
|
510
|
+
)
|
511
|
+
handle_http_sync_errors(response)
|
512
|
+
return response
|
513
|
+
|
514
|
+
def delete_extract_strategy(self, strategy_id: str) -> httpx.Response:
|
515
|
+
if self.writer_session is None:
|
516
|
+
raise Exception("KB not configured")
|
517
|
+
|
518
|
+
response: httpx.Response = self.writer_session.delete(
|
519
|
+
f"{self.url}{DELETE_EXTRACT_STRATEGY.format(id=strategy_id)}",
|
520
|
+
)
|
521
|
+
handle_http_sync_errors(response)
|
522
|
+
return response
|
523
|
+
|
490
524
|
|
491
525
|
class AsyncNucliaDBClient(BaseNucliaDBClient):
|
492
526
|
reader_session: Optional[httpx.AsyncClient] = None
|
@@ -813,3 +847,34 @@ class AsyncNucliaDBClient(BaseNucliaDBClient):
|
|
813
847
|
)
|
814
848
|
await handle_http_async_errors(response)
|
815
849
|
return response
|
850
|
+
|
851
|
+
async def list_extract_strategies(self) -> httpx.Response:
|
852
|
+
if self.reader_session is None:
|
853
|
+
raise Exception("KB not configured")
|
854
|
+
|
855
|
+
response: httpx.Response = await self.reader_session.get(
|
856
|
+
f"{self.url}{EXTRACT_STRATEGIES}"
|
857
|
+
)
|
858
|
+
await handle_http_async_errors(response)
|
859
|
+
return response
|
860
|
+
|
861
|
+
async def add_extract_strategy(self, config: ExtractConfig) -> httpx.Response:
|
862
|
+
if self.writer_session is None:
|
863
|
+
raise Exception("KB not configured")
|
864
|
+
|
865
|
+
response: httpx.Response = await self.writer_session.post(
|
866
|
+
f"{self.url}{EXTRACT_STRATEGIES}",
|
867
|
+
json=config.model_dump(mode="json", exclude_unset=True),
|
868
|
+
)
|
869
|
+
await handle_http_async_errors(response)
|
870
|
+
return response
|
871
|
+
|
872
|
+
async def delete_extract_strategy(self, strategy_id: str) -> httpx.Response:
|
873
|
+
if self.writer_session is None:
|
874
|
+
raise Exception("KB not configured")
|
875
|
+
|
876
|
+
response: httpx.Response = await self.writer_session.delete(
|
877
|
+
f"{self.url}{DELETE_EXTRACT_STRATEGY.format(id=strategy_id)}",
|
878
|
+
)
|
879
|
+
await handle_http_async_errors(response)
|
880
|
+
return response
|
@@ -0,0 +1,98 @@
|
|
1
|
+
from nuclia.data import get_auth, get_async_auth
|
2
|
+
from nuclia.decorators import kb, pretty
|
3
|
+
from nuclia.lib.kb import NucliaDBClient, AsyncNucliaDBClient
|
4
|
+
from nuclia.sdk.auth import NucliaAuth, AsyncNucliaAuth
|
5
|
+
from nuclia_models.config.proto import ExtractConfig
|
6
|
+
from typing import Dict
|
7
|
+
|
8
|
+
|
9
|
+
class NucliaExtractStrategy:
|
10
|
+
@property
|
11
|
+
def _auth(self) -> NucliaAuth:
|
12
|
+
auth = get_auth()
|
13
|
+
return auth
|
14
|
+
|
15
|
+
@kb
|
16
|
+
@pretty
|
17
|
+
def list(self, *args, **kwargs) -> Dict[str, ExtractConfig]:
|
18
|
+
"""
|
19
|
+
List extract strategies
|
20
|
+
"""
|
21
|
+
ndb: NucliaDBClient = kwargs["ndb"]
|
22
|
+
response = ndb.list_extract_strategies()
|
23
|
+
return response.json()
|
24
|
+
|
25
|
+
@kb
|
26
|
+
def add(
|
27
|
+
self,
|
28
|
+
*args,
|
29
|
+
config: ExtractConfig,
|
30
|
+
**kwargs,
|
31
|
+
) -> str:
|
32
|
+
"""
|
33
|
+
Add extract strategy
|
34
|
+
|
35
|
+
:param config: strategy configuration
|
36
|
+
"""
|
37
|
+
if isinstance(config, dict):
|
38
|
+
config = ExtractConfig.model_validate(config)
|
39
|
+
|
40
|
+
ndb: NucliaDBClient = kwargs["ndb"]
|
41
|
+
response = ndb.add_extract_strategy(config=config)
|
42
|
+
return response.json()
|
43
|
+
|
44
|
+
@kb
|
45
|
+
def delete(self, *args, id: str, **kwargs):
|
46
|
+
"""
|
47
|
+
Delete extract strategy
|
48
|
+
|
49
|
+
:param id: ID of the strategy to delete
|
50
|
+
"""
|
51
|
+
ndb: NucliaDBClient = kwargs["ndb"]
|
52
|
+
ndb.delete_extract_strategy(strategy_id=id)
|
53
|
+
|
54
|
+
|
55
|
+
class AsyncNucliaExtractStrategy:
|
56
|
+
@property
|
57
|
+
def _auth(self) -> AsyncNucliaAuth:
|
58
|
+
auth = get_async_auth()
|
59
|
+
return auth
|
60
|
+
|
61
|
+
@kb
|
62
|
+
@pretty
|
63
|
+
async def list(self, *args, **kwargs) -> Dict[str, ExtractConfig]:
|
64
|
+
"""
|
65
|
+
List extract strategies
|
66
|
+
"""
|
67
|
+
ndb: AsyncNucliaDBClient = kwargs["ndb"]
|
68
|
+
response = await ndb.list_extract_strategies()
|
69
|
+
return response.json()
|
70
|
+
|
71
|
+
@kb
|
72
|
+
async def add(
|
73
|
+
self,
|
74
|
+
*args,
|
75
|
+
config: ExtractConfig,
|
76
|
+
**kwargs,
|
77
|
+
) -> str:
|
78
|
+
"""
|
79
|
+
Add extract strategy
|
80
|
+
|
81
|
+
:param config: strategy configuration
|
82
|
+
"""
|
83
|
+
if isinstance(config, dict):
|
84
|
+
config = ExtractConfig.model_validate(config)
|
85
|
+
|
86
|
+
ndb: AsyncNucliaDBClient = kwargs["ndb"]
|
87
|
+
response = await ndb.add_extract_strategy(config=config)
|
88
|
+
return response.json()
|
89
|
+
|
90
|
+
@kb
|
91
|
+
async def delete(self, *args, id: str, **kwargs):
|
92
|
+
"""
|
93
|
+
Delete extract strategy
|
94
|
+
|
95
|
+
:param id: ID of the strategy to delete
|
96
|
+
"""
|
97
|
+
ndb: AsyncNucliaDBClient = kwargs["ndb"]
|
98
|
+
await ndb.delete_extract_strategy(strategy_id=id)
|
nuclia/sdk/kb.py
CHANGED
@@ -30,6 +30,10 @@ from nuclia.sdk.remi import NucliaRemi, AsyncNucliaRemi
|
|
30
30
|
from nuclia.sdk.resource import AsyncNucliaResource, NucliaResource
|
31
31
|
from nuclia.sdk.search import AsyncNucliaSearch, NucliaSearch
|
32
32
|
from nuclia.sdk.task import NucliaTask, AsyncNucliaTask
|
33
|
+
from nuclia.sdk.extract_strategy import (
|
34
|
+
NucliaExtractStrategy,
|
35
|
+
AsyncNucliaExtractStrategy,
|
36
|
+
)
|
33
37
|
from nuclia.sdk.upload import AsyncNucliaUpload, NucliaUpload
|
34
38
|
|
35
39
|
|
@@ -48,6 +52,7 @@ class NucliaKB:
|
|
48
52
|
self.logs = NucliaLogs()
|
49
53
|
self.task = NucliaTask()
|
50
54
|
self.remi = NucliaRemi()
|
55
|
+
self.extract_strategies = NucliaExtractStrategy()
|
51
56
|
|
52
57
|
@kb
|
53
58
|
def list(
|
@@ -459,6 +464,7 @@ class AsyncNucliaKB:
|
|
459
464
|
self.logs = AsyncNucliaLogs()
|
460
465
|
self.task = AsyncNucliaTask()
|
461
466
|
self.remi = AsyncNucliaRemi()
|
467
|
+
self.extract_strategies = AsyncNucliaExtractStrategy()
|
462
468
|
|
463
469
|
@kb
|
464
470
|
async def list(self, **kwargs) -> ResourceList:
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from nuclia.sdk.kb import NucliaKB
|
2
|
+
|
3
|
+
|
4
|
+
def test_extract_strategies(testing_config):
|
5
|
+
nkb = NucliaKB()
|
6
|
+
# preventive clean up
|
7
|
+
for id in nkb.extract_strategies.list().keys():
|
8
|
+
nkb.extract_strategies.delete(id=id)
|
9
|
+
|
10
|
+
# tests
|
11
|
+
nkb.extract_strategies.add(config={"name": "strategy1", "vllm_config": {}})
|
12
|
+
all = nkb.extract_strategies.list()
|
13
|
+
assert len(all.keys()) == 1
|
14
|
+
nkb.extract_strategies.delete(id=list(all.keys())[0])
|
15
|
+
all = nkb.extract_strategies.list()
|
16
|
+
assert len(all.keys()) == 0
|
@@ -9,7 +9,7 @@ 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=vSLfmV6HqPvWJwPVw4iIzkDnm0M96_ImTH3QMZdkd_I,30985
|
13
13
|
nuclia/lib/models.py,sha256=ekEQrVIFU3aFvt60yQh-zpWkGNORBMSc7c5Hd_VzPzI,1564
|
14
14
|
nuclia/lib/nua.py,sha256=sUVFdCjvLigTqUUhILywdHpiC0qKCtKPABn5kUXfuxQ,27064
|
15
15
|
nuclia/lib/nua_chat.py,sha256=ApL1Y1FWvAVUt-Y9a_8TUSJIhg8-UmBSy8TlDPn6tD8,3874
|
@@ -21,7 +21,8 @@ nuclia/sdk/agent.py,sha256=ot_oA4yi7TkXahPnhcRIxztq9Dtskc85-A57WN1BNGg,1961
|
|
21
21
|
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
|
-
nuclia/sdk/
|
24
|
+
nuclia/sdk/extract_strategy.py,sha256=NZBLLThdLyQYw8z1mT9iRhFjkE5sQP86-3QhsTiyV9o,2540
|
25
|
+
nuclia/sdk/kb.py,sha256=2-H9FOvPgsG-ZYNUA8D4FYAJhX3K8m2VwbwSQy1JV7c,27044
|
25
26
|
nuclia/sdk/kbs.py,sha256=nXEvg5ddZYdDS8Kie7TrN-s1meU9ecYLf9FlT5xr-ro,9131
|
26
27
|
nuclia/sdk/logger.py,sha256=UHB81eS6IGmLrsofKxLh8cmF2AsaTj_HXP0tGqMr_HM,57
|
27
28
|
nuclia/sdk/logs.py,sha256=3jfORpo8fzZiXFFSbGY0o3Bre1ZgJaKQCXgxP1keNHw,9614
|
@@ -42,6 +43,7 @@ nuclia/tests/assets/conversation.json,sha256=jLmVngHEW8QdAzSMa-MYgbJgYxOO8tHq6Ia
|
|
42
43
|
nuclia/tests/test_kb/test_backup.py,sha256=67fAw1C_NB363G-wuI9LnSH6nG_YrYs-uBcFyBx6Peg,2932
|
43
44
|
nuclia/tests/test_kb/test_conversation.py,sha256=plsWY_gEhK3P4CsIO9jkBmimZk3UDGeMYPu7YVFeuIQ,727
|
44
45
|
nuclia/tests/test_kb/test_export_import.py,sha256=lQEww2jFNHZYcudFJqcHhoWAPrmtvvnPvcFqrijxLbo,1019
|
46
|
+
nuclia/tests/test_kb/test_extract_strategies.py,sha256=aKNzE98H1sE4eFqh8XiwvzDT8-7SnMs0v3NTeubZ-XY,521
|
45
47
|
nuclia/tests/test_kb/test_graph.py,sha256=ecAB-lWqm3_796HUuF-fSpGzlhsXV9NGZnAjvxXANps,2540
|
46
48
|
nuclia/tests/test_kb/test_labels.py,sha256=IUdTq4mzv0OrOkwBWWy4UwKGKyJybtoHrgvXr676vyY,961
|
47
49
|
nuclia/tests/test_kb/test_logs.py,sha256=Z9ELtiiU9NniITJzeWt92GCcERKYy9Nwc_fUVPboRU0,3121
|
@@ -61,9 +63,9 @@ nuclia/tests/test_nucliadb/test_crud.py,sha256=GuY76HRvt2DFaNgioKm5n0Aco1HnG7zzV
|
|
61
63
|
nuclia/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
62
64
|
nuclia/tests/unit/test_export_import.py,sha256=xo_wVbjUnNlVV65ZGH7LtZ38qy39EkJp2hjOuTHC1nU,980
|
63
65
|
nuclia/tests/unit/test_nua_responses.py,sha256=t_hIdVztTi27RWvpfTJUYcCL0lpKdZFegZIwLdaPNh8,319
|
64
|
-
nuclia-4.9.
|
65
|
-
nuclia-4.9.
|
66
|
-
nuclia-4.9.
|
67
|
-
nuclia-4.9.
|
68
|
-
nuclia-4.9.
|
69
|
-
nuclia-4.9.
|
66
|
+
nuclia-4.9.2.dist-info/licenses/LICENSE,sha256=Ops2LTti_HJtpmWcanuUTdTY3vKDR1myJ0gmGBKC0FA,1063
|
67
|
+
nuclia-4.9.2.dist-info/METADATA,sha256=QqBc1WyVh98_k_OuLTJBoD5_Ig5VZuQ5ewQZIriu9p0,2337
|
68
|
+
nuclia-4.9.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
69
|
+
nuclia-4.9.2.dist-info/entry_points.txt,sha256=iZHOyXPNS54r3eQmdi5So20xO1gudI9K2oP4sQsCJRw,46
|
70
|
+
nuclia-4.9.2.dist-info/top_level.txt,sha256=cqn_EitXOoXOSUvZnd4q6QGrhm04pg8tLAZtem-Zfdo,7
|
71
|
+
nuclia-4.9.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|