pygeai 0.6.0b13__py3-none-any.whl → 0.6.1__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.
Files changed (217) hide show
  1. pygeai/__init__.py +1 -2
  2. pygeai/_docs/source/content/api_reference/project.rst +392 -0
  3. pygeai/_docs/source/content/authentication.rst +130 -1
  4. pygeai/_docs/source/content/debugger.rst +327 -157
  5. pygeai/_docs/source/content/migration.rst +391 -7
  6. pygeai/_docs/source/pygeai.core.common.rst +8 -0
  7. pygeai/_docs/source/pygeai.tests.auth.rst +56 -0
  8. pygeai/_docs/source/pygeai.tests.cli.rst +8 -0
  9. pygeai/admin/clients.py +1 -3
  10. pygeai/analytics/clients.py +1 -1
  11. pygeai/assistant/clients.py +2 -7
  12. pygeai/assistant/data/clients.py +0 -8
  13. pygeai/assistant/data_analyst/clients.py +0 -2
  14. pygeai/assistant/managers.py +1 -1
  15. pygeai/assistant/rag/clients.py +0 -2
  16. pygeai/assistant/rag/mappers.py +9 -11
  17. pygeai/auth/clients.py +26 -7
  18. pygeai/auth/endpoints.py +2 -1
  19. pygeai/chat/clients.py +2 -2
  20. pygeai/chat/managers.py +1 -1
  21. pygeai/cli/commands/admin.py +13 -25
  22. pygeai/cli/commands/analytics.py +56 -88
  23. pygeai/cli/commands/assistant.py +84 -138
  24. pygeai/cli/commands/auth.py +23 -46
  25. pygeai/cli/commands/base.py +0 -1
  26. pygeai/cli/commands/chat.py +218 -209
  27. pygeai/cli/commands/common.py +5 -5
  28. pygeai/cli/commands/configuration.py +79 -29
  29. pygeai/cli/commands/docs.py +3 -4
  30. pygeai/cli/commands/embeddings.py +13 -19
  31. pygeai/cli/commands/evaluation.py +133 -344
  32. pygeai/cli/commands/feedback.py +7 -15
  33. pygeai/cli/commands/files.py +26 -53
  34. pygeai/cli/commands/gam.py +28 -69
  35. pygeai/cli/commands/lab/ai_lab.py +96 -142
  36. pygeai/cli/commands/lab/common.py +1 -1
  37. pygeai/cli/commands/lab/spec.py +12 -32
  38. pygeai/cli/commands/llm.py +9 -18
  39. pygeai/cli/commands/migrate.py +43 -99
  40. pygeai/cli/commands/organization.py +223 -196
  41. pygeai/cli/commands/rag.py +35 -58
  42. pygeai/cli/commands/rerank.py +21 -25
  43. pygeai/cli/commands/secrets.py +39 -67
  44. pygeai/cli/commands/usage_limits.py +50 -136
  45. pygeai/cli/commands/validators.py +1 -1
  46. pygeai/cli/geai.py +32 -3
  47. pygeai/cli/geai_proxy.py +6 -2
  48. pygeai/cli/install_man.py +1 -1
  49. pygeai/cli/parsers.py +1 -1
  50. pygeai/core/base/clients.py +90 -21
  51. pygeai/core/base/mappers.py +39 -55
  52. pygeai/core/base/session.py +134 -22
  53. pygeai/core/common/config.py +50 -13
  54. pygeai/core/common/constants.py +8 -0
  55. pygeai/core/common/exceptions.py +6 -0
  56. pygeai/core/embeddings/clients.py +0 -1
  57. pygeai/core/embeddings/managers.py +0 -1
  58. pygeai/core/feedback/clients.py +0 -2
  59. pygeai/core/feedback/models.py +1 -1
  60. pygeai/core/files/clients.py +0 -3
  61. pygeai/core/files/managers.py +1 -1
  62. pygeai/core/files/mappers.py +4 -5
  63. pygeai/core/llm/clients.py +0 -1
  64. pygeai/core/models.py +4 -4
  65. pygeai/core/plugins/clients.py +0 -3
  66. pygeai/core/plugins/models.py +2 -2
  67. pygeai/core/rerank/clients.py +0 -2
  68. pygeai/core/secrets/clients.py +0 -2
  69. pygeai/core/services/rest.py +80 -14
  70. pygeai/core/singleton.py +24 -0
  71. pygeai/dbg/__init__.py +2 -2
  72. pygeai/dbg/debugger.py +276 -38
  73. pygeai/evaluation/clients.py +2 -4
  74. pygeai/evaluation/dataset/clients.py +0 -1
  75. pygeai/evaluation/plan/clients.py +0 -2
  76. pygeai/evaluation/result/clients.py +0 -2
  77. pygeai/gam/clients.py +1 -3
  78. pygeai/health/clients.py +1 -3
  79. pygeai/lab/clients.py +0 -1
  80. pygeai/lab/managers.py +0 -1
  81. pygeai/lab/models.py +0 -1
  82. pygeai/lab/strategies/clients.py +1 -2
  83. pygeai/lab/tools/clients.py +2 -2
  84. pygeai/lab/tools/mappers.py +1 -1
  85. pygeai/migration/strategies.py +5 -6
  86. pygeai/migration/tools.py +1 -1
  87. pygeai/organization/clients.py +118 -12
  88. pygeai/organization/endpoints.py +1 -0
  89. pygeai/organization/limits/clients.py +4 -6
  90. pygeai/organization/limits/managers.py +1 -4
  91. pygeai/organization/managers.py +2 -2
  92. pygeai/proxy/config.py +1 -0
  93. pygeai/proxy/managers.py +6 -5
  94. pygeai/tests/admin/test_clients.py +11 -11
  95. pygeai/tests/assistants/rag/test_clients.py +1 -1
  96. pygeai/tests/assistants/rag/test_models.py +1 -2
  97. pygeai/tests/assistants/test_clients.py +1 -1
  98. pygeai/tests/assistants/test_managers.py +1 -3
  99. pygeai/tests/auth/test_cli_configuration.py +252 -0
  100. pygeai/tests/auth/test_client_initialization.py +411 -0
  101. pygeai/tests/auth/test_clients.py +29 -27
  102. pygeai/tests/auth/test_config_manager.py +305 -0
  103. pygeai/tests/auth/test_header_injection.py +294 -0
  104. pygeai/tests/auth/test_oauth.py +3 -1
  105. pygeai/tests/auth/test_session_logging.py +119 -0
  106. pygeai/tests/auth/test_session_validation.py +408 -0
  107. pygeai/tests/auth/test_singleton_reset.py +201 -0
  108. pygeai/tests/chat/test_clients.py +1 -1
  109. pygeai/tests/chat/test_iris.py +1 -1
  110. pygeai/tests/chat/test_ui.py +0 -2
  111. pygeai/tests/cli/commands/lab/test_ai_lab.py +1 -3
  112. pygeai/tests/cli/commands/lab/test_common.py +0 -1
  113. pygeai/tests/cli/commands/test_chat.py +1 -1
  114. pygeai/tests/cli/commands/test_common.py +0 -1
  115. pygeai/tests/cli/commands/test_embeddings.py +2 -2
  116. pygeai/tests/cli/commands/test_evaluation.py +1 -9
  117. pygeai/tests/cli/commands/test_llm.py +1 -1
  118. pygeai/tests/cli/commands/test_migrate.py +1 -1
  119. pygeai/tests/cli/commands/test_rerank.py +0 -1
  120. pygeai/tests/cli/commands/test_secrets.py +1 -1
  121. pygeai/tests/cli/commands/test_show_help.py +0 -1
  122. pygeai/tests/cli/commands/test_validators.py +0 -1
  123. pygeai/tests/cli/test_credentials_flag.py +312 -0
  124. pygeai/tests/cli/test_error_handler.py +0 -1
  125. pygeai/tests/core/base/test_mappers.py +2 -2
  126. pygeai/tests/core/base/test_models.py +4 -4
  127. pygeai/tests/core/common/test_config.py +2 -7
  128. pygeai/tests/core/common/test_decorators.py +0 -1
  129. pygeai/tests/core/embeddings/test_managers.py +1 -1
  130. pygeai/tests/core/feedback/test_clients.py +2 -2
  131. pygeai/tests/core/files/test_clients.py +6 -6
  132. pygeai/tests/core/files/test_models.py +0 -1
  133. pygeai/tests/core/files/test_responses.py +0 -1
  134. pygeai/tests/core/llm/test_clients.py +1 -1
  135. pygeai/tests/core/plugins/test_clients.py +4 -4
  136. pygeai/tests/core/rerank/test_mappers.py +1 -3
  137. pygeai/tests/core/secrets/test_clients.py +2 -3
  138. pygeai/tests/core/services/test_rest.py +10 -10
  139. pygeai/tests/core/utils/test_console.py +0 -1
  140. pygeai/tests/dbg/test_debugger.py +95 -8
  141. pygeai/tests/evaluation/dataset/test_clients.py +24 -27
  142. pygeai/tests/evaluation/plan/test_clients.py +16 -18
  143. pygeai/tests/evaluation/result/test_clients.py +4 -5
  144. pygeai/tests/health/test_clients.py +2 -2
  145. pygeai/tests/integration/lab/agents/test_create_agent.py +1 -3
  146. pygeai/tests/integration/lab/agents/test_get_agent.py +1 -1
  147. pygeai/tests/integration/lab/processes/test_create_process.py +2 -2
  148. pygeai/tests/integration/lab/processes/test_create_task.py +2 -3
  149. pygeai/tests/integration/lab/processes/test_delete_process.py +0 -1
  150. pygeai/tests/integration/lab/processes/test_get_process.py +2 -4
  151. pygeai/tests/integration/lab/processes/test_list_process_instances.py +1 -3
  152. pygeai/tests/integration/lab/processes/test_update_process.py +3 -9
  153. pygeai/tests/integration/lab/reasoning_strategies/test_update_reasoning_strategy.py +1 -2
  154. pygeai/tests/integration/lab/tools/test_delete_tool.py +1 -1
  155. pygeai/tests/integration/lab/tools/test_list_tools.py +1 -1
  156. pygeai/tests/integration/lab/tools/test_update_tool.py +1 -1
  157. pygeai/tests/lab/agents/test_clients.py +17 -17
  158. pygeai/tests/lab/processes/test_clients.py +67 -67
  159. pygeai/tests/lab/processes/test_mappers.py +23 -23
  160. pygeai/tests/lab/spec/test_loader.py +0 -2
  161. pygeai/tests/lab/spec/test_parsers.py +1 -2
  162. pygeai/tests/lab/strategies/test_clients.py +10 -10
  163. pygeai/tests/lab/test_managers.py +3 -5
  164. pygeai/tests/lab/test_mappers.py +1 -4
  165. pygeai/tests/lab/tools/test_clients.py +21 -21
  166. pygeai/tests/lab/tools/test_mappers.py +0 -1
  167. pygeai/tests/organization/limits/test_clients.py +33 -33
  168. pygeai/tests/organization/limits/test_managers.py +7 -7
  169. pygeai/tests/organization/test_clients.py +78 -60
  170. pygeai/tests/proxy/test_clients.py +1 -1
  171. pygeai/tests/proxy/test_integration.py +1 -4
  172. pygeai/tests/proxy/test_managers.py +1 -2
  173. pygeai/tests/proxy/test_servers.py +1 -2
  174. pygeai/tests/snippets/assistants/rag/delete_rag_assistant.py +0 -1
  175. pygeai/tests/snippets/assistants/rag/get_documents.py +0 -1
  176. pygeai/tests/snippets/assistants/rag/get_rag_assistant_data.py +0 -1
  177. pygeai/tests/snippets/chat/get_request_status.py +0 -1
  178. pygeai/tests/snippets/dbg/file_debugging.py +72 -0
  179. pygeai/tests/snippets/dbg/module_debugging.py +60 -0
  180. pygeai/tests/snippets/embeddings/cohere_example.py +2 -2
  181. pygeai/tests/snippets/embeddings/openai_base64_example.py +1 -1
  182. pygeai/tests/snippets/evaluation/dataset/complete_workflow_example.py +8 -8
  183. pygeai/tests/snippets/evaluation/plan/complete_workflow_example.py +5 -5
  184. pygeai/tests/snippets/evaluation/result/complete_workflow_example.py +3 -3
  185. pygeai/tests/snippets/lab/agentic_flow_example_1.py +1 -1
  186. pygeai/tests/snippets/lab/agentic_flow_example_2.py +3 -4
  187. pygeai/tests/snippets/lab/agents/create_agent_with_permissions.py +2 -2
  188. pygeai/tests/snippets/lab/agents/delete_agent.py +1 -2
  189. pygeai/tests/snippets/lab/agents/get_agent.py +1 -1
  190. pygeai/tests/snippets/lab/agents/get_agent_with_new_fields.py +10 -10
  191. pygeai/tests/snippets/lab/agents/get_sharing_link.py +0 -1
  192. pygeai/tests/snippets/lab/agents/list_agents.py +1 -1
  193. pygeai/tests/snippets/lab/agents/publish_agent_revision.py +0 -1
  194. pygeai/tests/snippets/lab/agents/update_agent_properties.py +1 -1
  195. pygeai/tests/snippets/lab/crud_ui.py +3 -5
  196. pygeai/tests/snippets/lab/processes/kbs/get_kb.py +0 -1
  197. pygeai/tests/snippets/lab/processes/kbs/list_kbs.py +0 -1
  198. pygeai/tests/snippets/lab/processes/list_processes.py +1 -1
  199. pygeai/tests/snippets/lab/samples/summarize_files.py +0 -3
  200. pygeai/tests/snippets/lab/strategies/get_reasoning_strategy.py +0 -1
  201. pygeai/tests/snippets/lab/strategies/list_reasoning_strategies.py +1 -1
  202. pygeai/tests/snippets/lab/tools/get_tool.py +1 -1
  203. pygeai/tests/snippets/lab/tools/publish_tool_revision.py +0 -1
  204. pygeai/tests/snippets/lab/tools/set_parameters.py +1 -2
  205. pygeai/tests/snippets/lab/use_cases/c_code_fixer_agent_flow.py +2 -3
  206. pygeai/tests/snippets/lab/use_cases/file_summarizer_example_2.py +1 -1
  207. pygeai/tests/snippets/lab/use_cases/update_cli_expert.py +0 -1
  208. pygeai/tests/snippets/lab/use_cases/update_lab_expert.py +0 -1
  209. pygeai/tests/snippets/lab/use_cases/update_web_designer.py +0 -1
  210. pygeai/tests/snippets/lab/use_cases/update_web_reader.py +0 -1
  211. pygeai/tests/snippets/migrate/orchestrator_examples.py +1 -1
  212. {pygeai-0.6.0b13.dist-info → pygeai-0.6.1.dist-info}/METADATA +32 -7
  213. {pygeai-0.6.0b13.dist-info → pygeai-0.6.1.dist-info}/RECORD +217 -206
  214. {pygeai-0.6.0b13.dist-info → pygeai-0.6.1.dist-info}/WHEEL +0 -0
  215. {pygeai-0.6.0b13.dist-info → pygeai-0.6.1.dist-info}/entry_points.txt +0 -0
  216. {pygeai-0.6.0b13.dist-info → pygeai-0.6.1.dist-info}/licenses/LICENSE +0 -0
  217. {pygeai-0.6.0b13.dist-info → pygeai-0.6.1.dist-info}/top_level.txt +0 -0
