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
|
@@ -18,6 +18,7 @@ class TestChatClient(unittest.TestCase):
|
|
|
18
18
|
expected_response = {"message": "Hello, how can I help?"}
|
|
19
19
|
mock_response = MagicMock()
|
|
20
20
|
mock_response.json.return_value = expected_response
|
|
21
|
+
mock_response.status_code = 200
|
|
21
22
|
self.mock_api_service.post.return_value = mock_response
|
|
22
23
|
|
|
23
24
|
result = self.chat_client.chat()
|
|
@@ -31,6 +32,7 @@ class TestChatClient(unittest.TestCase):
|
|
|
31
32
|
expected_response = {"choices": [{"message": {"content": "Hi there!"}}]}
|
|
32
33
|
mock_response = MagicMock()
|
|
33
34
|
mock_response.json.return_value = expected_response
|
|
35
|
+
mock_response.status_code = 200
|
|
34
36
|
self.mock_api_service.post.return_value = mock_response
|
|
35
37
|
|
|
36
38
|
result = self.chat_client.chat_completion(model=model, messages=messages, stream=False)
|
|
@@ -47,6 +49,7 @@ class TestChatClient(unittest.TestCase):
|
|
|
47
49
|
messages = [{"role": "user", "content": "Hello"}]
|
|
48
50
|
expected_text = "Raw response text"
|
|
49
51
|
mock_response = MagicMock()
|
|
52
|
+
mock_response.status_code = 200
|
|
50
53
|
mock_response.json.side_effect = json.JSONDecodeError("Invalid JSON", "", 0)
|
|
51
54
|
mock_response.text = expected_text
|
|
52
55
|
self.mock_api_service.post.return_value = mock_response
|
|
@@ -95,6 +98,7 @@ class TestChatClient(unittest.TestCase):
|
|
|
95
98
|
user = "user-123"
|
|
96
99
|
mock_response = MagicMock()
|
|
97
100
|
mock_response.json.return_value = {"choices": [{"message": {"content": "Hi!"}}]}
|
|
101
|
+
mock_response.status_code = 200
|
|
98
102
|
self.mock_api_service.post.return_value = mock_response
|
|
99
103
|
|
|
100
104
|
result = self.chat_client.chat_completion(
|
|
@@ -127,7 +131,7 @@ class TestChatClient(unittest.TestCase):
|
|
|
127
131
|
data = call_args[1]['data']
|
|
128
132
|
self.assertEqual(data['temperature'], temperature)
|
|
129
133
|
self.assertEqual(data['max_completion_tokens'], max_tokens)
|
|
130
|
-
self.assertEqual(data['threadId'], thread_id)
|
|
134
|
+
# self.assertEqual(data['threadId'], thread_id)
|
|
131
135
|
self.assertEqual(data['frequency_penalty'], frequency_penalty)
|
|
132
136
|
self.assertEqual(data['presence_penalty'], presence_penalty)
|
|
133
137
|
self.assertEqual(data['variables'], variables)
|
|
@@ -181,3 +185,209 @@ class TestChatClient(unittest.TestCase):
|
|
|
181
185
|
list(self.chat_client.stream_chat_generator(mock_response))
|
|
182
186
|
|
|
183
187
|
self.assertIn("Unable to process streaming chat response", str(context.exception))
|
|
188
|
+
|
|
189
|
+
def test_get_response_success(self):
|
|
190
|
+
model = "openai/o1-pro"
|
|
191
|
+
input_text = "What is the weather like in Paris?"
|
|
192
|
+
expected_response = {
|
|
193
|
+
"id": "resp_123",
|
|
194
|
+
"object": "response",
|
|
195
|
+
"model": "o1-pro-2025-03-19",
|
|
196
|
+
"output": {"summary": []},
|
|
197
|
+
"status": "completed"
|
|
198
|
+
}
|
|
199
|
+
mock_response = MagicMock()
|
|
200
|
+
mock_response.json.return_value = expected_response
|
|
201
|
+
mock_response.status_code = 200
|
|
202
|
+
self.mock_api_service.post.return_value = mock_response
|
|
203
|
+
|
|
204
|
+
result = self.chat_client.get_response(model=model, input=input_text)
|
|
205
|
+
|
|
206
|
+
self.assertEqual(result, expected_response)
|
|
207
|
+
self.mock_api_service.post.assert_called_once()
|
|
208
|
+
call_args = self.mock_api_service.post.call_args
|
|
209
|
+
self.assertEqual(call_args[1]['data']['model'], model)
|
|
210
|
+
self.assertEqual(call_args[1]['data']['input'], input_text)
|
|
211
|
+
|
|
212
|
+
def test_get_response_with_files(self):
|
|
213
|
+
import tempfile
|
|
214
|
+
import os
|
|
215
|
+
|
|
216
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
|
|
217
|
+
f.write("test content")
|
|
218
|
+
temp_file = f.name
|
|
219
|
+
|
|
220
|
+
try:
|
|
221
|
+
model = "openai/o1-pro"
|
|
222
|
+
input_text = "Analyze this file"
|
|
223
|
+
files = [temp_file]
|
|
224
|
+
expected_response = {"id": "resp_456", "status": "completed"}
|
|
225
|
+
mock_response = MagicMock()
|
|
226
|
+
mock_response.json.return_value = expected_response
|
|
227
|
+
mock_response.status_code = 200
|
|
228
|
+
self.mock_api_service.post_files_multipart.return_value = mock_response
|
|
229
|
+
|
|
230
|
+
result = self.chat_client.get_response(model=model, input=input_text, files=files)
|
|
231
|
+
|
|
232
|
+
self.assertEqual(result, expected_response)
|
|
233
|
+
self.mock_api_service.post_files_multipart.assert_called_once()
|
|
234
|
+
finally:
|
|
235
|
+
os.unlink(temp_file)
|
|
236
|
+
|
|
237
|
+
def test_get_response_with_tools(self):
|
|
238
|
+
model = "openai/o1-pro"
|
|
239
|
+
input_text = "What is the weather?"
|
|
240
|
+
tools = [{
|
|
241
|
+
"type": "function",
|
|
242
|
+
"name": "get_weather",
|
|
243
|
+
"description": "Get current temperature",
|
|
244
|
+
"parameters": {"type": "object", "properties": {"location": {"type": "string"}}}
|
|
245
|
+
}]
|
|
246
|
+
tool_choice = "auto"
|
|
247
|
+
expected_response = {"id": "resp_789", "status": "completed"}
|
|
248
|
+
mock_response = MagicMock()
|
|
249
|
+
mock_response.json.return_value = expected_response
|
|
250
|
+
mock_response.status_code = 200
|
|
251
|
+
self.mock_api_service.post.return_value = mock_response
|
|
252
|
+
|
|
253
|
+
result = self.chat_client.get_response(
|
|
254
|
+
model=model,
|
|
255
|
+
input=input_text,
|
|
256
|
+
tools=tools,
|
|
257
|
+
tool_choice=tool_choice
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
self.assertEqual(result, expected_response)
|
|
261
|
+
call_args = self.mock_api_service.post.call_args
|
|
262
|
+
self.assertEqual(call_args[1]['data']['tools'], tools)
|
|
263
|
+
self.assertEqual(call_args[1]['data']['tool_choice'], tool_choice)
|
|
264
|
+
|
|
265
|
+
def test_get_response_with_all_parameters(self):
|
|
266
|
+
model = "openai/o1-pro"
|
|
267
|
+
input_text = "Test input"
|
|
268
|
+
temperature = 0.7
|
|
269
|
+
max_output_tokens = 1000
|
|
270
|
+
top_p = 0.9
|
|
271
|
+
metadata = {"key": "value"}
|
|
272
|
+
user = "user-123"
|
|
273
|
+
instructions = "Be concise"
|
|
274
|
+
reasoning = {"effort": "medium"}
|
|
275
|
+
truncation = "disabled"
|
|
276
|
+
parallel_tool_calls = True
|
|
277
|
+
store = True
|
|
278
|
+
|
|
279
|
+
expected_response = {"id": "resp_all", "status": "completed"}
|
|
280
|
+
mock_response = MagicMock()
|
|
281
|
+
mock_response.json.return_value = expected_response
|
|
282
|
+
mock_response.status_code = 200
|
|
283
|
+
self.mock_api_service.post.return_value = mock_response
|
|
284
|
+
|
|
285
|
+
result = self.chat_client.get_response(
|
|
286
|
+
model=model,
|
|
287
|
+
input=input_text,
|
|
288
|
+
temperature=temperature,
|
|
289
|
+
max_output_tokens=max_output_tokens,
|
|
290
|
+
top_p=top_p,
|
|
291
|
+
metadata=metadata,
|
|
292
|
+
user=user,
|
|
293
|
+
instructions=instructions,
|
|
294
|
+
reasoning=reasoning,
|
|
295
|
+
truncation=truncation,
|
|
296
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
297
|
+
store=store
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
self.assertEqual(result, expected_response)
|
|
301
|
+
call_args = self.mock_api_service.post.call_args
|
|
302
|
+
data = call_args[1]['data']
|
|
303
|
+
self.assertEqual(data['temperature'], temperature)
|
|
304
|
+
self.assertEqual(data['max_output_tokens'], max_output_tokens)
|
|
305
|
+
self.assertEqual(data['top_p'], top_p)
|
|
306
|
+
self.assertEqual(data['metadata'], metadata)
|
|
307
|
+
self.assertEqual(data['user'], user)
|
|
308
|
+
self.assertEqual(data['instructions'], instructions)
|
|
309
|
+
self.assertEqual(data['reasoning'], reasoning)
|
|
310
|
+
self.assertEqual(data['truncation'], truncation)
|
|
311
|
+
self.assertEqual(data['parallel_tool_calls'], parallel_tool_calls)
|
|
312
|
+
self.assertEqual(data['store'], store)
|
|
313
|
+
|
|
314
|
+
def test_get_response_json_decode_error(self):
|
|
315
|
+
model = "openai/o1-pro"
|
|
316
|
+
input_text = "Test input"
|
|
317
|
+
mock_response = MagicMock()
|
|
318
|
+
mock_response.status_code = 200
|
|
319
|
+
mock_response.json.side_effect = json.JSONDecodeError("Invalid JSON", "", 0)
|
|
320
|
+
mock_response.text = "Raw response text"
|
|
321
|
+
self.mock_api_service.post.return_value = mock_response
|
|
322
|
+
|
|
323
|
+
with self.assertRaises(InvalidAPIResponseException) as context:
|
|
324
|
+
self.chat_client.get_response(model=model, input=input_text)
|
|
325
|
+
|
|
326
|
+
self.assertIn("Unable to get response", str(context.exception))
|
|
327
|
+
|
|
328
|
+
def test_get_response_file_not_found(self):
|
|
329
|
+
model = "openai/o1-pro"
|
|
330
|
+
input_text = "Analyze this file"
|
|
331
|
+
files = ["/nonexistent/file.pdf"]
|
|
332
|
+
|
|
333
|
+
with self.assertRaises(FileNotFoundError):
|
|
334
|
+
self.chat_client.get_response(model=model, input=input_text, files=files)
|
|
335
|
+
|
|
336
|
+
def test_get_response_streaming(self):
|
|
337
|
+
model = "openai/o1-pro"
|
|
338
|
+
input_text = "Tell me a story"
|
|
339
|
+
|
|
340
|
+
mock_stream = [
|
|
341
|
+
'data: {"choices":[{"delta":{"content":"Once"}}]}',
|
|
342
|
+
'data: {"choices":[{"delta":{"content":" upon"}}]}',
|
|
343
|
+
'data: {"choices":[{"delta":{"content":" a time"}}]}',
|
|
344
|
+
'data: [DONE]'
|
|
345
|
+
]
|
|
346
|
+
|
|
347
|
+
self.mock_api_service.stream_post.return_value = iter(mock_stream)
|
|
348
|
+
|
|
349
|
+
result = self.chat_client.get_response(model=model, input=input_text, stream=True)
|
|
350
|
+
|
|
351
|
+
chunks = list(result)
|
|
352
|
+
self.assertEqual(chunks, ["Once", " upon", " a time"])
|
|
353
|
+
self.mock_api_service.stream_post.assert_called_once()
|
|
354
|
+
|
|
355
|
+
def test_get_response_streaming_with_files_raises_error(self):
|
|
356
|
+
import tempfile
|
|
357
|
+
|
|
358
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
|
|
359
|
+
f.write("test content")
|
|
360
|
+
temp_file = f.name
|
|
361
|
+
|
|
362
|
+
try:
|
|
363
|
+
model = "openai/o1-pro"
|
|
364
|
+
input_text = "Analyze this file"
|
|
365
|
+
files = [temp_file]
|
|
366
|
+
|
|
367
|
+
with self.assertRaises(InvalidAPIResponseException) as context:
|
|
368
|
+
self.chat_client.get_response(model=model, input=input_text, files=files, stream=True)
|
|
369
|
+
|
|
370
|
+
self.assertIn("Streaming is not supported when uploading files", str(context.exception))
|
|
371
|
+
finally:
|
|
372
|
+
import os
|
|
373
|
+
os.unlink(temp_file)
|
|
374
|
+
|
|
375
|
+
def test_stream_response_generator_success(self):
|
|
376
|
+
mock_stream = [
|
|
377
|
+
'data: {"choices":[{"delta":{"content":"Hello"}}]}',
|
|
378
|
+
'data: {"choices":[{"delta":{"content":" world"}}]}',
|
|
379
|
+
'data: [DONE]'
|
|
380
|
+
]
|
|
381
|
+
|
|
382
|
+
result = list(self.chat_client.stream_response_generator(iter(mock_stream)))
|
|
383
|
+
|
|
384
|
+
self.assertEqual(result, ["Hello", " world"])
|
|
385
|
+
|
|
386
|
+
def test_stream_response_generator_exception(self):
|
|
387
|
+
mock_response = MagicMock()
|
|
388
|
+
mock_response.__iter__.side_effect = Exception("Streaming error")
|
|
389
|
+
|
|
390
|
+
with self.assertRaises(InvalidAPIResponseException) as context:
|
|
391
|
+
list(self.chat_client.stream_response_generator(mock_response))
|
|
392
|
+
|
|
393
|
+
self.assertIn("Unable to process streaming response", str(context.exception))
|
|
@@ -13,7 +13,21 @@ class TestEmbeddingsCommands(unittest.TestCase):
|
|
|
13
13
|
def setUp(self):
|
|
14
14
|
self.mock_console = MagicMock()
|
|
15
15
|
self.mock_client = MagicMock()
|
|
16
|
-
self.mock_client.generate_embeddings.return_value = {
|
|
16
|
+
self.mock_client.generate_embeddings.return_value = {
|
|
17
|
+
"model": "test-model",
|
|
18
|
+
"object": "list",
|
|
19
|
+
"data": [
|
|
20
|
+
{
|
|
21
|
+
"object": "embedding",
|
|
22
|
+
"index": 0,
|
|
23
|
+
"embedding": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"usage": {
|
|
27
|
+
"prompt_tokens": 10,
|
|
28
|
+
"total_tokens": 10
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
self.option_list_with_all_params = [
|
|
18
32
|
(Option("model", ["--model"], "", True), "test-model"),
|
|
19
33
|
(Option("input", ["--input"], "", True), "input1"),
|
|
@@ -42,13 +56,13 @@ class TestEmbeddingsCommands(unittest.TestCase):
|
|
|
42
56
|
input_list=["input1", "input2"],
|
|
43
57
|
model="test-model",
|
|
44
58
|
encoding_format="float",
|
|
45
|
-
dimensions=
|
|
59
|
+
dimensions=512,
|
|
46
60
|
user="user123",
|
|
47
61
|
input_type="text",
|
|
48
|
-
timeout=
|
|
62
|
+
timeout=30,
|
|
49
63
|
cache=True
|
|
50
64
|
)
|
|
51
|
-
mock_write_stdout.
|
|
65
|
+
mock_write_stdout.assert_called_once()
|
|
52
66
|
|
|
53
67
|
@patch('pygeai.cli.commands.embeddings.Console.write_stdout')
|
|
54
68
|
@patch('pygeai.cli.commands.embeddings.EmbeddingsClient')
|
|
@@ -68,7 +82,7 @@ class TestEmbeddingsCommands(unittest.TestCase):
|
|
|
68
82
|
timeout=None,
|
|
69
83
|
cache=None
|
|
70
84
|
)
|
|
71
|
-
mock_write_stdout.
|
|
85
|
+
mock_write_stdout.assert_called_once()
|
|
72
86
|
|
|
73
87
|
def test_generate_embeddings_missing_model(self):
|
|
74
88
|
option_list_no_model = [
|
|
@@ -96,14 +110,23 @@ class TestEmbeddingsCommands(unittest.TestCase):
|
|
|
96
110
|
with self.assertRaises(WrongArgumentError):
|
|
97
111
|
generate_embeddings(option_list_invalid_cache)
|
|
98
112
|
|
|
99
|
-
def
|
|
100
|
-
|
|
113
|
+
def test_generate_embeddings_invalid_dimensions(self):
|
|
114
|
+
option_list_invalid_dimensions = [
|
|
101
115
|
(Option("model", ["--model"], "", True), "test-model"),
|
|
102
116
|
(Option("input", ["--input"], "", True), "input1"),
|
|
103
|
-
(Option("
|
|
117
|
+
(Option("dimensions", ["--dimensions"], "", True), "invalid")
|
|
104
118
|
]
|
|
105
119
|
|
|
106
120
|
with self.assertRaises(WrongArgumentError):
|
|
107
|
-
generate_embeddings(
|
|
121
|
+
generate_embeddings(option_list_invalid_dimensions)
|
|
108
122
|
|
|
123
|
+
def test_generate_embeddings_invalid_timeout(self):
|
|
124
|
+
option_list_invalid_timeout = [
|
|
125
|
+
(Option("model", ["--model"], "", True), "test-model"),
|
|
126
|
+
(Option("input", ["--input"], "", True), "input1"),
|
|
127
|
+
(Option("timeout", ["--timeout"], "", True), "invalid")
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
with self.assertRaises(WrongArgumentError):
|
|
131
|
+
generate_embeddings(option_list_invalid_timeout)
|
|
109
132
|
|
|
@@ -49,6 +49,13 @@ class TestEvaluationCommands(unittest.TestCase):
|
|
|
49
49
|
python -m unittest pygeai.tests.cli.commands.test_evaluation.TestEvaluationCommands
|
|
50
50
|
"""
|
|
51
51
|
|
|
52
|
+
def setUp(self):
|
|
53
|
+
self.eval_client_patcher = patch('pygeai.evaluation.clients.EvaluationClient.__init__', return_value=None)
|
|
54
|
+
self.mock_eval_client_init = self.eval_client_patcher.start()
|
|
55
|
+
|
|
56
|
+
def tearDown(self):
|
|
57
|
+
self.eval_client_patcher.stop()
|
|
58
|
+
|
|
52
59
|
def test_show_help(self):
|
|
53
60
|
with patch('pygeai.core.utils.console.Console.write_stdout') as mock_stdout:
|
|
54
61
|
show_help()
|