nuclia 4.8.7__py3-none-any.whl → 4.8.8__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/cli/run.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import logging
2
2
  import sys
3
- from pathlib import Path
3
+ from importlib.metadata import version
4
4
 
5
5
  import fire # type: ignore
6
6
  from nucliadb_sdk import exceptions
@@ -9,12 +9,13 @@ from nuclia.data import get_auth
9
9
  from nuclia.exceptions import NeedUserToken, UserTokenExpired
10
10
  from nuclia.lib.utils import serialize
11
11
  from nuclia.sdk.accounts import NucliaAccounts
12
+ from nuclia.sdk.backup import NucliaBackup
12
13
  from nuclia.sdk.kb import NucliaKB
13
14
  from nuclia.sdk.kbs import NucliaKBS
14
- from nuclia.sdk.backup import NucliaBackup
15
15
  from nuclia.sdk.logger import logger
16
16
  from nuclia.sdk.nua import NucliaNUA
17
17
  from nuclia.sdk.zones import NucliaZones
18
+
18
19
  from .utils import CustomFormatter
19
20
 
20
21
 
@@ -30,9 +31,7 @@ class NucliaCLI(object):
30
31
 
31
32
  def version(self):
32
33
  """Print the version of the CLI"""
33
- _dir = Path(__file__).resolve().parent.parent.parent
34
- VERSION = _dir.joinpath("VERSION").open().read().strip()
35
- return VERSION
34
+ return version("nuclia")
36
35
 
37
36
 
38
37
  def run():
nuclia/lib/nua.py CHANGED
@@ -56,6 +56,8 @@ import os
56
56
  from tqdm import tqdm
57
57
  import asyncio
58
58
  from nuclia.lib.utils import build_httpx_client, build_httpx_async_client
59
+ from pydantic import ValidationError
60
+
59
61
 
60
62
  if TYPE_CHECKING:
61
63
  from nucliadb_protos.writer_pb2 import BrokerMessage
@@ -147,8 +149,19 @@ class NuaClient:
147
149
  json=payload,
148
150
  timeout=timeout,
149
151
  ) as response:
150
- for json_body in response.iter_lines():
151
- yield GenerativeChunk.model_validate_json(json_body) # type: ignore
152
+ if response.headers.get("content-type") == "application/x-ndjson":
153
+ for json_body in response.iter_lines():
154
+ try:
155
+ yield GenerativeChunk.model_validate_json(json_body) # type: ignore
156
+ except ValidationError as e:
157
+ raise RuntimeError(f"Invalid stream chunk: {json_body}") from e
158
+
159
+ else:
160
+ # Read the full error body and raise an appropriate exception
161
+ error_content = response.content
162
+ raise RuntimeError(
163
+ f"Stream request failed with status {response.status_code}: {error_content.decode('utf-8')}"
164
+ )
152
165
 
153
166
  def add_config_predict(self, kbid: str, config: LearningConfigurationCreation):
154
167
  endpoint = f"{self.url}{CONFIG}/{kbid}"
@@ -456,8 +469,19 @@ class AsyncNuaClient:
456
469
  json=payload,
457
470
  timeout=timeout,
458
471
  ) as response:
459
- async for json_body in response.aiter_lines():
460
- yield GenerativeChunk.model_validate_json(json_body) # type: ignore
472
+ if response.headers.get("content-type") == "application/x-ndjson":
473
+ async for json_body in response.aiter_lines():
474
+ try:
475
+ yield GenerativeChunk.model_validate_json(json_body) # type: ignore
476
+ except ValidationError as e:
477
+ raise RuntimeError(f"Invalid stream chunk: {json_body}") from e
478
+
479
+ else:
480
+ # Read the full error body and raise an appropriate exception
481
+ error_content = await response.aread()
482
+ raise RuntimeError(
483
+ f"Stream request failed with status {response.status_code}: {error_content.decode('utf-8')}"
484
+ )
461
485
 