pygeai/auth/clients.py CHANGED
@@ -2,7 +2,6 @@ from pygeai import logger
2
2
  from pygeai.auth.endpoints import GET_USER_PROFILE_INFO, GET_OAUTH2_ACCESS_TOKEN, \
3
3
  CREATE_PROJECT_API_TOKEN_V2, DELETE_PROJECT_API_TOKEN_V2, UPDATE_PROJECT_API_TOKEN_V2, GET_PROJECT_API_TOKEN_V2
4
4
  from pygeai.core.base.clients import BaseClient
5
- from pygeai.core.common.exceptions import InvalidAPIResponseException, APIResponseError
6
5
  from pygeai.core.utils.validators import validate_status_code
7
6
  from pygeai.core.utils.parsers import parse_json_response
8
7
 
@@ -37,15 +36,35 @@ class AuthClient(BaseClient):
37
36
  validate_status_code(response)
38
37
  return parse_json_response(response, "obtain Oauth2 access token")
39
38
 
40
- def get_user_profile_information(self, access_token: str) -> dict:
39
+ def get_user_profile_information(self, access_token: str, project_id: str = None) -> dict:
41
40
  """
42
- Get user profile information
43
-
44
- :param access_token: str - Token obtained in the POST to /oauth/access_token
41
+ Get user profile information using an OAuth access token.
42
+
43
+ This method creates a temporary API service to avoid mutating the session state.
44
+
45
+ :param access_token: str - OAuth 2.0 access token
46
+ :param project_id: str - Project ID for OAuth context (optional, uses session project_id if available)
45
47
  :return: dict - The API response containing the user profile information
48
+ :raises: MissingRequirementException - If project_id is not provided and not in session
46
49
  """
