aidial-client 0.10.0.dev1__tar.gz → 0.10.0.dev3__tar.gz

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.
Files changed (67) hide show
  1. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/PKG-INFO +46 -1
  2. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/README.md +45 -0
  3. aidial_client-0.10.0.dev3/aidial_client/resources/prompts.py +171 -0
  4. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/pyproject.toml +2 -1
  5. aidial_client-0.10.0.dev1/aidial_client/resources/prompts.py +0 -70
  6. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/LICENSE +0 -0
  7. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/__init__.py +0 -0
  8. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_auth.py +0 -0
  9. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_client.py +0 -0
  10. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_client_pool.py +0 -0
  11. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_compatibility/__init__.py +0 -0
  12. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_compatibility/openai.py +0 -0
  13. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_compatibility/pydantic.py +0 -0
  14. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_compatibility/pydantic_v1.py +0 -0
  15. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_constants.py +0 -0
  16. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_exception.py +0 -0
  17. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_http_client/__init__.py +0 -0
  18. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_http_client/_async.py +0 -0
  19. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_http_client/_base.py +0 -0
  20. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_http_client/_sync.py +0 -0
  21. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_internal_types/__init__.py +0 -0
  22. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_internal_types/_defaults.py +0 -0
  23. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_internal_types/_generic.py +0 -0
  24. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_internal_types/_http_request.py +0 -0
  25. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_internal_types/_model.py +0 -0
  26. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_log.py +0 -0
  27. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_utils/__init__.py +0 -0
  28. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_utils/_alias.py +0 -0
  29. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_utils/_dict.py +0 -0
  30. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_utils/_openai.py +0 -0
  31. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_utils/_response_processing.py +0 -0
  32. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/_utils/_type_guard.py +0 -0
  33. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/helpers/__init__.py +0 -0
  34. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/helpers/_url.py +0 -0
  35. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/helpers/storage_resource.py +0 -0
  36. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/py.typed +0 -0
  37. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/__init__.py +0 -0
  38. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/application.py +0 -0
  39. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/base.py +0 -0
  40. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/bucket.py +0 -0
  41. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/chat/__init__.py +0 -0
  42. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/chat/completions.py +0 -0
  43. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/deployments.py +0 -0
  44. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/files.py +0 -0
  45. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/metadata.py +0 -0
  46. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/model.py +0 -0
  47. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/resource_permissions.py +0 -0
  48. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/resources/toolset.py +0 -0
  49. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/__init__.py +0 -0
  50. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/application.py +0 -0
  51. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/bucket.py +0 -0
  52. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/__init__.py +0 -0
  53. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/addon.py +0 -0
  54. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/function.py +0 -0
  55. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/legacy/__init__.py +0 -0
  56. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/legacy/application_request.py +0 -0
  57. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/legacy/chat_completion.py +0 -0
  58. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/request.py +0 -0
  59. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/request_param.py +0 -0
  60. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/response.py +0 -0
  61. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/chat/tool.py +0 -0
  62. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/deployment.py +0 -0
  63. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/file.py +0 -0
  64. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/metadata.py +0 -0
  65. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/model.py +0 -0
  66. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/prompt.py +0 -0
  67. {aidial_client-0.10.0.dev1 → aidial_client-0.10.0.dev3}/aidial_client/types/toolset.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aidial-client
