pygeai 0.6.0b7__py3-none-any.whl → 0.6.0b10__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 +191 -25
- pygeai/chat/endpoints.py +2 -1
- pygeai/cli/commands/chat.py +227 -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.0b10.dist-info}/METADATA +1 -1
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/RECORD +178 -96
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/WHEEL +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/entry_points.txt +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/licenses/LICENSE +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@ import unittest
|
|
|
2
2
|
from unittest.mock import patch, MagicMock
|
|
3
3
|
from json import JSONDecodeError
|
|
4
4
|
from pygeai.assistant.rag.clients import RAGAssistantClient
|
|
5
|
-
from pygeai.core.common.exceptions import InvalidAPIResponseException
|
|
5
|
+
from pygeai.core.common.exceptions import InvalidAPIResponseException, APIResponseError, APIResponseError
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class TestRAGAssistantClient(unittest.TestCase):
|
|
@@ -29,6 +29,7 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
29
29
|
def test_get_assistants_from_project_successful_json_response(self):
|
|
30
30
|
expected_response = {"assistants": []}
|
|
31
31
|
self.mock_response.json.return_value = expected_response
|
|
32
|
+
self.mock_response.status_code = 200
|
|
32
33
|
self.client.api_service.get.return_value = self.mock_response
|
|
33
34
|
|
|
34
35
|
result = self.client.get_assistants_from_project()
|
|
@@ -42,15 +43,16 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
42
43
|
self.mock_response.status_code = 500
|
|
43
44
|
self.client.api_service.get.return_value = self.mock_response
|
|
44
45
|
|
|
45
|
-
with self.assertRaises(
|
|
46
|
+
with self.assertRaises(APIResponseError) as context:
|
|
46
47
|
self.client.get_assistants_from_project()
|
|
47
48
|
|
|
48
49
|
self.client.api_service.get.assert_called_once()
|
|
49
|
-
self.assertIn("Unable to get assistants from project", str(context.exception))
|
|
50
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to get assistants from project", str(context.exception))
|
|
50
51
|
|
|
51
52
|
def test_get_assistant_data_successful_json_response(self):
|
|
52
53
|
expected_response = {"name": self.assistant_name, "details": "test"}
|
|
53
54
|
self.mock_response.json.return_value = expected_response
|
|
55
|
+
self.mock_response.status_code = 200
|
|
54
56
|
self.client.api_service.get.return_value = self.mock_response
|
|
55
57
|
|
|
56
58
|
result = self.client.get_assistant_data(self.assistant_name)
|
|
@@ -64,17 +66,18 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
64
66
|
self.mock_response.status_code = 500
|
|
65
67
|
self.client.api_service.get.return_value = self.mock_response
|
|
66
68
|
|
|
67
|
-
with self.assertRaises(
|
|
69
|
+
with self.assertRaises(APIResponseError) as context:
|
|
68
70
|
self.client.get_assistant_data(self.assistant_name)
|
|
69
71
|
|
|
70
72
|
self.client.api_service.get.assert_called_once()
|
|
71
|
-
self.assertIn("Unable to get assistant data", str(context.exception))
|
|
73
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to get assistant data", str(context.exception))
|
|
72
74
|
|
|
73
75
|
def test_create_assistant_successful_json_response(self):
|
|
74
76
|
name = "new_assistant"
|
|
75
77
|
description = "Test description"
|
|
76
78
|
expected_response = {"id": "new_id", "name": name}
|
|
77
79
|
self.mock_response.json.return_value = expected_response
|
|
80
|
+
self.mock_response.status_code = 200
|
|
78
81
|
self.client.api_service.post.return_value = self.mock_response
|
|
79
82
|
|
|
80
83
|
result = self.client.create_assistant(name, description)
|
|
@@ -90,17 +93,18 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
90
93
|
self.mock_response.status_code = 500
|
|
91
94
|
self.client.api_service.post.return_value = self.mock_response
|
|
92
95
|
|
|
93
|
-
with self.assertRaises(
|
|
96
|
+
with self.assertRaises(APIResponseError) as context:
|
|
94
97
|
self.client.create_assistant(name, description)
|
|
95
98
|
|
|
96
99
|
self.client.api_service.post.assert_called_once()
|
|
97
|
-
self.assertIn("Unable to create assistant", str(context.exception))
|
|
100
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to create assistant", str(context.exception))
|
|
98
101
|
|
|
99
102
|
def test_update_assistant_successful_json_response(self):
|
|
100
103
|
name = "test_assistant"
|
|
101
104
|
status = 1
|
|
102
105
|
expected_response = {"name": name, "status": status}
|
|
103
106
|
self.mock_response.json.return_value = expected_response
|
|
107
|
+
self.mock_response.status_code = 200
|
|
104
108
|
self.client.api_service.put.return_value = self.mock_response
|
|
105
109
|
|
|
106
110
|
result = self.client.update_assistant(name, status)
|
|
@@ -116,16 +120,17 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
116
120
|
self.mock_response.status_code = 500
|
|
117
121
|
self.client.api_service.put.return_value = self.mock_response
|
|
118
122
|
|
|
119
|
-
with self.assertRaises(
|
|
123
|
+
with self.assertRaises(APIResponseError) as context:
|
|
120
124
|
self.client.update_assistant(name, status)
|
|
121
125
|
|
|
122
126
|
self.client.api_service.put.assert_called_once()
|
|
123
|
-
self.assertIn("Unable to update assistant", str(context.exception))
|
|
127
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to update assistant", str(context.exception))
|
|
124
128
|
|
|
125
129
|
def test_delete_assistant_successful_json_response(self):
|
|
126
130
|
name = "test_assistant"
|
|
127
131
|
expected_response = {"message": "Assistant deleted"}
|
|
128
132
|
self.mock_response.json.return_value = expected_response
|
|
133
|
+
self.mock_response.status_code = 200
|
|
129
134
|
self.client.api_service.delete.return_value = self.mock_response
|
|
130
135
|
|
|
131
136
|
result = self.client.delete_assistant(name)
|
|
@@ -140,11 +145,11 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
140
145
|
self.mock_response.status_code = 500
|
|
141
146
|
self.client.api_service.delete.return_value = self.mock_response
|
|
142
147
|
|
|
143
|
-
with self.assertRaises(
|
|
148
|
+
with self.assertRaises(APIResponseError) as context:
|
|
144
149
|
self.client.delete_assistant(name)
|
|
145
150
|
|
|
146
151
|
self.client.api_service.delete.assert_called_once()
|
|
147
|
-
self.assertIn("Unable to delete assistant", str(context.exception))
|
|
152
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to delete assistant", str(context.exception))
|
|
148
153
|
|
|
149
154
|
def test_get_documents_successful_json_response(self):
|
|
150
155
|
name = "test_assistant"
|
|
@@ -152,6 +157,7 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
152
157
|
count = 10
|
|
153
158
|
expected_response = {"documents": []}
|
|
154
159
|
self.mock_response.json.return_value = expected_response
|
|
160
|
+
self.mock_response.status_code = 200
|
|
155
161
|
self.client.api_service.get.return_value = self.mock_response
|
|
156
162
|
|
|
157
163
|
result = self.client.get_documents(name, skip, count)
|
|
@@ -168,16 +174,17 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
168
174
|
self.mock_response.status_code = 500
|
|
169
175
|
self.client.api_service.get.return_value = self.mock_response
|
|
170
176
|
|
|
171
|
-
with self.assertRaises(
|
|
177
|
+
with self.assertRaises(APIResponseError) as context:
|
|
172
178
|
self.client.get_documents(name, skip, count)
|
|
173
179
|
|
|
174
180
|
self.client.api_service.get.assert_called_once()
|
|
175
|
-
self.assertIn("Unable to get documents", str(context.exception))
|
|
181
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to get documents", str(context.exception))
|
|
176
182
|
|
|
177
183
|
def test_delete_all_documents_successful_json_response(self):
|
|
178
184
|
name = "test_assistant"
|
|
179
185
|
expected_response = {"message": "All documents deleted"}
|
|
180
186
|
self.mock_response.json.return_value = expected_response
|
|
187
|
+
self.mock_response.status_code = 200
|
|
181
188
|
self.client.api_service.delete.return_value = self.mock_response
|
|
182
189
|
|
|
183
190
|
result = self.client.delete_all_documents(name)
|
|
@@ -192,17 +199,18 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
192
199
|
self.mock_response.status_code = 500
|
|
193
200
|
self.client.api_service.delete.return_value = self.mock_response
|
|
194
201
|
|
|
195
|
-
with self.assertRaises(
|
|
202
|
+
with self.assertRaises(APIResponseError) as context:
|
|
196
203
|
self.client.delete_all_documents(name)
|
|
197
204
|
|
|
198
205
|
self.client.api_service.delete.assert_called_once()
|
|
199
|
-
self.assertIn("Unable to delete all documents", str(context.exception))
|
|
206
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to delete all documents", str(context.exception))
|
|
200
207
|
|
|
201
208
|
def test_retrieve_document_successful_json_response(self):
|
|
202
209
|
name = "test_assistant"
|
|
203
210
|
document_id = "doc_123"
|
|
204
211
|
expected_response = {"id": document_id, "content": "test content"}
|
|
205
212
|
self.mock_response.json.return_value = expected_response
|
|
213
|
+
self.mock_response.status_code = 200
|
|
206
214
|
self.client.api_service.get.return_value = self.mock_response
|
|
207
215
|
|
|
208
216
|
result = self.client.retrieve_document(name, document_id)
|
|
@@ -218,11 +226,11 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
218
226
|
self.mock_response.status_code = 500
|
|
219
227
|
self.client.api_service.get.return_value = self.mock_response
|
|
220
228
|
|
|
221
|
-
with self.assertRaises(
|
|
229
|
+
with self.assertRaises(APIResponseError) as context:
|
|
222
230
|
self.client.retrieve_document(name, document_id)
|
|
223
231
|
|
|
224
232
|
self.client.api_service.get.assert_called_once()
|
|
225
|
-
self.assertIn("Unable to retrieve document", str(context.exception))
|
|
233
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to retrieve document", str(context.exception))
|
|
226
234
|
|
|
227
235
|
def test_upload_document_binary_successful_json_response(self):
|
|
228
236
|
name = "test_assistant"
|
|
@@ -231,6 +239,7 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
231
239
|
content_type = "application/pdf"
|
|
232
240
|
expected_response = {"id": "uploaded_doc", "status": "success"}
|
|
233
241
|
self.mock_response.json.return_value = expected_response
|
|
242
|
+
self.mock_response.status_code = 200
|
|
234
243
|
self.client.api_service.post_file_binary.return_value = self.mock_response
|
|
235
244
|
|
|
236
245
|
with patch('builtins.open', return_value=MagicMock()):
|
|
@@ -247,6 +256,7 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
247
256
|
metadata = {"key": "value"}
|
|
248
257
|
expected_response = {"id": "uploaded_doc", "status": "success"}
|
|
249
258
|
self.mock_response.json.return_value = expected_response
|
|
259
|
+
self.mock_response.status_code = 200
|
|
250
260
|
self.client.api_service.post_files_multipart.return_value = self.mock_response
|
|
251
261
|
|
|
252
262
|
with patch('builtins.open', return_value=MagicMock()), \
|
|
@@ -277,17 +287,18 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
277
287
|
self.client.api_service.post_file_binary.return_value = self.mock_response
|
|
278
288
|
|
|
279
289
|
with patch('builtins.open', return_value=MagicMock()):
|
|
280
|
-
with self.assertRaises(
|
|
290
|
+
with self.assertRaises(APIResponseError) as context:
|
|
281
291
|
self.client.upload_document(name, file_path, upload_type, content_type=content_type)
|
|
282
292
|
|
|
283
293
|
self.client.api_service.post_file_binary.assert_called_once()
|
|
284
|
-
self.assertIn("Unable to upload document", str(context.exception))
|
|
294
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to upload document", str(context.exception))
|
|
285
295
|
|
|
286
296
|
def test_delete_document_successful_json_response(self):
|
|
287
297
|
name = "test_assistant"
|
|
288
298
|
document_id = "doc_123"
|
|
289
299
|
expected_response = {"message": "Document deleted"}
|
|
290
300
|
self.mock_response.json.return_value = expected_response
|
|
301
|
+
self.mock_response.status_code = 200
|
|
291
302
|
self.client.api_service.delete.return_value = self.mock_response
|
|
292
303
|
|
|
293
304
|
result = self.client.delete_document(name, document_id)
|
|
@@ -303,16 +314,17 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
303
314
|
self.mock_response.status_code = 500
|
|
304
315
|
self.client.api_service.delete.return_value = self.mock_response
|
|
305
316
|
|
|
306
|
-
with self.assertRaises(
|
|
317
|
+
with self.assertRaises(APIResponseError) as context:
|
|
307
318
|
self.client.delete_document(name, document_id)
|
|
308
319
|
|
|
309
320
|
self.client.api_service.delete.assert_called_once()
|
|
310
|
-
self.assertIn("Unable to delete document", str(context.exception))
|
|
321
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to delete document", str(context.exception))
|
|
311
322
|
|
|
312
323
|
def test_execute_query_successful_json_response(self):
|
|
313
324
|
query = {"text": "test query"}
|
|
314
325
|
expected_response = {"result": "query response"}
|
|
315
326
|
self.mock_response.json.return_value = expected_response
|
|
327
|
+
self.mock_response.status_code = 200
|
|
316
328
|
self.client.api_service.post.return_value = self.mock_response
|
|
317
329
|
|
|
318
330
|
result = self.client.execute_query(query)
|
|
@@ -327,8 +339,8 @@ class TestRAGAssistantClient(unittest.TestCase):
|
|
|
327
339
|
self.mock_response.status_code = 500
|
|
328
340
|
self.client.api_service.post.return_value = self.mock_response
|
|
329
341
|
|
|
330
|
-
with self.assertRaises(
|
|
342
|
+
with self.assertRaises(APIResponseError) as context:
|
|
331
343
|
self.client.execute_query(query)
|
|
332
344
|
|
|
333
345
|
self.client.api_service.post.assert_called_once()
|
|
334
|
-
self.assertIn("Unable to execute query", str(context.exception))
|
|
346
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to execute query", str(context.exception))
|
|
@@ -2,7 +2,7 @@ import unittest
|
|
|
2
2
|
from unittest.mock import patch, MagicMock
|
|
3
3
|
from json import JSONDecodeError
|
|
4
4
|
from pygeai.assistant.clients import AssistantClient
|
|
5
|
-
from pygeai.core.common.exceptions import InvalidAPIResponseException
|
|
5
|
+
from pygeai.core.common.exceptions import InvalidAPIResponseException, APIResponseError, APIResponseError
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class TestAssistantClient(unittest.TestCase):
|
|
@@ -22,6 +22,7 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
22
22
|
detail = "summary"
|
|
23
23
|
expected_response = {"id": self.assistant_id, "name": "Test Assistant"}
|
|
24
24
|
self.mock_response.json.return_value = expected_response
|
|
25
|
+
self.mock_response.status_code = 200
|
|
25
26
|
self.client.api_service.get.return_value = self.mock_response
|
|
26
27
|
|
|
27
28
|
result = self.client.get_assistant_data(self.assistant_id, detail)
|
|
@@ -36,11 +37,11 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
36
37
|
self.mock_response.status_code = 500
|
|
37
38
|
self.client.api_service.get.return_value = self.mock_response
|
|
38
39
|
|
|
39
|
-
with self.assertRaises(
|
|
40
|
+
with self.assertRaises(APIResponseError) as context:
|
|
40
41
|
self.client.get_assistant_data(self.assistant_id, detail)
|
|
41
42
|
|
|
42
43
|
self.client.api_service.get.assert_called_once()
|
|
43
|
-
self.assertIn("Unable to get assistant data", str(context.exception))
|
|
44
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to get assistant data", str(context.exception))
|
|
44
45
|
|
|
45
46
|
def test_create_assistant_successful_json_response(self):
|
|
46
47
|
assistant_type = "text"
|
|
@@ -48,6 +49,7 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
48
49
|
prompt = "Help with text"
|
|
49
50
|
expected_response = {"id": "new_id", "name": name}
|
|
50
51
|
self.mock_response.json.return_value = expected_response
|
|
52
|
+
self.mock_response.status_code = 200
|
|
51
53
|
self.client.api_service.post.return_value = self.mock_response
|
|
52
54
|
|
|
53
55
|
result = self.client.create_assistant(assistant_type, name, prompt)
|
|
@@ -64,17 +66,18 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
64
66
|
self.mock_response.status_code = 500
|
|
65
67
|
self.client.api_service.post.return_value = self.mock_response
|
|
66
68
|
|
|
67
|
-
with self.assertRaises(
|
|
69
|
+
with self.assertRaises(APIResponseError) as context:
|
|
68
70
|
self.client.create_assistant(assistant_type, name, prompt)
|
|
69
71
|
|
|
70
72
|
self.client.api_service.post.assert_called_once()
|
|
71
|
-
self.assertIn("Unable to create assistant", str(context.exception))
|
|
73
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to create assistant", str(context.exception))
|
|
72
74
|
|
|
73
75
|
def test_update_assistant_successful_json_response(self):
|
|
74
76
|
status = 1
|
|
75
77
|
action = "save"
|
|
76
78
|
expected_response = {"id": self.assistant_id, "status": status}
|
|
77
79
|
self.mock_response.json.return_value = expected_response
|
|
80
|
+
self.mock_response.status_code = 200
|
|
78
81
|
self.client.api_service.put.return_value = self.mock_response
|
|
79
82
|
|
|
80
83
|
result = self.client.update_assistant(self.assistant_id, status, action)
|
|
@@ -90,15 +93,16 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
90
93
|
self.mock_response.status_code = 500
|
|
91
94
|
self.client.api_service.put.return_value = self.mock_response
|
|
92
95
|
|
|
93
|
-
with self.assertRaises(
|
|
96
|
+
with self.assertRaises(APIResponseError) as context:
|
|
94
97
|
self.client.update_assistant(self.assistant_id, status, action)
|
|
95
98
|
|
|
96
99
|
self.client.api_service.put.assert_called_once()
|
|
97
|
-
self.assertIn("Unable to update assistant", str(context.exception))
|
|
100
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to update assistant", str(context.exception))
|
|
98
101
|
|
|
99
102
|
def test_delete_assistant_successful_json_response(self):
|
|
100
103
|
expected_response = {"message": "Assistant deleted"}
|
|
101
104
|
self.mock_response.json.return_value = expected_response
|
|
105
|
+
self.mock_response.status_code = 200
|
|
102
106
|
self.client.api_service.delete.return_value = self.mock_response
|
|
103
107
|
|
|
104
108
|
result = self.client.delete_assistant(self.assistant_id)
|
|
@@ -112,16 +116,17 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
112
116
|
self.mock_response.status_code = 500
|
|
113
117
|
self.client.api_service.delete.return_value = self.mock_response
|
|
114
118
|
|
|
115
|
-
with self.assertRaises(
|
|
119
|
+
with self.assertRaises(APIResponseError) as context:
|
|
116
120
|
self.client.delete_assistant(self.assistant_id)
|
|
117
121
|
|
|
118
122
|
self.client.api_service.delete.assert_called_once()
|
|
119
|
-
self.assertIn("Unable to delete assistant", str(context.exception))
|
|
123
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to delete assistant", str(context.exception))
|
|
120
124
|
|
|
121
125
|
def test_send_chat_request_successful_json_response(self):
|
|
122
126
|
messages = [{"role": "user", "content": "Hello"}]
|
|
123
127
|
expected_response = {"response": "Hi there!"}
|
|
124
128
|
self.mock_response.json.return_value = expected_response
|
|
129
|
+
self.mock_response.status_code = 200
|
|
125
130
|
self.client.api_service.post.return_value = self.mock_response
|
|
126
131
|
|
|
127
132
|
result = self.client.send_chat_request(self.assistant_name, messages)
|
|
@@ -136,15 +141,16 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
136
141
|
self.mock_response.status_code = 500
|
|
137
142
|
self.client.api_service.post.return_value = self.mock_response
|
|
138
143
|
|
|
139
|
-
with self.assertRaises(
|
|
144
|
+
with self.assertRaises(APIResponseError) as context:
|
|
140
145
|
self.client.send_chat_request(self.assistant_name, messages)
|
|
141
146
|
|
|
142
147
|
self.client.api_service.post.assert_called_once()
|
|
143
|
-
self.assertIn("Unable to send chat request", str(context.exception))
|
|
148
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to send chat request", str(context.exception))
|
|
144
149
|
|
|
145
150
|
def test_get_request_status_successful_json_response(self):
|
|
146
151
|
expected_response = {"status": "completed"}
|
|
147
152
|
self.mock_response.json.return_value = expected_response
|
|
153
|
+
self.mock_response.status_code = 200
|
|
148
154
|
self.client.api_service.get.return_value = self.mock_response
|
|
149
155
|
|
|
150
156
|
result = self.client.get_request_status(self.request_id)
|
|
@@ -158,15 +164,16 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
158
164
|
self.mock_response.status_code = 500
|
|
159
165
|
self.client.api_service.get.return_value = self.mock_response
|
|
160
166
|
|
|
161
|
-
with self.assertRaises(
|
|
167
|
+
with self.assertRaises(APIResponseError) as context:
|
|
162
168
|
self.client.get_request_status(self.request_id)
|
|
163
169
|
|
|
164
170
|
self.client.api_service.get.assert_called_once()
|
|
165
|
-
self.assertIn("Unable to get request status", str(context.exception))
|
|
171
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to get request status", str(context.exception))
|
|
166
172
|
|
|
167
173
|
def test_cancel_request_successful_json_response(self):
|
|
168
174
|
expected_response = {"message": "Request cancelled"}
|
|
169
175
|
self.mock_response.json.return_value = expected_response
|
|
176
|
+
self.mock_response.status_code = 200
|
|
170
177
|
self.client.api_service.post.return_value = self.mock_response
|
|
171
178
|
|
|
172
179
|
result = self.client.cancel_request(self.request_id)
|
|
@@ -180,9 +187,9 @@ class TestAssistantClient(unittest.TestCase):
|
|
|
180
187
|
self.mock_response.status_code = 500
|
|
181
188
|
self.client.api_service.post.return_value = self.mock_response
|
|
182
189
|
|
|
183
|
-
with self.assertRaises(
|
|
190
|
+
with self.assertRaises(APIResponseError) as context:
|
|
184
191
|
self.client.cancel_request(self.request_id)
|
|
185
192
|
|
|
186
193
|
self.client.api_service.post.assert_called_once()
|
|
187
|
-
self.assertIn("Unable to cancel request", str(context.exception))
|
|
194
|
+
self.assertIn("API returned an error", str(context.exception)) # "Unable to cancel request", str(context.exception))
|
|
188
195
|
|
|
@@ -38,6 +38,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
38
38
|
@patch('pygeai.core.services.rest.ApiService.get')
|
|
39
39
|
def test_get_oauth2_access_token_custom_scope(self, mock_get):
|
|
40
40
|
self.mock_response.json.return_value = {"access_token": "token-123"}
|
|
41
|
+
self.mock_response.status_code = 200
|
|
41
42
|
mock_get.return_value = self.mock_response
|
|
42
43
|
|
|
43
44
|
result = self.client.get_oauth2_access_token(
|
|
@@ -62,7 +63,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
62
63
|
username="user@example.com",
|
|
63
64
|
password="wrong"
|
|
64
65
|
)
|
|
65
|
-
self.assertIn("API returned an error", str(context.exception))
|
|
66
|
+
self.assertIn("API returned an error", str(context.exception)) # "API returned an error", str(context.exception))
|
|
66
67
|
|
|
67
68
|
@patch.object(AuthClient, 'api_service', create=True)
|
|
68
69
|
def test_get_user_profile_information_success(self, mock_api_service):
|
|
@@ -71,6 +72,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
71
72
|
"email": "user@example.com",
|
|
72
73
|
"name": "Test User"
|
|
73
74
|
}
|
|
75
|
+
self.mock_response.status_code = 200
|
|
74
76
|
mock_api_service.get.return_value = self.mock_response
|
|
75
77
|
mock_api_service.token = None
|
|
76
78
|
|
|
@@ -98,7 +100,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
98
100
|
|
|
99
101
|
with self.assertRaises(APIResponseError) as context:
|
|
100
102
|
client.get_user_profile_information("invalid-token")
|
|
101
|
-
self.assertIn("API returned an error", str(context.exception))
|
|
103
|
+
self.assertIn("API returned an error", str(context.exception)) # "API returned an error", str(context.exception))
|
|
102
104
|
|
|
103
105
|
@patch('pygeai.core.services.rest.ApiService.post')
|
|
104
106
|
def test_create_project_api_token_success(self, mock_post):
|
|
@@ -119,6 +121,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
119
121
|
],
|
|
120
122
|
"errors": []
|
|
121
123
|
}
|
|
124
|
+
self.mock_response.status_code = 200
|
|
122
125
|
mock_post.return_value = self.mock_response
|
|
123
126
|
|
|
124
127
|
result = self.client.create_project_api_token(
|
|
@@ -142,6 +145,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
142
145
|
"name": "TestToken",
|
|
143
146
|
"status": "Active"
|
|
144
147
|
}
|
|
148
|
+
self.mock_response.status_code = 200
|
|
145
149
|
mock_post.return_value = self.mock_response
|
|
146
150
|
|
|
147
151
|
result = self.client.create_project_api_token(
|
|
@@ -164,11 +168,12 @@ class TestAuthClient(unittest.TestCase):
|
|
|
164
168
|
project_id="project-123",
|
|
165
169
|
name="TestToken"
|
|
166
170
|
)
|
|
167
|
-
self.assertIn("API returned an error", str(context.exception))
|
|
171
|
+
self.assertIn("API returned an error", str(context.exception)) # "API returned an error", str(context.exception))
|
|
168
172
|
|
|
169
173
|
@patch('pygeai.core.services.rest.ApiService.delete')
|
|
170
174
|
def test_delete_project_api_token_success(self, mock_delete):
|
|
171
175
|
self.mock_response.json.return_value = {}
|
|
176
|
+
self.mock_response.status_code = 200
|
|
172
177
|
mock_delete.return_value = self.mock_response
|
|
173
178
|
|
|
174
179
|
result = self.client.delete_project_api_token(api_token_id="token-123")
|
|
@@ -187,7 +192,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
187
192
|
|
|
188
193
|
with self.assertRaises(APIResponseError) as context:
|
|
189
194
|
self.client.delete_project_api_token(api_token_id="invalid-token")
|
|
190
|
-
self.assertIn("API returned an error", str(context.exception))
|
|
195
|
+
self.assertIn("API returned an error", str(context.exception)) # "API returned an error", str(context.exception))
|
|
191
196
|
|
|
192
197
|
@patch('pygeai.core.services.rest.ApiService.put')
|
|
193
198
|
def test_update_project_api_token_success(self, mock_put):
|
|
@@ -197,6 +202,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
197
202
|
"type": "Success"
|
|
198
203
|
}
|
|
199
204
|
]
|
|
205
|
+
self.mock_response.status_code = 200
|
|
200
206
|
mock_put.return_value = self.mock_response
|
|
201
207
|
|
|
202
208
|
result = self.client.update_project_api_token(
|
|
@@ -220,6 +226,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
220
226
|
"type": "Success"
|
|
221
227
|
}
|
|
222
228
|
]
|
|
229
|
+
self.mock_response.status_code = 200
|
|
223
230
|
mock_put.return_value = self.mock_response
|
|
224
231
|
|
|
225
232
|
result = self.client.update_project_api_token(
|
|
@@ -243,7 +250,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
243
250
|
api_token_id="token-123",
|
|
244
251
|
description="New description"
|
|
245
252
|
)
|
|
246
|
-
self.assertIn("API returned an error", str(context.exception))
|
|
253
|
+
self.assertIn("API returned an error", str(context.exception)) # "API returned an error", str(context.exception))
|
|
247
254
|
|
|
248
255
|
@patch('pygeai.core.services.rest.ApiService.get')
|
|
249
256
|
def test_get_project_api_token_success(self, mock_get):
|
|
@@ -255,6 +262,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
255
262
|
"scope": "Pia.Data.Organization",
|
|
256
263
|
"timestamp": "2024-07-22T18:37:32.341"
|
|
257
264
|
}
|
|
265
|
+
self.mock_response.status_code = 200
|
|
258
266
|
mock_get.return_value = self.mock_response
|
|
259
267
|
|
|
260
268
|
result = self.client.get_project_api_token(api_token_id="token-123")
|
|
@@ -274,7 +282,7 @@ class TestAuthClient(unittest.TestCase):
|
|
|
274
282
|
|
|
275
283
|
with self.assertRaises(APIResponseError) as context:
|
|
276
284
|
self.client.get_project_api_token(api_token_id="invalid-token")
|
|
277
|
-
self.assertIn("API returned an error", str(context.exception))
|
|
285
|
+
self.assertIn("API returned an error", str(context.exception)) # "API returned an error", str(context.exception))
|
|
278
286
|
|
|
279
287
|
|
|
280
288
|
if __name__ == '__main__':
|