47
- self.api_service.token = access_token
48
- response = self.api_service.get(endpoint=GET_USER_PROFILE_INFO)
50
+ # Determine project_id to use
51
+ effective_project_id = project_id or self.session.project_id
52
+
53
+ if not effective_project_id:
54
+ logger.warning(
55
+ "No project_id provided for get_user_profile_information. "
56
+ "This may cause authentication issues."
57
+ )
58
+
59
+ # Create a temporary API service without mutating session
60
+ from pygeai.core.services.rest import GEAIApiService
61
+ temp_service = GEAIApiService(
62
+ base_url=self.session.base_url,
63
+ token=access_token,
64
+ project_id=effective_project_id
65
+ )
66
+
67
+ response = temp_service.get(endpoint=GET_USER_PROFILE_INFO)
49
68
  validate_status_code(response)
50
69
  return parse_json_response(response, "retrieve user profile information")
51
70
 
pygeai/auth/endpoints.py CHANGED
@@ -1,4 +1,5 @@
1
- GET_OAUTH2_ACCESS_TOKEN = "/oauth/access_token" # POST -> Obtain an OAuth 2.0 access token
1
+ # GET_OAUTH2_ACCESS_TOKEN = "/oauth/access_token" # POST -> Obtain an OAuth 2.0 access token
2
+ GET_OAUTH2_ACCESS_TOKEN = "/oauth/gam/v2.0/access_token" # POST -> Obtain an OAuth 2.0 access token
2
3
  GET_USER_PROFILE_INFO = "/openid/userinfo" # GET -> Retrieve user profile information