3
- Version: 0.10.0.dev1
3
+ Version: 0.10.0.dev3
4
4
  Summary: A Python client library for the AI DIAL API
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -613,6 +613,40 @@ FileMetadata(
613
613
 
614
614
  ### Prompts
615
615
 
616
+ #### Save Prompt
617
+
618
+ Use `save()` to create or update a prompt by its storage path:
619
+
620
+ ```python
621
+ from aidial_client.types.prompt import Prompt
622
+
623
+ prompt_url = "prompts/my-bucket/my-folder/my-prompt"
624
+ prompt_payload = Prompt(
625
+ id=prompt_url,
626
+ name="my-prompt",
627
+ folder_id="my-folder",
628
+ content="You are a helpful assistant.",
629
+ )
630
+
631
+ # Sync
632
+ saved_prompt = client.prompts.save(prompt_url, prompt=prompt_payload)
633
+ # Async
634
+ saved_prompt = await async_client.prompts.save(prompt_url, prompt=prompt_payload)
635
+ ```
636
+
637
+ As a result, you will receive a `PromptMetadata` object:
638
+
639
+ ```python
640
+ PromptMetadata(
641
+ name="my-prompt",
642
+ parent_path="my-folder",
643
+ bucket="my-bucket",
644
+ url="prompts/my-bucket/my-folder/my-prompt",
645
+ node_type="ITEM",
646
+ resource_type="PROMPT",
647
+ )
648
+ ```
649
+
616
650
  #### Get Prompt
617
651
 
618
652
  Use `get()` to fetch a single prompt by its storage path:
@@ -662,6 +696,17 @@ PromptMetadata(
662
696
  )
663
697
  ```
664
698
 
699
+ #### Delete Prompt
700
+
701
+ Use `delete()` to remove a prompt by its storage path:
702
+
703
+ ```python
704
+ # Sync
705
+ client.prompts.delete("prompts/my-bucket/my-folder/my-prompt")
706
+ # Async
707
+ await async_client.prompts.delete("prompts/my-bucket/my-folder/my-prompt")
708
+ ```
709
+
665
710
  ### Applications
666
711
 
667
712
  #### List Applications
@@ -591,6 +591,40 @@ FileMetadata(
591
591
 
592
592
  ### Prompts
593
593
 
594
+ #### Save Prompt
595
+
596
+ Use `save()` to create or update a prompt by its storage path:
597
+
598
+ ```python
599
+ from aidial_client.types.prompt import Prompt
600
+
601
+ prompt_url = "prompts/my-bucket/my-folder/my-prompt"
602
+ prompt_payload = Prompt(
603
+ id=prompt_url,
604
+ name="my-prompt",
605
+ folder_id="my-folder",
606
+ content="You are a helpful assistant.",
607
+ )
608
+
609
+ # Sync
610
+ saved_prompt = client.prompts.save(prompt_url, prompt=prompt_payload)
611
+ # Async
612
+ saved_prompt = await async_client.prompts.save(prompt_url, prompt=prompt_payload)
613
+ ```
614
+
615
+ As a result, you will receive a `PromptMetadata` object:
616
+
617
+ ```python
618
+ PromptMetadata(
619
+ name="my-prompt",
620
+ parent_path="my-folder",
621
+ bucket="my-bucket",
622
+ url="prompts/my-bucket/my-folder/my-prompt",
623
+ node_type="ITEM",
624
+ resource_type="PROMPT",
625
+ )
626
+ ```
627
+
594
628
  #### Get Prompt
595
629
 
596
630
  Use `get()` to fetch a single prompt by its storage path:
@@ -640,6 +674,17 @@ PromptMetadata(
640
674
  )
641
675
  ```
642
676
 
677
+ #### Delete Prompt
678
+
679
+ Use `delete()` to remove a prompt by its storage path:
680
+
681
+ ```python
682
+ # Sync
683
+ client.prompts.delete("prompts/my-bucket/my-folder/my-prompt")
684
+ # Async
685
+ await async_client.prompts.delete("prompts/my-bucket/my-folder/my-prompt")
686
+ ```
687
+
643
688
  ### Applications
644
689
 
645
690
  #### List Applications
@@ -0,0 +1,171 @@
1
+ from pathlib import PurePosixPath
2
+ from typing import Any, Dict, Literal, Optional, Union
3
+ from urllib.parse import urljoin
4
+
5
+ import httpx
6
+
7
+ from aidial_client._compatibility.pydantic import PYDANTIC_V2
8
+ from aidial_client._constants import API_PREFIX
9
+ from aidial_client._exception import (
10
+ DialException,
11
+ EtagMismatchError,
12
+ ResourceNotFoundError,
13
+ )
14
+ from aidial_client._internal_types._generic import NoneType
15
+ from aidial_client._internal_types._http_request import FinalRequestOptions
16
+ from aidial_client._utils._dict import remove_none
17
+ from aidial_client.helpers.storage_resource import DialStorageResourceMixin
18
+ from aidial_client.resources.base import AsyncResource, Resource
19
+ from aidial_client.resources.metadata import AsyncMetadata, Metadata
20
+ from aidial_client.types.metadata import PromptMetadata
21
+ from aidial_client.types.prompt import Prompt
22
+
23
+
24
+ def _prompts_error_processor(
25
+ http_status_error: httpx.HTTPStatusError,
26
+ ) -> Optional[DialException]:
27
+ if http_status_error.response.status_code == 412:
28
+ return EtagMismatchError(
29
+ message=http_status_error.response.text,
30
+ )
31
+ elif http_status_error.response.status_code == 404:
32
+ return ResourceNotFoundError(
33
+ message=http_status_error.response.text,
34
+ )
35
+ return None
36
+
37
+
38
+ def _prompt_to_json(prompt: Prompt) -> Dict[str, Any]:
39
+ if PYDANTIC_V2:
40
+ return prompt.model_dump(by_alias=True) # type: ignore
41
+ return prompt.dict(by_alias=True)
42
+
43
+
44
+ class Prompts(Resource, DialStorageResourceMixin):
45
+ metadata: Metadata
46
+ resource_type: str = "prompts"
47
+
48
+ def save(
49
+ self,
50
+ url: Union[str, PurePosixPath],
51
+ prompt: Prompt,
52
+ etag_if_match: Optional[str] = None,
53
+ etag_if_none_match: Optional[Literal["*"]] = None,
54
+ ) -> PromptMetadata:
55
+ return self.http_client.request(
56
+ cast_to=PromptMetadata,
57
+ options=FinalRequestOptions(
58
+ method="PUT",
59
+ url=urljoin(API_PREFIX, self.get_api_path(str(url))),
60
+ json_data=_prompt_to_json(prompt),
61
+ headers=remove_none(
62
+ {
63
+ "If-Match": etag_if_match,
64
+ "If-None-Match": etag_if_none_match,
65
+ }
66
+ ),
67
+ ),
68
+ on_http_error=_prompts_error_processor,
69
+ )
70
+
71
+ def get(self, url: Union[str, PurePosixPath]) -> Prompt:
72
+ """Fetch a single prompt by its storage path."""
73
+ return self.http_client.request(
74
+ cast_to=Prompt,
75
+ options=FinalRequestOptions(
76
+ method="GET",
77
+ url=urljoin(API_PREFIX, self.get_api_path(str(url))),
78
+ ),
79
+ on_http_error=_prompts_error_processor,
80
+ )
81
+
82
+ def delete(
83
+ self,
84
+ url: Union[str, PurePosixPath],
85
+ etag_if_match: Optional[str] = None,
86
+ ) -> None:
87
+ return self.http_client.request(
88
+ cast_to=NoneType,
89
+ options=FinalRequestOptions(
90
+ method="DELETE",
91
+ url=urljoin(API_PREFIX, self.get_api_path(str(url))),
92
+ headers=remove_none(
93
+ {
94
+ "If-Match": etag_if_match,
95
+ }
96
+ ),
97
+ ),
98
+ on_http_error=_prompts_error_processor,
99
+ )
100
+
101
+ def get_metadata(self, url: Union[str, PurePosixPath]) -> PromptMetadata:
102
+ return self.metadata.get(
103
+ resource="prompts",
104
+ relative_url=self.get_api_path(str(url)),
105
+ )
106
+
107
+
108
+ class AsyncPrompts(AsyncResource, DialStorageResourceMixin):
109
+ metadata: AsyncMetadata
110
+ resource_type: str = "prompts"
111
+
112
+ async def save(
113
+ self,
114
+ url: Union[str, PurePosixPath],
115
+ prompt: Prompt,
116
+ etag_if_match: Optional[str] = None,
117
+ etag_if_none_match: Optional[Literal["*"]] = None,
118
+ ) -> PromptMetadata:
119
+ return await self.http_client.request(
120
+ cast_to=PromptMetadata,
121
+ options=FinalRequestOptions(
122
+ method="PUT",
123
+ url=urljoin(API_PREFIX, self.get_api_path(str(url))),
124
+ json_data=_prompt_to_json(prompt),
125
+ headers=remove_none(
126
+ {
127
+ "If-Match": etag_if_match,
128
+ "If-None-Match": etag_if_none_match,
129
+ }
130
+ ),
131
+ ),
132
+ on_http_error=_prompts_error_processor,
133
+ )
134
+
135
+ async def get(self, url: Union[str, PurePosixPath]) -> Prompt:
136
+ """Fetch a single prompt by its storage path."""
137
+ return await self.http_client.request(
138
+ cast_to=Prompt,
139
+ options=FinalRequestOptions(
140
+ method="GET",
141
+ url=urljoin(API_PREFIX, self.get_api_path(str(url))),
142
+ ),
143
+ on_http_error=_prompts_error_processor,
144
+ )
145
+
146
+ async def delete(
147
+ self,
148
+ url: Union[str, PurePosixPath],
149
+ etag_if_match: Optional[str] = None,
150
+ ) -> None:
151
+ return await self.http_client.request(
152
+ cast_to=NoneType,
153
+ options=FinalRequestOptions(
154
+ method="DELETE",
155
+ url=urljoin(API_PREFIX, self.get_api_path(str(url))),
156
+ headers=remove_none(
157
+ {
158
+ "If-Match": etag_if_match,
159
+ }
160
+ ),
161
+ ),
162
+ on_http_error=_prompts_error_processor,
163
+ )
164
+
165
+ async def get_metadata(
166
+ self, url: Union[str, PurePosixPath]
167
+ ) -> PromptMetadata:
168
+ return await self.metadata.get(
169
+ resource="prompts",
170
+ relative_url=self.get_api_path(str(url)),
171
+ )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aidial-client"
3
- version = "0.10.0.dev1"
3
+ version = "0.10.0.dev3"
4
4
  description = "A Python client library for the AI DIAL API"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -63,6 +63,7 @@ exclude = [
63
63
 
64
64
  [tool.black]
65
65
  line-length = 80
66
+ target-version = ["py310"]
66
67
  exclude = '''
67
68
  /(
68
69
  \.git
@@ -1,70 +0,0 @@
1
- from pathlib import PurePosixPath
2
- from typing import Optional, Union
3
- from urllib.parse import urljoin
4
-
5
- import httpx
6
-
7
- from aidial_client._constants import API_PREFIX
8
- from aidial_client._exception import DialException, ResourceNotFoundError
9
- from aidial_client._internal_types._http_request import FinalRequestOptions
10
- from aidial_client.helpers.storage_resource import DialStorageResourceMixin
11
- from aidial_client.resources.base import AsyncResource, Resource
12
- from aidial_client.resources.metadata import AsyncMetadata, Metadata
13
- from aidial_client.types.metadata import PromptMetadata
14
- from aidial_client.types.prompt import Prompt
15
-
16
-
17
- def _prompts_error_processor(
18
- http_status_error: httpx.HTTPStatusError,
19
- ) -> Optional[DialException]:
20
- if http_status_error.response.status_code == 404:
21
- return ResourceNotFoundError(
22
- message=http_status_error.response.text,
23
- )
24
- return None
25
-
26
-
27
- class Prompts(Resource, DialStorageResourceMixin):
28
- metadata: Metadata
29
- resource_type: str = "prompts"
30
-
31
- def get(self, url: Union[str, PurePosixPath]) -> Prompt:
32
- """Fetch a single prompt by its storage path."""
33
- return self.http_client.request(
34
- cast_to=Prompt,
35
- options=FinalRequestOptions(
36
- method="GET",
37
- url=urljoin(API_PREFIX, self.get_api_path(str(url))),
38
- ),
39
- on_http_error=_prompts_error_processor,
40
- )
41
-
42
- def get_metadata(self, url: Union[str, PurePosixPath]) -> PromptMetadata:
43
- return self.metadata.get(
44
- resource="prompts",
45
- relative_url=self.get_api_path(str(url)),
46
- )
47
-
48
-
49
- class AsyncPrompts(AsyncResource, DialStorageResourceMixin):
50
- metadata: AsyncMetadata
51
- resource_type: str = "prompts"
52
-
53
- async def get(self, url: Union[str, PurePosixPath]) -> Prompt:
54
- """Fetch a single prompt by its storage path."""
55
- return await self.http_client.request(
56
- cast_to=Prompt,
57
- options=FinalRequestOptions(
58
- method="GET",
59
- url=urljoin(API_PREFIX, self.get_api_path(str(url))),
60
- ),
61
- on_http_error=_prompts_error_processor,
62
- )
63
-
64
- async def get_metadata(
65
- self, url: Union[str, PurePosixPath]
66
- ) -> PromptMetadata:
67
- return await self.metadata.get(
68
- resource="prompts",
69
- relative_url=self.get_api_path(str(url)),
70
- )