462
486
  async def add_config_predict(
463
487
  self, kbid: str, config: LearningConfigurationCreation
@@ -120,10 +120,10 @@ class ChatModel(BaseModel):
120
120
  raise ValueError("Can not setup markdown and JSON Schema at the same time")
121
121
  if self.citations is True and self.json_schema is not None:
122
122
  raise ValueError("Can not setup citations and JSON Schema at the same time")
123
- if self.citations is True and self.tools is not None:
123
+ if self.citations is True and len(self.tools) > 0:
124
124
  raise ValueError("Can not setup citations and Tools at the same time")
125
- if self.tools is True and self.json_schema is not None:
126
- raise ValueError("Can not setup tools and JSON Schema at the same time")
125
+ if len(self.tools) > 0 and self.json_schema is not None:
126
+ raise ValueError("Can not setup Tools and JSON Schema at the same time")
127
127
  return self
128
128
 
129
129
 
@@ -69,7 +69,7 @@ def test_search(testing_config):
69
69
  def test_catalog(testing_config):
70
70
  search = NucliaSearch()
71
71
  results = search.catalog()
72
- assert len(results.resources.keys()) == 2
72
+ assert len(results.resources.keys()) >= 2
73
73
 
74
74
 
75
75
  def test_search_object(testing_config):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nuclia
3
- Version: 4.8.7
3
+ Version: 4.8.8
4
4
  Summary: Nuclia Python SDK
5
5
  Author-email: Nuclia <info@nuclia.com>
6
6
  License-Expression: MIT
@@ -5,15 +5,15 @@ nuclia/decorators.py,sha256=GUhGDSrNtQ3DHpgsFArVJXpjykbDpi-Y8XRV5Vm4r6I,9879
5
5
  nuclia/exceptions.py,sha256=5nuWelyxjV7-oDJUnYRgIw_gnDnRUzJxvtXrAknV7So,748
6
6
  nuclia/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  nuclia/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- nuclia/cli/run.py,sha256=po6XRcWhtf-OcV2BkD4YJ0PmNTm6Hll4bs_rpotBEWo,1661
8
+ 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
12
  nuclia/lib/kb.py,sha256=98zpJ8Dp4rQYMNKm4nhpOms3PY-PFOd8acNgDmBud-o,31819
13
13
  nuclia/lib/models.py,sha256=lO3TZa4jTQ6C8ptGO1oX-5pxDgv8ocO13z7j5jXOC0Y,1554
14
- nuclia/lib/nua.py,sha256=Y8W0sJWnJqNLQ8y8fPbcJAV-6UtbE1FearHs68qwZQA,25888
14
+ nuclia/lib/nua.py,sha256=sUVFdCjvLigTqUUhILywdHpiC0qKCtKPABn5kUXfuxQ,27064
15
15
  nuclia/lib/nua_chat.py,sha256=ApL1Y1FWvAVUt-Y9a_8TUSJIhg8-UmBSy8TlDPn6tD8,3874
16
- nuclia/lib/nua_responses.py,sha256=zji-T-ipYRPo-e1U163Nn_saIiYJYNW3PfjTSL2fQXg,12726
16
+ nuclia/lib/nua_responses.py,sha256=9WRGpvvhA2ZOyOv9kzX1zI7C3ypM8ySqciVYCSibUjo,12724
17
17
  nuclia/lib/utils.py,sha256=XAVRRICPem-qOIEcssqDuv-vqD-9PICk6Iuj6DK5GKk,4808
18
18
  nuclia/sdk/__init__.py,sha256=-nAw8i53XBdmbfTa1FJZ0FNRMNakimDVpD6W4OdES-c,1374
19
19
  nuclia/sdk/accounts.py,sha256=7XQ3K9_jlSuk2Cez868FtazZ05xSGab6h3Mt1qMMwIE,647
@@ -47,7 +47,7 @@ nuclia/tests/test_kb/test_labels.py,sha256=IUdTq4mzv0OrOkwBWWy4UwKGKyJybtoHrgvXr
47
47
  nuclia/tests/test_kb/test_logs.py,sha256=Iw0v-R5QLlfHKxL8roPeOQKjTylgpYgot0wG4vsXQTE,2609
48
48
  nuclia/tests/test_kb/test_remi.py,sha256=OX5N-MHbgcwpLg6fBjrAK_KhqkMspJo_VKQHCBCayZ8,2080
49
49
  nuclia/tests/test_kb/test_resource.py,sha256=05Xgmg5fwcPW2PZKnUSSjr6MPXp5w8XDgx8plfNcR68,1102
50
- nuclia/tests/test_kb/test_search.py,sha256=GWI1_TqCma9PSdn2yvHaFm-IHBldmEnVGQflQ556EJE,4660
50
+ nuclia/tests/test_kb/test_search.py,sha256=bsQhfB6-NYFwY3gqkrVJJnru153UgZqEhV22ho4VeWM,4660
51
51
  nuclia/tests/test_kb/test_tasks.py,sha256=tfJl1js2o0_dKyXdOxiwdj929kbzMkfl5XjO8HVMInQ,3456
52
52
  nuclia/tests/test_manage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  nuclia/tests/test_manage/test_account.py,sha256=u9NhRK8gJLS7BEY618aGoYoV2rgDLHZUeSsWWYkDhF8,289
@@ -61,9 +61,9 @@ nuclia/tests/test_nucliadb/test_crud.py,sha256=GuY76HRvt2DFaNgioKm5n0Aco1HnG7zzV
61
61
  nuclia/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  nuclia/tests/unit/test_export_import.py,sha256=xo_wVbjUnNlVV65ZGH7LtZ38qy39EkJp2hjOuTHC1nU,980
63
63
  nuclia/tests/unit/test_nua_responses.py,sha256=t_hIdVztTi27RWvpfTJUYcCL0lpKdZFegZIwLdaPNh8,319
64
- nuclia-4.8.7.dist-info/licenses/LICENSE,sha256=Ops2LTti_HJtpmWcanuUTdTY3vKDR1myJ0gmGBKC0FA,1063
65
- nuclia-4.8.7.dist-info/METADATA,sha256=L_ftUZ5c8tQ5NA4gpDuNzKTkn8Id_XfSxjEk1pleolU,2337
66
- nuclia-4.8.7.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
67
- nuclia-4.8.7.dist-info/entry_points.txt,sha256=iZHOyXPNS54r3eQmdi5So20xO1gudI9K2oP4sQsCJRw,46
68
- nuclia-4.8.7.dist-info/top_level.txt,sha256=cqn_EitXOoXOSUvZnd4q6QGrhm04pg8tLAZtem-Zfdo,7
69
- nuclia-4.8.7.dist-info/RECORD,,
64
+ nuclia-4.8.8.dist-info/licenses/LICENSE,sha256=Ops2LTti_HJtpmWcanuUTdTY3vKDR1myJ0gmGBKC0FA,1063
65
+ nuclia-4.8.8.dist-info/METADATA,sha256=EI0YpmuSdlgl0IM4hDq9C0DJSW7mgmFoIzYz2KQh-Qo,2337
66
+ nuclia-4.8.8.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
67
+ nuclia-4.8.8.dist-info/entry_points.txt,sha256=iZHOyXPNS54r3eQmdi5So20xO1gudI9K2oP4sQsCJRw,46
68
+ nuclia-4.8.8.dist-info/top_level.txt,sha256=cqn_EitXOoXOSUvZnd4q6QGrhm04pg8tLAZtem-Zfdo,7
69
+ nuclia-4.8.8.dist-info/RECORD,,
File without changes