3
4
  CREATE_PROJECT_API_TOKEN_V2 = "v2/projects/tokens" # POST -> Create a new API token for a project
4
5
  DELETE_PROJECT_API_TOKEN_V2 = "v2/projects/tokens/{id}" # DELETE -> Revoke an API token
pygeai/chat/clients.py CHANGED
@@ -197,7 +197,7 @@ class ChatClient(BaseClient):
197
197
  ):
198
198
  content = json_data["choices"][0]["delta"]["content"]
199
199
  yield content
200
- except JSONDecodeError as e:
200
+ except JSONDecodeError:
201
201
  continue
202
202
  except Exception as e:
203
203
  raise InvalidAPIResponseException(f"Unable to process streaming chat response: {e}")
@@ -225,7 +225,7 @@ class ChatClient(BaseClient):
225
225
  ):
226
226
  content = json_data["choices"][0]["delta"]["content"]
227
227
  yield content
228
- except JSONDecodeError as e:
228
+ except JSONDecodeError:
229
229
  continue
230
230
  except Exception as e:
231
231
  raise InvalidAPIResponseException(f"Unable to process streaming response: {e}")
pygeai/chat/managers.py CHANGED
@@ -5,7 +5,7 @@ from pygeai.core.models import ChatMessageList, \
5
5
  ChatVariableList, LlmSettings, ChatToolList, ToolChoice
