pygeai 0.6.0b7__py3-none-any.whl → 0.6.0b11__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.
- pygeai/_docs/source/conf.py +78 -6
- pygeai/_docs/source/content/api_reference/embeddings.rst +31 -1
- pygeai/_docs/source/content/api_reference/evaluation.rst +590 -0
- pygeai/_docs/source/content/api_reference/feedback.rst +237 -0
- pygeai/_docs/source/content/api_reference/files.rst +592 -0
- pygeai/_docs/source/content/api_reference/gam.rst +401 -0
- pygeai/_docs/source/content/api_reference/proxy.rst +318 -0
- pygeai/_docs/source/content/api_reference/secrets.rst +495 -0
- pygeai/_docs/source/content/api_reference/usage_limits.rst +390 -0
- pygeai/_docs/source/content/api_reference.rst +7 -0
- pygeai/_docs/source/content/debugger.rst +376 -83
- pygeai/_docs/source/content/migration.rst +528 -0
- pygeai/_docs/source/content/modules.rst +1 -1
- pygeai/_docs/source/pygeai.cli.rst +8 -0
- pygeai/_docs/source/pygeai.tests.cli.rst +16 -0
- pygeai/_docs/source/pygeai.tests.core.embeddings.rst +16 -0
- pygeai/_docs/source/pygeai.tests.snippets.chat.rst +40 -0
- pygeai/_docs/source/pygeai.tests.snippets.dbg.rst +45 -0
- pygeai/_docs/source/pygeai.tests.snippets.embeddings.rst +40 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.dataset.rst +197 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.plan.rst +133 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.result.rst +37 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.rst +10 -0
- pygeai/_docs/source/pygeai.tests.snippets.rst +1 -0
- pygeai/admin/clients.py +5 -0
- pygeai/assistant/clients.py +7 -0
- pygeai/assistant/data_analyst/clients.py +2 -0
- pygeai/assistant/rag/clients.py +11 -0
- pygeai/chat/clients.py +236 -25
- pygeai/chat/endpoints.py +3 -1
- pygeai/cli/commands/chat.py +322 -1
- pygeai/cli/commands/embeddings.py +56 -8
- pygeai/cli/commands/migrate.py +994 -434
- pygeai/cli/error_handler.py +116 -0
- pygeai/cli/geai.py +28 -10
- pygeai/cli/parsers.py +8 -2
- pygeai/core/base/clients.py +3 -1
- pygeai/core/common/exceptions.py +11 -10
- pygeai/core/embeddings/__init__.py +19 -0
- pygeai/core/embeddings/clients.py +17 -2
- pygeai/core/embeddings/mappers.py +16 -2
- pygeai/core/embeddings/responses.py +9 -2
- pygeai/core/feedback/clients.py +1 -0
- pygeai/core/files/clients.py +5 -7
- pygeai/core/files/managers.py +42 -0
- pygeai/core/llm/clients.py +4 -0
- pygeai/core/plugins/clients.py +1 -0
- pygeai/core/rerank/clients.py +1 -0
- pygeai/core/secrets/clients.py +6 -0
- pygeai/core/services/rest.py +1 -1
- pygeai/dbg/__init__.py +3 -0
- pygeai/dbg/debugger.py +565 -70
- pygeai/evaluation/clients.py +1 -1
- pygeai/evaluation/dataset/clients.py +45 -44
- pygeai/evaluation/plan/clients.py +27 -26
- pygeai/evaluation/result/clients.py +37 -5
- pygeai/gam/clients.py +4 -0
- pygeai/health/clients.py +1 -0
- pygeai/lab/agents/clients.py +8 -1
- pygeai/lab/models.py +3 -3
- pygeai/lab/processes/clients.py +21 -0
- pygeai/lab/strategies/clients.py +4 -0
- pygeai/lab/tools/clients.py +1 -0
- pygeai/migration/__init__.py +31 -0
- pygeai/migration/strategies.py +404 -155
- pygeai/migration/tools.py +170 -3
- pygeai/organization/clients.py +13 -0
- pygeai/organization/limits/clients.py +15 -0
- pygeai/proxy/clients.py +3 -1
- pygeai/tests/admin/test_clients.py +16 -11
- pygeai/tests/assistants/rag/test_clients.py +35 -23
- pygeai/tests/assistants/test_clients.py +22 -15
- pygeai/tests/auth/test_clients.py +14 -6
- pygeai/tests/chat/test_clients.py +211 -1
- pygeai/tests/cli/commands/test_embeddings.py +32 -9
- pygeai/tests/cli/commands/test_evaluation.py +7 -0
- pygeai/tests/cli/commands/test_migrate.py +112 -243
- pygeai/tests/cli/test_error_handler.py +225 -0
- pygeai/tests/cli/test_geai_driver.py +154 -0
- pygeai/tests/cli/test_parsers.py +5 -5
- pygeai/tests/core/embeddings/test_clients.py +144 -0
- pygeai/tests/core/embeddings/test_managers.py +171 -0
- pygeai/tests/core/embeddings/test_mappers.py +142 -0
- pygeai/tests/core/feedback/test_clients.py +2 -0
- pygeai/tests/core/files/test_clients.py +1 -0
- pygeai/tests/core/llm/test_clients.py +14 -9
- pygeai/tests/core/plugins/test_clients.py +5 -3
- pygeai/tests/core/rerank/test_clients.py +1 -0
- pygeai/tests/core/secrets/test_clients.py +19 -13
- pygeai/tests/dbg/test_debugger.py +453 -75
- pygeai/tests/evaluation/dataset/test_clients.py +3 -1
- pygeai/tests/evaluation/plan/test_clients.py +4 -2
- pygeai/tests/evaluation/result/test_clients.py +7 -5
- pygeai/tests/gam/test_clients.py +1 -1
- pygeai/tests/health/test_clients.py +1 -0
- pygeai/tests/lab/agents/test_clients.py +9 -0
- pygeai/tests/lab/processes/test_clients.py +36 -0
- pygeai/tests/lab/processes/test_mappers.py +3 -0
- pygeai/tests/lab/strategies/test_clients.py +14 -9
- pygeai/tests/migration/test_strategies.py +45 -218
- pygeai/tests/migration/test_tools.py +133 -9
- pygeai/tests/organization/limits/test_clients.py +17 -0
- pygeai/tests/organization/test_clients.py +22 -0
- pygeai/tests/proxy/test_clients.py +2 -0
- pygeai/tests/proxy/test_integration.py +1 -0
- pygeai/tests/snippets/chat/chat_completion_with_reasoning_effort.py +18 -0
- pygeai/tests/snippets/chat/get_response.py +15 -0
- pygeai/tests/snippets/chat/get_response_streaming.py +20 -0
- pygeai/tests/snippets/chat/get_response_with_files.py +16 -0
- pygeai/tests/snippets/chat/get_response_with_tools.py +36 -0
- pygeai/tests/snippets/dbg/__init__.py +0 -0
- pygeai/tests/snippets/dbg/basic_debugging.py +32 -0
- pygeai/tests/snippets/dbg/breakpoint_management.py +48 -0
- pygeai/tests/snippets/dbg/stack_navigation.py +45 -0
- pygeai/tests/snippets/dbg/stepping_example.py +40 -0
- pygeai/tests/snippets/embeddings/cache_example.py +31 -0
- pygeai/tests/snippets/embeddings/cohere_example.py +41 -0
- pygeai/tests/snippets/embeddings/openai_base64_example.py +27 -0
- pygeai/tests/snippets/embeddings/openai_example.py +30 -0
- pygeai/tests/snippets/embeddings/similarity_example.py +42 -0
- pygeai/tests/snippets/evaluation/dataset/__init__.py +0 -0
- pygeai/tests/snippets/evaluation/dataset/complete_workflow_example.py +195 -0
- pygeai/tests/snippets/evaluation/dataset/create_dataset.py +26 -0
- pygeai/tests/snippets/evaluation/dataset/create_dataset_from_file.py +11 -0
- pygeai/tests/snippets/evaluation/dataset/create_dataset_row.py +17 -0
- pygeai/tests/snippets/evaluation/dataset/create_expected_source.py +18 -0
- pygeai/tests/snippets/evaluation/dataset/create_filter_variable.py +19 -0
- pygeai/tests/snippets/evaluation/dataset/delete_dataset.py +9 -0
- pygeai/tests/snippets/evaluation/dataset/delete_dataset_row.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/delete_expected_source.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/delete_filter_variable.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/get_dataset.py +9 -0
- pygeai/tests/snippets/evaluation/dataset/get_dataset_row.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/get_expected_source.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/get_filter_variable.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/list_dataset_rows.py +9 -0
- pygeai/tests/snippets/evaluation/dataset/list_datasets.py +6 -0
- pygeai/tests/snippets/evaluation/dataset/list_expected_sources.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/list_filter_variables.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/update_dataset.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/update_dataset_row.py +20 -0
- pygeai/tests/snippets/evaluation/dataset/update_expected_source.py +18 -0
- pygeai/tests/snippets/evaluation/dataset/update_filter_variable.py +19 -0
- pygeai/tests/snippets/evaluation/dataset/upload_dataset_rows_file.py +10 -0
- pygeai/tests/snippets/evaluation/plan/__init__.py +0 -0
- pygeai/tests/snippets/evaluation/plan/add_plan_system_metric.py +13 -0
- pygeai/tests/snippets/evaluation/plan/complete_workflow_example.py +136 -0
- pygeai/tests/snippets/evaluation/plan/create_evaluation_plan.py +24 -0
- pygeai/tests/snippets/evaluation/plan/create_rag_evaluation_plan.py +22 -0
- pygeai/tests/snippets/evaluation/plan/delete_evaluation_plan.py +9 -0
- pygeai/tests/snippets/evaluation/plan/delete_plan_system_metric.py +13 -0
- pygeai/tests/snippets/evaluation/plan/execute_evaluation_plan.py +11 -0
- pygeai/tests/snippets/evaluation/plan/get_evaluation_plan.py +9 -0
- pygeai/tests/snippets/evaluation/plan/get_plan_system_metric.py +13 -0
- pygeai/tests/snippets/evaluation/plan/get_system_metric.py +9 -0
- pygeai/tests/snippets/evaluation/plan/list_evaluation_plans.py +7 -0
- pygeai/tests/snippets/evaluation/plan/list_plan_system_metrics.py +9 -0
- pygeai/tests/snippets/evaluation/plan/list_system_metrics.py +7 -0
- pygeai/tests/snippets/evaluation/plan/update_evaluation_plan.py +22 -0
- pygeai/tests/snippets/evaluation/plan/update_plan_system_metric.py +14 -0
- pygeai/tests/snippets/evaluation/result/__init__.py +0 -0
- pygeai/tests/snippets/evaluation/result/complete_workflow_example.py +150 -0
- pygeai/tests/snippets/evaluation/result/get_evaluation_result.py +26 -0
- pygeai/tests/snippets/evaluation/result/list_evaluation_results.py +17 -0
- pygeai/tests/snippets/migrate/__init__.py +45 -0
- pygeai/tests/snippets/migrate/agent_migration.py +110 -0
- pygeai/tests/snippets/migrate/assistant_migration.py +64 -0
- pygeai/tests/snippets/migrate/orchestrator_examples.py +179 -0
- pygeai/tests/snippets/migrate/process_migration.py +64 -0
- pygeai/tests/snippets/migrate/project_migration.py +42 -0
- pygeai/tests/snippets/migrate/tool_migration.py +64 -0
- pygeai/tests/snippets/organization/create_project.py +2 -2
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/METADATA +1 -1
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/RECORD +178 -96
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/WHEEL +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/entry_points.txt +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/licenses/LICENSE +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
File Management
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
The File Management module provides functionality to upload, retrieve, and manage files within your organization and projects. Files can be used by assistants, stored for reference, or organized into folders.
|
|
5
|
+
|
|
6
|
+
This section covers:
|
|
7
|
+
|
|
8
|
+
* Uploading files to organization/project storage
|
|
9
|
+
* Retrieving file metadata and content
|
|
10
|
+
* Listing files in a project
|
|
11
|
+
* Deleting files
|
|
12
|
+
* Organizing files into folders
|
|
13
|
+
|
|
14
|
+
For each operation, you have three implementation options:
|
|
15
|
+
|
|
16
|
+
* `Command Line`_
|
|
17
|
+
* `Low-Level Service Layer`_
|
|
18
|
+
* `High-Level Service Layer`_
|
|
19
|
+
|
|
20
|
+
Overview
|
|
21
|
+
--------
|
|
22
|
+
|
|
23
|
+
File operations are scoped to:
|
|
24
|
+
|
|
25
|
+
* **Organization**: Top-level container for all resources
|
|
26
|
+
* **Project**: Specific project within an organization
|
|
27
|
+
* **Folder**: Optional logical grouping within a project
|
|
28
|
+
|
|
29
|
+
The SDK automatically resolves organization and project IDs from your API token when using the high-level manager.
|
|
30
|
+
|
|
31
|
+
Upload File
|
|
32
|
+
-----------
|
|
33
|
+
|
|
34
|
+
Uploads a file to project storage.
|
|
35
|
+
|
|
36
|
+
Command Line
|
|
37
|
+
^^^^^^^^^^^^
|
|
38
|
+
|
|
39
|
+
.. code-block:: shell
|
|
40
|
+
|
|
41
|
+
geai files upload \
|
|
42
|
+
--file-path "/path/to/document.pdf" \
|
|
43
|
+
--folder "documents" \
|
|
44
|
+
--file-name "user-manual.pdf"
|
|
45
|
+
|
|
46
|
+
Low-Level Service Layer
|
|
47
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
48
|
+
|
|
49
|
+
.. code-block:: python
|
|
50
|
+
|
|
51
|
+
from pygeai.core.files.clients import FileClient
|
|
52
|
+
|
|
53
|
+
client = FileClient()
|
|
54
|
+
|
|
55
|
+
result = client.upload_file(
|
|
56
|
+
file_path="/path/to/document.pdf",
|
|
57
|
+
organization_id="org-uuid",
|
|
58
|
+
project_id="project-uuid",
|
|
59
|
+
folder="documents",
|
|
60
|
+
file_name="user-manual.pdf"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
print(f"File uploaded: {result['fileId']}")
|
|
64
|
+
print(f"File URL: {result['url']}")
|
|
65
|
+
|
|
66
|
+
**Parameters:**
|
|
67
|
+
|
|
68
|
+
* ``file_path``: (Required) Local path to the file to upload
|
|
69
|
+
* ``organization_id``: (Required) Organization UUID
|
|
70
|
+
* ``project_id``: (Required) Project UUID
|
|
71
|
+
* ``folder``: Optional folder name (defaults to temporary storage if omitted)
|
|
72
|
+
* ``file_name``: Optional custom name (defaults to original filename)
|
|
73
|
+
|
|
74
|
+
**Returns:**
|
|
75
|
+
Dictionary containing file ID and URL.
|
|
76
|
+
|
|
77
|
+
High-Level Service Layer
|
|
78
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
79
|
+
|
|
80
|
+
.. code-block:: python
|
|
81
|
+
|
|
82
|
+
from pygeai.core.files.managers import FileManager
|
|
83
|
+
from pygeai.core.files.models import UploadFile
|
|
84
|
+
|
|
85
|
+
manager = FileManager()
|
|
86
|
+
|
|
87
|
+
file_to_upload = UploadFile(
|
|
88
|
+
path="/path/to/document.pdf",
|
|
89
|
+
name="user-manual.pdf",
|
|
90
|
+
folder="documents"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
response = manager.upload_file(file=file_to_upload)
|
|
94
|
+
|
|
95
|
+
print(f"File ID: {response.file_id}")
|
|
96
|
+
print(f"File URL: {response.url}")
|
|
97
|
+
|
|
98
|
+
**Components:**
|
|
99
|
+
|
|
100
|
+
* ``FileManager``: Automatically resolves organization and project IDs from API token
|
|
101
|
+
* ``UploadFile``: Model defining file upload parameters
|
|
102
|
+
* ``UploadFileResponse``: Response with file ID and URL
|
|
103
|
+
|
|
104
|
+
**Returns:**
|
|
105
|
+
``UploadFileResponse`` object containing upload details.
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
List Files
|
|
109
|
+
----------
|
|
110
|
+
|
|
111
|
+
Retrieves all files in a project.
|
|
112
|
+
|
|
113
|
+
Command Line
|
|
114
|
+
^^^^^^^^^^^^
|
|
115
|
+
|
|
116
|
+
.. code-block:: shell
|
|
117
|
+
|
|
118
|
+
geai files list
|
|
119
|
+
|
|
120
|
+
Low-Level Service Layer
|
|
121
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
122
|
+
|
|
123
|
+
.. code-block:: python
|
|
124
|
+
|
|
125
|
+
from pygeai.core.files.clients import FileClient
|
|
126
|
+
|
|
127
|
+
client = FileClient()
|
|
128
|
+
|
|
129
|
+
files = client.get_file_list(
|
|
130
|
+
organization="org-uuid",
|
|
131
|
+
project="project-uuid"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
for file in files.get('files', []):
|
|
135
|
+
print(f"{file['name']} - {file['folder']}")
|
|
136
|
+
|
|
137
|
+
**Parameters:**
|
|
138
|
+
|
|
139
|
+
* ``organization``: (Required) Organization UUID
|
|
140
|
+
* ``project``: (Required) Project UUID
|
|
141
|
+
|
|
142
|
+
**Returns:**
|
|
143
|
+
Dictionary containing list of files with metadata.
|
|
144
|
+
|
|
145
|
+
High-Level Service Layer
|
|
146
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
147
|
+
|
|
148
|
+
.. code-block:: python
|
|
149
|
+
|
|
150
|
+
from pygeai.core.files.managers import FileManager
|
|
151
|
+
|
|
152
|
+
manager = FileManager()
|
|
153
|
+
file_list = manager.get_file_list()
|
|
154
|
+
|
|
155
|
+
for file in file_list.files:
|
|
156
|
+
print(f"Name: {file.name}")
|
|
157
|
+
print(f"ID: {file.id}")
|
|
158
|
+
print(f"Folder: {file.folder}")
|
|
159
|
+
print(f"Size: {file.size} bytes")
|
|
160
|
+
print("---")
|
|
161
|
+
|
|
162
|
+
**Returns:**
|
|
163
|
+
``FileList`` object containing list of ``File`` objects.
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
Get File Metadata
|
|
167
|
+
-----------------
|
|
168
|
+
|
|
169
|
+
Retrieves metadata for a specific file.
|
|
170
|
+
|
|
171
|
+
Command Line
|
|
172
|
+
^^^^^^^^^^^^
|
|
173
|
+
|
|
174
|
+
.. code-block:: shell
|
|
175
|
+
|
|
176
|
+
geai files get --id "file-uuid"
|
|
177
|
+
|
|
178
|
+
Low-Level Service Layer
|
|
179
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
180
|
+
|
|
181
|
+
.. code-block:: python
|
|
182
|
+
|
|
183
|
+
from pygeai.core.files.clients import FileClient
|
|
184
|
+
|
|
185
|
+
client = FileClient()
|
|
186
|
+
|
|
187
|
+
file_data = client.get_file(
|
|
188
|
+
organization="org-uuid",
|
|
189
|
+
project="project-uuid",
|
|
190
|
+
file_id="file-uuid"
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
print(f"Name: {file_data['name']}")
|
|
194
|
+
print(f"Size: {file_data['size']}")
|
|
195
|
+
print(f"Folder: {file_data['folder']}")
|
|
196
|
+
print(f"Created: {file_data['createdAt']}")
|
|
197
|
+
|
|
198
|
+
**Parameters:**
|
|
199
|
+
|
|
200
|
+
* ``organization``: (Required) Organization UUID
|
|
201
|
+
* ``project``: (Required) Project UUID
|
|
202
|
+
* ``file_id``: (Required) File UUID
|
|
203
|
+
|
|
204
|
+
**Returns:**
|
|
205
|
+
Dictionary with file metadata (name, size, folder, timestamps, etc.).
|
|
206
|
+
|
|
207
|
+
High-Level Service Layer
|
|
208
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
209
|
+
|
|
210
|
+
.. code-block:: python
|
|
211
|
+
|
|
212
|
+
from pygeai.core.files.managers import FileManager
|
|
213
|
+
|
|
214
|
+
manager = FileManager()
|
|
215
|
+
file_data = manager.get_file_data(file_id="file-uuid")
|
|
216
|
+
|
|
217
|
+
print(f"File: {file_data.name}")
|
|
218
|
+
print(f"Size: {file_data.size} bytes")
|
|
219
|
+
print(f"Location: {file_data.folder}")
|
|
220
|
+
|
|
221
|
+
**Returns:**
|
|
222
|
+
``File`` object with file metadata.
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
Get File Content
|
|
226
|
+
----------------
|
|
227
|
+
|
|
228
|
+
Downloads the raw binary content of a file.
|
|
229
|
+
|
|
230
|
+
Command Line
|
|
231
|
+
^^^^^^^^^^^^
|
|
232
|
+
|
|
233
|
+
.. code-block:: shell
|
|
234
|
+
|
|
235
|
+
geai files download \
|
|
236
|
+
--id "file-uuid" \
|
|
237
|
+
--output "/path/to/save/file.pdf"
|
|
238
|
+
|
|
239
|
+
Low-Level Service Layer
|
|
240
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
241
|
+
|
|
242
|
+
.. code-block:: python
|
|
243
|
+
|
|
244
|
+
from pygeai.core.files.clients import FileClient
|
|
245
|
+
|
|
246
|
+
client = FileClient()
|
|
247
|
+
|
|
248
|
+
content = client.get_file_content(
|
|
249
|
+
organization="org-uuid",
|
|
250
|
+
project="project-uuid",
|
|
251
|
+
file_id="file-uuid"
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
# Save to file
|
|
255
|
+
with open("/path/to/save/file.pdf", "wb") as f:
|
|
256
|
+
f.write(content)
|
|
257
|
+
|
|
258
|
+
**Parameters:**
|
|
259
|
+
|
|
260
|
+
* ``organization``: (Required) Organization UUID
|
|
261
|
+
* ``project``: (Required) Project UUID
|
|
262
|
+
* ``file_id``: (Required) File UUID
|
|
263
|
+
|
|
264
|
+
**Returns:**
|
|
265
|
+
File content as bytes.
|
|
266
|
+
|
|
267
|
+
High-Level Service Layer
|
|
268
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
269
|
+
|
|
270
|
+
.. code-block:: python
|
|
271
|
+
|
|
272
|
+
from pygeai.core.files.managers import FileManager
|
|
273
|
+
|
|
274
|
+
manager = FileManager()
|
|
275
|
+
content = manager.get_file_content(file_id="file-uuid")
|
|
276
|
+
|
|
277
|
+
# Save to file
|
|
278
|
+
with open("/path/to/save/file.pdf", "wb") as f:
|
|
279
|
+
f.write(content)
|
|
280
|
+
|
|
281
|
+
print(f"Downloaded {len(content)} bytes")
|
|
282
|
+
|
|
283
|
+
**Returns:**
|
|
284
|
+
File content as bytes.
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
Delete File
|
|
288
|
+
-----------
|
|
289
|
+
|
|
290
|
+
Removes a file from storage.
|
|
291
|
+
|
|
292
|
+
Command Line
|
|
293
|
+
^^^^^^^^^^^^
|
|
294
|
+
|
|
295
|
+
.. code-block:: shell
|
|
296
|
+
|
|
297
|
+
geai files delete --id "file-uuid"
|
|
298
|
+
|
|
299
|
+
Low-Level Service Layer
|
|
300
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
301
|
+
|
|
302
|
+
.. code-block:: python
|
|
303
|
+
|
|
304
|
+
from pygeai.core.files.clients import FileClient
|
|
305
|
+
|
|
306
|
+
client = FileClient()
|
|
307
|
+
|
|
308
|
+
result = client.delete_file(
|
|
309
|
+
organization="org-uuid",
|
|
310
|
+
project="project-uuid",
|
|
311
|
+
file_id="file-uuid"
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
print("File deleted successfully")
|
|
315
|
+
|
|
316
|
+
**Parameters:**
|
|
317
|
+
|
|
318
|
+
* ``organization``: (Required) Organization UUID
|
|
319
|
+
* ``project``: (Required) Project UUID
|
|
320
|
+
* ``file_id``: (Required) File UUID
|
|
321
|
+
|
|
322
|
+
**Returns:**
|
|
323
|
+
Dictionary confirming deletion.
|
|
324
|
+
|
|
325
|
+
High-Level Service Layer
|
|
326
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
327
|
+
|
|
328
|
+
.. code-block:: python
|
|
329
|
+
|
|
330
|
+
from pygeai.core.files.managers import FileManager
|
|
331
|
+
|
|
332
|
+
manager = FileManager()
|
|
333
|
+
response = manager.delete_file(file_id="file-uuid")
|
|
334
|
+
|
|
335
|
+
print(f"Status: {response.message}")
|
|
336
|
+
|
|
337
|
+
**Returns:**
|
|
338
|
+
``EmptyResponse`` confirming successful deletion.
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
Complete Workflow Example
|
|
342
|
+
--------------------------
|
|
343
|
+
|
|
344
|
+
.. code-block:: python
|
|
345
|
+
|
|
346
|
+
from pygeai.core.files.managers import FileManager
|
|
347
|
+
from pygeai.core.files.models import UploadFile
|
|
348
|
+
from pathlib import Path
|
|
349
|
+
|
|
350
|
+
manager = FileManager()
|
|
351
|
+
|
|
352
|
+
# Upload a document
|
|
353
|
+
document = UploadFile(
|
|
354
|
+
path="/path/to/report.pdf",
|
|
355
|
+
name="quarterly-report-Q1-2026.pdf",
|
|
356
|
+
folder="reports/2026/Q1"
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
upload_response = manager.upload_file(file=document)
|
|
360
|
+
file_id = upload_response.file_id
|
|
361
|
+
print(f"Uploaded: {file_id}")
|
|
362
|
+
|
|
363
|
+
# List all files in the project
|
|
364
|
+
file_list = manager.get_file_list()
|
|
365
|
+
print(f"\nTotal files: {len(file_list.files)}")
|
|
366
|
+
|
|
367
|
+
for file in file_list.files:
|
|
368
|
+
print(f" - {file.name} ({file.folder})")
|
|
369
|
+
|
|
370
|
+
# Get file metadata
|
|
371
|
+
file_data = manager.get_file_data(file_id=file_id)
|
|
372
|
+
print(f"\nFile details:")
|
|
373
|
+
print(f" Name: {file_data.name}")
|
|
374
|
+
print(f" Size: {file_data.size:,} bytes")
|
|
375
|
+
print(f" Folder: {file_data.folder}")
|
|
376
|
+
|
|
377
|
+
# Download file content
|
|
378
|
+
content = manager.get_file_content(file_id=file_id)
|
|
379
|
+
|
|
380
|
+
# Save to local disk
|
|
381
|
+
output_path = Path(f"/tmp/{file_data.name}")
|
|
382
|
+
output_path.write_bytes(content)
|
|
383
|
+
print(f"\nDownloaded to: {output_path}")
|
|
384
|
+
|
|
385
|
+
# Clean up - delete file
|
|
386
|
+
manager.delete_file(file_id=file_id)
|
|
387
|
+
print("\nFile deleted from storage")
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
Folder Organization
|
|
391
|
+
-------------------
|
|
392
|
+
|
|
393
|
+
Organizing Files
|
|
394
|
+
~~~~~~~~~~~~~~~~
|
|
395
|
+
|
|
396
|
+
Use folders to organize files logically:
|
|
397
|
+
|
|
398
|
+
.. code-block:: python
|
|
399
|
+
|
|
400
|
+
from pygeai.core.files.managers import FileManager
|
|
401
|
+
from pygeai.core.files.models import UploadFile
|
|
402
|
+
|
|
403
|
+
manager = FileManager()
|
|
404
|
+
|
|
405
|
+
# Upload to different folders
|
|
406
|
+
folders = {
|
|
407
|
+
"contracts": "/path/to/contract.pdf",
|
|
408
|
+
"invoices/2026": "/path/to/invoice.pdf",
|
|
409
|
+
"documents/legal": "/path/to/terms.pdf"
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
for folder, filepath in folders.items():
|
|
413
|
+
file = UploadFile(
|
|
414
|
+
path=filepath,
|
|
415
|
+
folder=folder
|
|
416
|
+
)
|
|
417
|
+
manager.upload_file(file=file)
|
|
418
|
+
|
|
419
|
+
**Folder Naming:**
|
|
420
|
+
|
|
421
|
+
* Use forward slashes for hierarchy: ``"reports/2026/Q1"``
|
|
422
|
+
* Use descriptive names: ``"customer-documents"`` not ``"docs1"``
|
|
423
|
+
* Be consistent with naming conventions
|
|
424
|
+
|
|
425
|
+
Listing by Folder
|
|
426
|
+
~~~~~~~~~~~~~~~~~
|
|
427
|
+
|
|
428
|
+
.. code-block:: python
|
|
429
|
+
|
|
430
|
+
manager = FileManager()
|
|
431
|
+
all_files = manager.get_file_list()
|
|
432
|
+
|
|
433
|
+
# Group by folder
|
|
434
|
+
from collections import defaultdict
|
|
435
|
+
by_folder = defaultdict(list)
|
|
436
|
+
|
|
437
|
+
for file in all_files.files:
|
|
438
|
+
by_folder[file.folder].append(file)
|
|
439
|
+
|
|
440
|
+
for folder, files in sorted(by_folder.items()):
|
|
441
|
+
print(f"\n{folder or '(root)'}:")
|
|
442
|
+
for file in files:
|
|
443
|
+
print(f" - {file.name}")
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
Best Practices
|
|
447
|
+
--------------
|
|
448
|
+
|
|
449
|
+
File Naming
|
|
450
|
+
~~~~~~~~~~~
|
|
451
|
+
|
|
452
|
+
* Use descriptive names
|
|
453
|
+
* Include version or date when relevant
|
|
454
|
+
* Avoid special characters (use hyphens/underscores)
|
|
455
|
+
* Use consistent extensions
|
|
456
|
+
|
|
457
|
+
File Organization
|
|
458
|
+
~~~~~~~~~~~~~~~~~
|
|
459
|
+
|
|
460
|
+
* Use folders to group related files
|
|
461
|
+
* Create hierarchical folder structures
|
|
462
|
+
* Document folder naming conventions
|
|
463
|
+
* Clean up temporary files regularly
|
|
464
|
+
|
|
465
|
+
Storage Management
|
|
466
|
+
~~~~~~~~~~~~~~~~~~
|
|
467
|
+
|
|
468
|
+
* Monitor storage usage
|
|
469
|
+
* Delete obsolete files
|
|
470
|
+
* Use appropriate file formats (compressed when possible)
|
|
471
|
+
* Consider file size limits
|
|
472
|
+
|
|
473
|
+
Security
|
|
474
|
+
~~~~~~~~
|
|
475
|
+
|
|
476
|
+
* Only upload files you have rights to use
|
|
477
|
+
* Don't upload sensitive data without encryption
|
|
478
|
+
* Use project scoping to isolate files
|
|
479
|
+
* Audit file access regularly
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
Error Handling
|
|
483
|
+
--------------
|
|
484
|
+
|
|
485
|
+
.. code-block:: python
|
|
486
|
+
|
|
487
|
+
from pygeai.core.files.managers import FileManager
|
|
488
|
+
from pygeai.core.files.models import UploadFile
|
|
489
|
+
from pygeai.core.common.exceptions import APIError
|
|
490
|
+
|
|
491
|
+
manager = FileManager()
|
|
492
|
+
|
|
493
|
+
# Handle file not found
|
|
494
|
+
try:
|
|
495
|
+
file = UploadFile(path="/nonexistent/file.pdf")
|
|
496
|
+
manager.upload_file(file=file)
|
|
497
|
+
except FileNotFoundError as e:
|
|
498
|
+
print(f"File not found: {e}")
|
|
499
|
+
|
|
500
|
+
# Handle upload errors
|
|
501
|
+
try:
|
|
502
|
+
file = UploadFile(path="/path/to/file.pdf")
|
|
503
|
+
response = manager.upload_file(file=file)
|
|
504
|
+
except APIError as e:
|
|
505
|
+
print(f"Upload failed: {e}")
|
|
506
|
+
|
|
507
|
+
# Handle retrieval errors
|
|
508
|
+
try:
|
|
509
|
+
content = manager.get_file_content(file_id="invalid-id")
|
|
510
|
+
except APIError as e:
|
|
511
|
+
print(f"Could not retrieve file: {e}")
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
Common Issues
|
|
515
|
+
~~~~~~~~~~~~~
|
|
516
|
+
|
|
517
|
+
**File Not Found**
|
|
518
|
+
|
|
519
|
+
.. code-block:: python
|
|
520
|
+
|
|
521
|
+
# ❌ Wrong
|
|
522
|
+
file = UploadFile(path="relative/path.pdf")
|
|
523
|
+
|
|
524
|
+
# ✅ Correct - use absolute paths
|
|
525
|
+
file = UploadFile(path="/absolute/path/to/file.pdf")
|
|
526
|
+
|
|
527
|
+
**Missing Organization/Project ID**
|
|
528
|
+
|
|
529
|
+
.. code-block:: python
|
|
530
|
+
|
|
531
|
+
# ❌ Wrong - using low-level client without IDs
|
|
532
|
+
client = FileClient()
|
|
533
|
+
client.upload_file(file_path="file.pdf") # Missing org/project IDs
|
|
534
|
+
|
|
535
|
+
# ✅ Correct - use high-level manager (auto-resolves)
|
|
536
|
+
manager = FileManager()
|
|
537
|
+
file = UploadFile(path="file.pdf")
|
|
538
|
+
manager.upload_file(file=file)
|
|
539
|
+
|
|
540
|
+
# ✅ Or provide IDs explicitly with client
|
|
541
|
+
client.upload_file(
|
|
542
|
+
file_path="file.pdf",
|
|
543
|
+
organization_id="org-uuid",
|
|
544
|
+
project_id="project-uuid"
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
**Large File Uploads**
|
|
548
|
+
|
|
549
|
+
For large files, consider:
|
|
550
|
+
|
|
551
|
+
* Checking file size before upload
|
|
552
|
+
* Implementing progress tracking
|
|
553
|
+
* Handling timeout errors
|
|
554
|
+
* Using appropriate network settings
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
Integration Examples
|
|
558
|
+
--------------------
|
|
559
|
+
|
|
560
|
+
Upload File for Assistant
|
|
561
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
562
|
+
|
|
563
|
+
.. code-block:: python
|
|
564
|
+
|
|
565
|
+
from pygeai.core.files.managers import FileManager
|
|
566
|
+
from pygeai.core.files.models import UploadFile
|
|
567
|
+
|
|
568
|
+
# Upload a knowledge base document
|
|
569
|
+
manager = FileManager()
|
|
570
|
+
|
|
571
|
+
kb_file = UploadFile(
|
|
572
|
+
path="/path/to/knowledge-base.pdf",
|
|
573
|
+
name="product-documentation-v2.pdf",
|
|
574
|
+
folder="assistant-kb"
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
response = manager.upload_file(file=kb_file)
|
|
578
|
+
file_url = response.url
|
|
579
|
+
|
|
580
|
+
# Use file_url with RAG assistant configuration
|
|
581
|
+
print(f"Use this URL in assistant: {file_url}")
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
Notes
|
|
585
|
+
-----
|
|
586
|
+
|
|
587
|
+
* Files without a folder are stored in temporary storage
|
|
588
|
+
* File IDs are UUIDs generated by the system
|
|
589
|
+
* The high-level ``FileManager`` automatically resolves organization and project IDs from your API token
|
|
590
|
+
* File content is returned as binary data (bytes)
|
|
591
|
+
* Deleted files cannot be recovered
|
|
592
|
+
* Maximum file size depends on your organization's configuration
|