nc-py-api 0.15.0__py3-none-any.whl → 0.16.0__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.
nc_py_api/_session.py CHANGED
@@ -150,7 +150,7 @@ class NcSessionBase(ABC):
150
150
  self.init_adapter()
151
151
  self.init_adapter_dav()
152
152
  self.response_headers = Headers()
153
- self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/")
153
+ self._ocs_regexp = re.compile(r"/ocs/v[12]\.php/|/apps/groupfolders/")
154
154
 
155
155
  def init_adapter(self, restart=False) -> None:
156
156
  if getattr(self, "adapter", None) is None or restart:
@@ -289,6 +289,7 @@ class NcSessionBasic(NcSessionBase, ABC):
289
289
  str_url = str(request.url)
290
290
  if re.search(self._ocs_regexp, str_url) is not None: # this is OCS call
291
291
  request.url = request.url.copy_merge_params({"format": "json"})
292
+ request.headers["Accept"] = "application/json"
292
293
 
293
294
  def _response_event(self, response: Response) -> None:
294
295
  str_url = str(response.request.url)
@@ -412,6 +413,7 @@ class AsyncNcSessionBasic(NcSessionBase, ABC):
412
413
  str_url = str(request.url)
413
414
  if re.search(self._ocs_regexp, str_url) is not None: # this is OCS call
414
415
  request.url = request.url.copy_merge_params({"format": "json"})
416
+ request.headers["Accept"] = "application/json"
415
417
 
416
418
  async def _response_event(self, response: Response) -> None:
417
419
  str_url = str(response.request.url)