6
6
  from pygeai.assistant.mappers import AssistantResponseMapper
7
7
  from pygeai.chat.clients import ChatClient
8
- from pygeai.core.responses import ChatResponse, ProviderResponse
8
+ from pygeai.core.responses import ProviderResponse
9
9
 
10
10
 
11
11
  class ChatManager:
@@ -2,7 +2,7 @@ from pygeai.admin.clients import AdminClient
2
2
  from pygeai.cli.commands import Command, Option, ArgumentsEnum
3
3
  from pygeai.cli.commands.builders import build_help_text
4
4
  from pygeai.cli.texts.help import ADMIN_HELP_TEXT
5
- from pygeai.core.common.exceptions import MissingRequirementException, WrongArgumentError
5
+ from pygeai.core.common.exceptions import MissingRequirementException
6
6
  from pygeai.core.utils.console import Console
7
7
 
8
8
 
@@ -27,10 +27,8 @@ def get_authorized_organizations():
27
27
 
28
28
 
29
29
  def get_authorized_projects_by_organization(option_list: list):
30
- organization = None
31
- for option_flag, option_arg in option_list:
32
- if option_flag.name == "organization":
33
- organization = option_arg
30
+ opts = {opt.name: arg for opt, arg in option_list}
31
+ organization = opts.get('organization')
34
32
 