nc_py_api/_version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Version of nc_py_api."""
2
2
 
3
- __version__ = "0.15.0"
3
+ __version__ = "0.16.0"
nc_py_api/ex_app/misc.py CHANGED
@@ -54,4 +54,4 @@ def get_model_path(model_name: str) -> str:
54
54
 
55
55
  def get_computation_device() -> str:
56
56
  """Returns computation device(`ROCM` or `CUDA`) if it is defined in the environment variable."""
57
- return os.environ.get("COMPUTE_DEVICE", "")
57
+ return str(os.environ.get("COMPUTE_DEVICE", "")).upper()
@@ -3,35 +3,101 @@
3
3
  import contextlib
4
4
  import dataclasses
5
5
  import typing
6
+ from enum import IntEnum
7
+
8
+ from pydantic import RootModel
9
+ from pydantic.dataclasses import dataclass
6
10
 
7
11
  from ..._exceptions import NextcloudException, NextcloudExceptionNotFound
8
- from ..._misc import clear_from_params_empty, require_capabilities
12
+ from ..._misc import require_capabilities
9
13
  from ..._session import AsyncNcSessionApp, NcSessionApp
10
14
 
11
15
  _EP_SUFFIX: str = "ai_provider/task_processing"
12
16
 
13
17
 
14
- @dataclasses.dataclass
15
- class TaskProcessingProvider:
16
- """TaskProcessing provider description."""
18
+ class ShapeType(IntEnum):
19
+ """Enum for shape types."""
20
+
21
+ NUMBER = 0
22
+ TEXT = 1
23
+ IMAGE = 2
24
+ AUDIO = 3
25
+ VIDEO = 4
26
+ FILE = 5
27
+ ENUM = 6
28
+ LIST_OF_NUMBERS = 10
29
+ LIST_OF_TEXTS = 11
30
+ LIST_OF_IMAGES = 12
31
+ LIST_OF_AUDIOS = 13
32
+ LIST_OF_VIDEOS = 14
33
+ LIST_OF_FILES = 15
34
+
35
+
36
+ @dataclass
37
+ class ShapeEnumValue:
38
+ """Data object for input output shape enum slot value."""
39
+
40
+ name: str
41
+ """Name of the enum slot value which will be displayed in the UI"""
42
+ value: str
43
+ """Value of the enum slot value"""
44
+
17
45
 
18
- def __init__(self, raw_data: dict):
19
- self._raw_data = raw_data
46
+ @dataclass
47
+ class ShapeDescriptor:
48
+ """Data object for input output shape entries."""
20
49
 
21
- @property
22
- def name(self) -> str:
23
- """Unique ID for the provider."""
24
- return self._raw_data["name"]
50
+ name: str
51
+ """Name of the shape entry"""
52
+ description: str
53
+ """Description of the shape entry"""
54
+ shape_type: ShapeType
55
+ """Type of the shape entry"""
25
56
 
26
- @property
27
- def display_name(self) -> str:
28
- """Providers display name."""
29
- return self._raw_data["display_name"]
30
57
 
31
- @property
32
- def task_type(self) -> str:
33
- """The TaskType provided by this provider."""
34
- return self._raw_data["task_type"]
58
+ @dataclass
59
+ class TaskType:
60
+ """TaskType description for the provider."""
61
+
62
+ id: str
63
+ """The unique ID for the task type."""
64
+ name: str
65
+ """The localized name of the task type."""
66
+ description: str
67
+ """The localized description of the task type."""
68
+ input_shape: list[ShapeDescriptor]
69
+ """The input shape of the task."""
70
+ output_shape: list[ShapeDescriptor]
71
+ """The output shape of the task."""
72
+
73
+
74
+ @dataclass
75
+ class TaskProcessingProvider:
76
+
77
+ id: str
78
+ """Unique ID for the provider."""
79
+ name: str
80
+ """The localized name of this provider"""
81
+ task_type: str
82
+ """The TaskType provided by this provider."""
83
+ expected_runtime: int = dataclasses.field(default=0)
84
+ """Expected runtime of the task in seconds."""
85
+ optional_input_shape: list[ShapeDescriptor] = dataclasses.field(default_factory=list)
86
+ """Optional input shape of the task."""
87
+ optional_output_shape: list[ShapeDescriptor] = dataclasses.field(default_factory=list)
88
+ """Optional output shape of the task."""
89
+ input_shape_enum_values: dict[str, list[ShapeEnumValue]] = dataclasses.field(default_factory=dict)
90
+ """The option dict for each input shape ENUM slot."""
91
+ input_shape_defaults: dict[str, str | int | float] = dataclasses.field(default_factory=dict)
92
+ """The default values for input shape slots."""
93
+ optional_input_shape_enum_values: dict[str, list[ShapeEnumValue]] = dataclasses.field(default_factory=dict)
94
+ """The option list for each optional input shape ENUM slot."""
95
+ optional_input_shape_defaults: dict[str, str | int | float] = dataclasses.field(default_factory=dict)
96
+ """The default values for optional input shape slots."""
97
+ output_shape_enum_values: dict[str, list[ShapeEnumValue]] = dataclasses.field(default_factory=dict)
98
+ """The option list for each output shape ENUM slot."""
99
+ optional_output_shape_enum_values: dict[str, list[ShapeEnumValue]] = dataclasses.field(default_factory=dict)
100
+ """The option list for each optional output shape ENUM slot."""
35
101
 
36
102
  def __repr__(self):
37
103
  return f"<{self.__class__.__name__} name={self.name}, type={self.task_type}>"
@@ -44,17 +110,16 @@ class _TaskProcessingProviderAPI:
44
110
  self._session = session
45
111
 
46
112
  def register(
47
- self, name: str, display_name: str, task_type: str, custom_task_type: dict[str, typing.Any] | None = None
113
+ self,
114
+ provider: TaskProcessingProvider,
115
+ custom_task_type: TaskType | None = None,
48
116
  ) -> None:
49
117
  """Registers or edit the TaskProcessing provider."""
50
118
  require_capabilities("app_api", self._session.capabilities)
51
119
  params = {
52
- "name": name,
53
- "displayName": display_name,
54
- "taskType": task_type,
55
- "customTaskType": custom_task_type,
120
+ "provider": RootModel(provider).model_dump(),
121
+ **({"customTaskType": RootModel(custom_task_type).model_dump()} if custom_task_type else {}),
56
122
  }
57
- clear_from_params_empty(["customTaskType"], params)
58
123
  self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params)
59
124
 
60
125
  def unregister(self, name: str, not_fail=True) -> None:
@@ -123,17 +188,16 @@ class _AsyncTaskProcessingProviderAPI:
123
188
  self._session = session
124
189
 
125
190
  async def register(
126
- self, name: str, display_name: str, task_type: str, custom_task_type: dict[str, typing.Any] | None = None
191
+ self,
192
+ provider: TaskProcessingProvider,
193
+ custom_task_type: TaskType | None = None,
127
194
  ) -> None:
128
195
  """Registers or edit the TaskProcessing provider."""
129
196
  require_capabilities("app_api", await self._session.capabilities)
130
197
  params = {
131
- "name": name,
132
- "displayName": display_name,
133
- "taskType": task_type,
134
- "customTaskType": custom_task_type,
198
+ "provider": RootModel(provider).model_dump(),
199
+ **({"customTaskType": RootModel(custom_task_type).model_dump()} if custom_task_type else {}),
135
200
  }
136
- clear_from_params_empty(["customTaskType"], params)
137
201
  await self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params)
138
202
 
139
203
  async def unregister(self, name: str, not_fail=True) -> None:
nc_py_api/files/files.py CHANGED
@@ -174,7 +174,7 @@ class FilesAPI:
174
174
  path = path.lstrip("/")
175
175
  result = None
176
176
  for i in Path(path).parts:
177
- _path = os.path.join(_path, i)
177
+ _path = f"{_path}/{i}"
178
178
  if not exist_ok:
179
179
  result = self.mkdir(_path)
180
180
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nc-py-api
3
- Version: 0.15.0
3
+ Version: 0.16.0
4
4
  Summary: Nextcloud Python Framework
5
5
  Project-URL: Changelog, https://github.com/cloud-py-api/nc_py_api/blob/main/CHANGELOG.md
6
6
  Project-URL: Documentation, https://cloud-py-api.github.io/nc_py_api/
@@ -4,10 +4,10 @@ nc_py_api/_exceptions.py,sha256=7vbUECaLmD7RJBCU27t4fuP6NmQK6r4508u_gS4szhI,2298
4
4
  nc_py_api/_misc.py,sha256=dUzCP9VmyhtICTsn1aexlFAYUioBm40k6Zh-YE5WwCY,3333
5
5
  nc_py_api/_preferences.py,sha256=OtovFZuGHnHYKjdDjSnUappO795tW8Oxj7qVaejHWpQ,2479
6
6
  nc_py_api/_preferences_ex.py,sha256=tThj6U0ZZMaBZ-jUkjrbaI0xDnafWsBowQKsC6gjOQs,7179
7
- nc_py_api/_session.py,sha256=dCXMbxzjHqbqYFhH_qqle5QGPJfuaydqljjmGa0pBnY,20042
7
+ nc_py_api/_session.py,sha256=iFv8_xkPA_erhUNvSvjUJvhKL3yCnq2xHNkL8PHLbrA,20180
8
8
  nc_py_api/_talk_api.py,sha256=0Uo7OduYniuuX3UQPb468RyGJJ-PWBCgJ5HoPuz5Qa0,51068
9
9
  nc_py_api/_theming.py,sha256=hTr3nuOemSuRFZaPy9iXNmBM7rDgQHECH43tHMWGqEY,1870
10
- nc_py_api/_version.py,sha256=WuFI1D5uSabdFVmTzxrwUg9lblNKAP09gCFGlHLDAKk,52
10
+ nc_py_api/_version.py,sha256=vw6VrjuPRin5Pm7VDRrwjw0_FOOwigsu-NyVCk5I4Ys,52
11
11
  nc_py_api/activity.py,sha256=t9VDSnnaXRNOvALqOSGCeXSQZ-426pCOMSfQ96JHys4,9574
12
12
  nc_py_api/apps.py,sha256=tc3Qg-V7au0inUQGOv1Mj7Td5sEGiHOjCjRq1mN41x0,9763
13
13
  nc_py_api/calendar.py,sha256=-T6CJ8cRbJZTLtxSEDWuuYpD29DMJGCTfLONmtxZV9w,1445
@@ -27,14 +27,14 @@ nc_py_api/ex_app/__init__.py,sha256=YqzRDfFGe-2BMnkIpPI1ws80uF20FiuvoDaN_KL4xZw,
27
27
  nc_py_api/ex_app/defs.py,sha256=FaQInH3jLugKxDUqpwrXdkMT-lBxmoqWmXJXc11fa6A,727
28
28
  nc_py_api/ex_app/events_listener.py,sha256=pgQ4hSQV39NuP9F9IDWxo0Qle6oG15-Ol2FlItnIBGY,4682
29
29
  nc_py_api/ex_app/integration_fastapi.py,sha256=xh-gSxYH6_FE8GluajlrVAHZg1HZeaAxJ-jIUP6uot4,11022
30
- nc_py_api/ex_app/misc.py,sha256=wA6KrcB05SQGwVAo7dgBxXAVm_2r9bgDf6SqioyOJPc,2286
30
+ nc_py_api/ex_app/misc.py,sha256=76EP7Ui3yEMZE3AP3-1Cc_buGDLSAurn8PDig6RN6QQ,2299
31
31
  nc_py_api/ex_app/occ_commands.py,sha256=hb2BJuvFKIigvLycSCyAe9v6hedq4Gfu2junQZTaK_M,5219
32
32
  nc_py_api/ex_app/persist_transformers_cache.py,sha256=ZoEBb1RnNaQrtxK_CjSZ8LZ36Oakz2Xciau_ZpNp8Ic,213
33
33
  nc_py_api/ex_app/uvicorn_fastapi.py,sha256=WLtNmWXMBKN6CMip2uhKcgy4mC2Ch9AmNfwRScBUsP0,752
34
34
  nc_py_api/ex_app/providers/__init__.py,sha256=jmUBdbAgzUCdYyHl8V5UCNYJI-FFpxPQQ4iEAoURKQs,43
35
35
  nc_py_api/ex_app/providers/providers.py,sha256=_1zWAgg9ol2u82Huf-yxFfxviGwtEeLIxDWTTYY2jJQ,1955
36
36
  nc_py_api/ex_app/providers/speech_to_text.py,sha256=JFD1ksdhXjpr5UFm5npqCxepqB5x-kdHG9CpPoGofx0,4959
37
- nc_py_api/ex_app/providers/task_processing.py,sha256=zZHjOwTwNIRV5e25jm4Yy4eR0weGwvaU-ooY5YNYsfg,7656
37
+ nc_py_api/ex_app/providers/task_processing.py,sha256=h-H3fGK30c9M-VUpk7I9WGc730t9OCoSZ6vf7lB7xdA,9874
38
38
  nc_py_api/ex_app/providers/text_processing.py,sha256=VUZMZ2fof-c6JD7mTKHTZBWbDMOqxDllMCNQFOlHXXk,5265
39
39
  nc_py_api/ex_app/providers/translations.py,sha256=io8UgVhdQXFmP7KnrJQx5Vtl8Dz0Z0EVZ0bt3hV7C7A,6112
40
40
  nc_py_api/ex_app/ui/__init__.py,sha256=jUMU7_miFF-Q8BQNT90KZYQiLy_a3OvEyK6y8eRMKRk,38
@@ -45,11 +45,11 @@ nc_py_api/ex_app/ui/top_menu.py,sha256=oCgGtIoMYbp-5iN5aXEbT7Q88HtccR7hg6IBFgbby
45
45
  nc_py_api/ex_app/ui/ui.py,sha256=OqFHKn6oIZli8T1wnv6YtQ4glNfeNb90WwGCvtWI1Z4,1632
46
46
  nc_py_api/files/__init__.py,sha256=p1RecBNkZCuu8_mf-y_mkbotj9fGsCDSFRl7hGkI1CA,17003
47
47
  nc_py_api/files/_files.py,sha256=_s_f8xbzQPEH2F2LNwomI9CxscYHryus1pMZ_vW00C4,13666
48
- nc_py_api/files/files.py,sha256=Yj388MJp_EdM-2neM9EnALaLnSR6zMJbYxXzHpHmOmI,24577
48
+ nc_py_api/files/files.py,sha256=DuAMkfmRGtNJntMIo-yEYhZ-a3KhhhnwKATcGqpxJL4,24569
49
49
  nc_py_api/files/files_async.py,sha256=rEIT6P1Pb7TeTub1dAB5IKpR4LDqHWc5LclAEzpiHEQ,25410
50
50
  nc_py_api/files/sharing.py,sha256=VRZCl-TYK6dbu9rUHPs3_jcVozu1EO8bLGZwoRpiLsU,14439
51
- nc_py_api-0.15.0.dist-info/METADATA,sha256=oj0llVaMYlQRj39-eSjdhXsbFIOs0ggj3NmWOvDuz1A,9466
52
- nc_py_api-0.15.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
53
- nc_py_api-0.15.0.dist-info/licenses/AUTHORS,sha256=Y1omFHyI8ned9k4jJXs2ATgmgi1GmQ7EZ6S1gxqnX2k,572
54
- nc_py_api-0.15.0.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
55
- nc_py_api-0.15.0.dist-info/RECORD,,
51
+ nc_py_api-0.16.0.dist-info/METADATA,sha256=tQ-TcI5upBWSmV436b2NxQ873SmfcwtmQT_qqrTrs3Y,9466
52
+ nc_py_api-0.16.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
53
+ nc_py_api-0.16.0.dist-info/licenses/AUTHORS,sha256=Y1omFHyI8ned9k4jJXs2ATgmgi1GmQ7EZ6S1gxqnX2k,572
54
+ nc_py_api-0.16.0.dist-info/licenses/LICENSE.txt,sha256=OLEMh401fAumGHfRSna365MLIfnjdTcdOHZ6QOzMjkg,1551
55
+ nc_py_api-0.16.0.dist-info/RECORD,,