35
33
  if not organization:
36
34
  raise MissingRequirementException("Cannot get authorized projects within organization without organization id")
@@ -53,16 +51,11 @@ authorized_projects_by_organization_options = [
53
51
 
54
52
 
55
53
  def get_project_visibility(option_list: list):
56
- organization = None
57
- project = None
58
- access_token = None
59
- for option_flag, option_arg in option_list:
60
- if option_flag.name == "organization":
61
- organization = option_arg
62
- if option_flag.name == "project":
63
- project = option_arg
64
- if option_flag.name == "access_token":
65
- access_token = option_arg
54
+ opts = {opt.name: arg for opt, arg in option_list}
55
+
56
+ organization = opts.get('organization')
57
+ project = opts.get('project')
58
+ access_token = opts.get('access_token')
66
59
 
67
60
  if not (organization and project and access_token):
68
61
  raise MissingRequirementException("Cannot get project visibility for access token without specifying "
@@ -100,16 +93,11 @@ project_visibility_options = [
100
93
 
101
94
 
102
95
  def get_project_api_token(option_list: list):
103
- organization = None
104
- project = None
105
- access_token = None
106
- for option_flag, option_arg in option_list:
107
- if option_flag.name == "organization":
108
- organization = option_arg
109
- if option_flag.name == "project":
110
- project = option_arg
111
- if option_flag.name == "access_token":
112
- access_token = option_arg
96
+ opts = {opt.name: arg for opt, arg in option_list}
97
+
98
+ organization = opts.get('organization')
99
+ project = opts.get('project')
100
+ access_token = opts.get('access_token')
113
101
 
114
102
  if not (organization and project and access_token):
115
103
  raise MissingRequirementException("Cannot get project API Token without specifying "
@@ -1,7 +1,7 @@
1
1
  from pygeai.cli.commands import Command, Option, ArgumentsEnum
2
2
  from pygeai.cli.commands.builders import build_help_text
3
3
  from pygeai.cli.texts.help import ANALYTICS_HELP_TEXT
4
- from pygeai.core.common.exceptions import MissingRequirementException
4
+
5
5
  from pygeai.core.utils.console import Console
6
6
  from pygeai.analytics.managers import AnalyticsManager
7
7
  import csv
@@ -55,16 +55,13 @@ CSV_EXPORT_OPTION = Option(
55
55
 
56
56
 
57
57
  def get_agents_created_and_modified(option_list: list):
58
- start_date = None
59
- end_date = None
60
- for option_flag, option_arg in option_list:
61
- if option_flag.name == "start_date":
62
- start_date = option_arg
63
- if option_flag.name == "end_date":
64
- end_date = option_arg
58
+ opts = {opt.name: arg for opt, arg in option_list}
59
+ start_date = opts.get("start_date")
60
+ end_date = opts.get("end_date")
65
61
 
66
- if not (start_date and end_date):
67
- raise MissingRequirementException("Cannot retrieve agents created and modified without start-date and end-date")
62
+ if not start_date or not end_date:
63
+ start_date, end_date = get_default_date_range()
64
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
68
65
 
69
66
  manager = AnalyticsManager()
70
67
  result = manager.get_agents_created_and_modified(start_date, end_date)
@@ -75,23 +72,18 @@ agents_created_options = [START_DATE_OPTION, END_DATE_OPTION]
75
72
 
76
73
 
77
74
  def get_total_requests_per_day(option_list: list):
78
- start_date = None
79
- end_date = None
80
- agent_name = None
81
- for option_flag, option_arg in option_list:
82
- if option_flag.name == "start_date":
83
- start_date = option_arg
84
- if option_flag.name == "end_date":
85
- end_date = option_arg
86
- if option_flag.name == "agent_name":
87
- agent_name = option_arg
88
-
89
- if not (start_date and end_date):
90
- raise MissingRequirementException("Cannot retrieve total requests per day without start-date and end-date")
75
+ opts = {opt.name: arg for opt, arg in option_list}
76
+ start_date = opts.get("start_date")
77
+ end_date = opts.get("end_date")
78
+ agent_name = opts.get("agent_name")
79
+
80
+ if not start_date or not end_date:
81
+ start_date, end_date = get_default_date_range()
82
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
91
83
 
92
84
  manager = AnalyticsManager()
93
85
  result = manager.get_total_requests_per_day(start_date, end_date, agent_name)
94
- Console.write_stdout(f"Total requests per day:")
86
+ Console.write_stdout("Total requests per day:")
95
87
  for item in result.requestsPerDay:
96
88
  Console.write_stdout(f" {item.date}: {item.totalRequests} requests ({item.totalRequestsWithError} errors)")
97
89
 
@@ -100,16 +92,13 @@ total_requests_per_day_options = [START_DATE_OPTION, END_DATE_OPTION, AGENT_NAME
100
92
 
101
93
 
102
94
  def get_total_cost(option_list: list):
103
- start_date = None
104
- end_date = None
105
- for option_flag, option_arg in option_list:
106
- if option_flag.name == "start_date":
107
- start_date = option_arg
108
- if option_flag.name == "end_date":
109
- end_date = option_arg
95
+ opts = {opt.name: arg for opt, arg in option_list}
96
+ start_date = opts.get("start_date")
97
+ end_date = opts.get("end_date")
110
98
 
111
- if not (start_date and end_date):
112
- raise MissingRequirementException("Cannot retrieve total cost without start-date and end-date")
99
+ if not start_date or not end_date:
100
+ start_date, end_date = get_default_date_range()
101
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
113
102
 
114
103
  manager = AnalyticsManager()
115
104
  result = manager.get_total_cost(start_date, end_date)
@@ -120,16 +109,13 @@ total_cost_options = [START_DATE_OPTION, END_DATE_OPTION]
120
109
 
121
110
 
122
111
  def get_average_cost_per_request(option_list: list):
123
- start_date = None
124
- end_date = None
125
- for option_flag, option_arg in option_list:
126
- if option_flag.name == "start_date":
127
- start_date = option_arg
128
- if option_flag.name == "end_date":
129
- end_date = option_arg
112
+ opts = {opt.name: arg for opt, arg in option_list}
113
+ start_date = opts.get("start_date")
114
+ end_date = opts.get("end_date")
130
115
 
131
- if not (start_date and end_date):
132
- raise MissingRequirementException("Cannot retrieve average cost per request without start-date and end-date")
116
+ if not start_date or not end_date:
117
+ start_date, end_date = get_default_date_range()
118
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
133
119
 
134
120
  manager = AnalyticsManager()
135
121
  result = manager.get_average_cost_per_request(start_date, end_date)
@@ -140,16 +126,13 @@ average_cost_per_request_options = [START_DATE_OPTION, END_DATE_OPTION]
140
126
 
141
127
 
142
128
  def get_total_tokens(option_list: list):
143
- start_date = None
144
- end_date = None
145
- for option_flag, option_arg in option_list:
146
- if option_flag.name == "start_date":
147
- start_date = option_arg
148
- if option_flag.name == "end_date":
149
- end_date = option_arg
129
+ opts = {opt.name: arg for opt, arg in option_list}
130
+ start_date = opts.get("start_date")
131
+ end_date = opts.get("end_date")
150
132
 
151
- if not (start_date and end_date):
152
- raise MissingRequirementException("Cannot retrieve total tokens without start-date and end-date")
133
+ if not start_date or not end_date:
134
+ start_date, end_date = get_default_date_range()
135
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
153
136
 
154
137
  manager = AnalyticsManager()
155
138
  result = manager.get_total_tokens(start_date, end_date)
@@ -160,16 +143,13 @@ total_tokens_options = [START_DATE_OPTION, END_DATE_OPTION]
160
143
 
161
144
 
162
145
  def get_overall_error_rate(option_list: list):
163
- start_date = None
164
- end_date = None
165
- for option_flag, option_arg in option_list:
166
- if option_flag.name == "start_date":
167
- start_date = option_arg
168
- if option_flag.name == "end_date":
169
- end_date = option_arg
146
+ opts = {opt.name: arg for opt, arg in option_list}
147
+ start_date = opts.get("start_date")
148
+ end_date = opts.get("end_date")
170
149
 
171
- if not (start_date and end_date):
172
- raise MissingRequirementException("Cannot retrieve overall error rate without start-date and end-date")
150
+ if not start_date or not end_date:
151
+ start_date, end_date = get_default_date_range()
152
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
173
153
 
174
154
  manager = AnalyticsManager()
175
155
  result = manager.get_overall_error_rate(start_date, end_date)
@@ -180,16 +160,13 @@ error_rate_options = [START_DATE_OPTION, END_DATE_OPTION]
180
160
 
181
161
 
182
162
  def get_top_agents_by_requests(option_list: list):
183
- start_date = None
184
- end_date = None
185
- for option_flag, option_arg in option_list:
186
- if option_flag.name == "start_date":
187
- start_date = option_arg
188
- if option_flag.name == "end_date":
189
- end_date = option_arg
163
+ opts = {opt.name: arg for opt, arg in option_list}
164
+ start_date = opts.get("start_date")
165
+ end_date = opts.get("end_date")
190
166
 
191
- if not (start_date and end_date):
192
- raise MissingRequirementException("Cannot retrieve top agents by requests without start-date and end-date")
167
+ if not start_date or not end_date:
168
+ start_date, end_date = get_default_date_range()
169
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
193
170
 
194
171
  manager = AnalyticsManager()
195
172
  result = manager.get_top_10_agents_by_requests(start_date, end_date)
@@ -202,16 +179,13 @@ top_agents_options = [START_DATE_OPTION, END_DATE_OPTION]
202
179
 
203
180
 
204
181
  def get_total_active_users(option_list: list):
205
- start_date = None
206
- end_date = None
207
- for option_flag, option_arg in option_list:
208
- if option_flag.name == "start_date":
209
- start_date = option_arg
210
- if option_flag.name == "end_date":
211
- end_date = option_arg
182
+ opts = {opt.name: arg for opt, arg in option_list}
183
+ start_date = opts.get("start_date")
184
+ end_date = opts.get("end_date")
212
185
 
213
- if not (start_date and end_date):
214
- raise MissingRequirementException("Cannot retrieve total active users without start-date and end-date")
186
+ if not start_date or not end_date:
187
+ start_date, end_date = get_default_date_range()
188
+ Console.write_stdout(f"Using default date range: {start_date} to {end_date}")
215
189
 
216
190
  manager = AnalyticsManager()
217
191
  result = manager.get_total_active_users(start_date, end_date)
@@ -222,16 +196,10 @@ active_users_options = [START_DATE_OPTION, END_DATE_OPTION]
222
196
 
223
197
 
224
198
  def get_full_report(option_list: list):
225
- start_date = None
226
- end_date = None
227
- csv_file = None
228
- for option_flag, option_arg in option_list:
229
- if option_flag.name == "start_date":
230
- start_date = option_arg
231
- if option_flag.name == "end_date":
232
- end_date = option_arg
233
- if option_flag.name == "csv_file":
234
- csv_file = option_arg
199
+ opts = {opt.name: arg for opt, arg in option_list}
200
+ start_date = opts.get("start_date")
201
+ end_date = opts.get("end_date")
202
+ csv_file = opts.get("csv_file")
235
203
 
236
204
  if not start_date or not end_date:
237
205
  start_date, end_date = get_default_date_range()