arpakitlib 1.6.47__py3-none-any.whl → 1.7.90__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 (157) hide show
  1. arpakitlib/_arpakit_project_template/.gitignore +51 -0
  2. arpakitlib/_arpakit_project_template/.python-version +1 -0
  3. arpakitlib/_arpakit_project_template/ARPAKITLIB +1 -0
  4. arpakitlib/_arpakit_project_template/AUTHOR.md +4 -0
  5. arpakitlib/_arpakit_project_template/NOTICE +16 -0
  6. arpakitlib/_arpakit_project_template/README.md +6 -0
  7. arpakitlib/_arpakit_project_template/example.env +22 -0
  8. arpakitlib/_arpakit_project_template/manage/__init__.py +0 -0
  9. arpakitlib/_arpakit_project_template/manage/docker_ps.sh +2 -0
  10. arpakitlib/_arpakit_project_template/manage/docker_ps_a.sh +2 -0
  11. arpakitlib/_arpakit_project_template/manage/docker_run_postgres_for_dev.sh +4 -0
  12. arpakitlib/_arpakit_project_template/manage/docker_start_postgres_for_dev.sh +2 -0
  13. arpakitlib/_arpakit_project_template/manage/docker_stop_postgres_for_dev.sh +2 -0
  14. arpakitlib/_arpakit_project_template/manage/example_nginx_proxy.nginx +14 -0
  15. arpakitlib/_arpakit_project_template/manage/example_poetry_arpakitlib.sh +1 -0
  16. arpakitlib/_arpakit_project_template/manage/example_pyproject.toml +18 -0
  17. arpakitlib/_arpakit_project_template/manage/example_systemd.service +12 -0
  18. arpakitlib/_arpakit_project_template/manage/git_branch.sh +2 -0
  19. arpakitlib/_arpakit_project_template/manage/git_commit.sh +3 -0
  20. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_company_github_1.sh +4 -0
  21. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_company_gitlab_1.sh +4 -0
  22. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_github_1.sh +4 -0
  23. arpakitlib/_arpakit_project_template/manage/git_push_arpakit_gitlab_1.sh +4 -0
  24. arpakitlib/_arpakit_project_template/manage/git_remote_v.sh +2 -0
  25. arpakitlib/_arpakit_project_template/manage/git_set_arpakit_company_origin.sh +7 -0
  26. arpakitlib/_arpakit_project_template/manage/git_set_arpakit_origin.sh +7 -0
  27. arpakitlib/_arpakit_project_template/manage/git_status.sh +2 -0
  28. arpakitlib/_arpakit_project_template/manage/hello_world.py +6 -0
  29. arpakitlib/_arpakit_project_template/manage/json_beutify.py +10 -0
  30. arpakitlib/_arpakit_project_template/manage/logging_check.py +14 -0
  31. arpakitlib/_arpakit_project_template/manage/note/__init__.py +0 -0
  32. arpakitlib/_arpakit_project_template/manage/note/note_1.txt +0 -0
  33. arpakitlib/_arpakit_project_template/manage/note/note_2.txt +0 -0
  34. arpakitlib/_arpakit_project_template/manage/note/note_3.txt +0 -0
  35. arpakitlib/_arpakit_project_template/manage/note/note_4.txt +0 -0
  36. arpakitlib/_arpakit_project_template/manage/note/note_5.txt +0 -0
  37. arpakitlib/_arpakit_project_template/manage/poetry_add_plugin_export.sh +2 -0
  38. arpakitlib/_arpakit_project_template/manage/poetry_check.sh +2 -0
  39. arpakitlib/_arpakit_project_template/manage/poetry_clear_cache.sh +4 -0
  40. arpakitlib/_arpakit_project_template/manage/poetry_config_virtualenvs_in_project_true.sh +2 -0
  41. arpakitlib/_arpakit_project_template/manage/poetry_generate_requirements.txt.sh +1 -0
  42. arpakitlib/_arpakit_project_template/manage/poetry_install.sh +5 -0
  43. arpakitlib/_arpakit_project_template/manage/poetry_lock.sh +2 -0
  44. arpakitlib/_arpakit_project_template/manage/poetry_remove_and_add_arpakitlib.sh +7 -0
  45. arpakitlib/_arpakit_project_template/manage/poetry_show.sh +2 -0
  46. arpakitlib/_arpakit_project_template/manage/poetry_show_arpakitlib.sh +2 -0
  47. arpakitlib/_arpakit_project_template/manage/poetry_update.sh +6 -0
  48. arpakitlib/_arpakit_project_template/manage/poetry_update_arpakitlib.sh +5 -0
  49. arpakitlib/_arpakit_project_template/manage/requirements.txt +209 -0
  50. arpakitlib/_arpakit_project_template/manage/sandbox/__init__.py +0 -0
  51. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_1.py +14 -0
  52. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_2.py +14 -0
  53. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_3.py +14 -0
  54. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_4.py +14 -0
  55. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_5.py +14 -0
  56. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_6.py +14 -0
  57. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_7.py +14 -0
  58. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_8.sh +0 -0
  59. arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_9.sh +0 -0
  60. arpakitlib/_arpakit_project_template/manage/settings_check.py +10 -0
  61. arpakitlib/_arpakit_project_template/manage/settings_generate_env_example.py +13 -0
  62. arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_check_conn.py +11 -0
  63. arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_init.py +11 -0
  64. arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_reinit.py +11 -0
  65. arpakitlib/_arpakit_project_template/resource/__init__.py +0 -0
  66. arpakitlib/_arpakit_project_template/resource/static/__init__.py +0 -0
  67. arpakitlib/_arpakit_project_template/resource/static/healthcheck +1 -0
  68. arpakitlib/_arpakit_project_template/resource/static/helloworld +1 -0
  69. arpakitlib/_arpakit_project_template/src/__init__.py +0 -0
  70. arpakitlib/_arpakit_project_template/src/additional_model/__init__.py +0 -0
  71. arpakitlib/_arpakit_project_template/src/additional_model/additional_model.py +6 -0
  72. arpakitlib/_arpakit_project_template/src/api/__init__.py +0 -0
  73. arpakitlib/_arpakit_project_template/src/api/asgi.py +3 -0
  74. arpakitlib/_arpakit_project_template/src/api/auth.py +1 -0
  75. arpakitlib/_arpakit_project_template/src/api/const.py +13 -0
  76. arpakitlib/_arpakit_project_template/src/api/create_api_app.py +117 -0
  77. arpakitlib/_arpakit_project_template/src/api/event.py +20 -0
  78. arpakitlib/_arpakit_project_template/src/api/router/__init__.py +0 -0
  79. arpakitlib/_arpakit_project_template/src/api/router/main_router.py +9 -0
  80. arpakitlib/_arpakit_project_template/src/api/router/v1/__init__.py +0 -0
  81. arpakitlib/_arpakit_project_template/src/api/router/v1/get_api_error_info.py +27 -0
  82. arpakitlib/_arpakit_project_template/src/api/router/v1/main_router.py +11 -0
  83. arpakitlib/_arpakit_project_template/src/api/schema/__init__.py +0 -0
  84. arpakitlib/_arpakit_project_template/src/api/schema/v1/__init__.py +0 -0
  85. arpakitlib/_arpakit_project_template/src/api/schema/v1/in_.py +0 -0
  86. arpakitlib/_arpakit_project_template/src/api/schema/v1/out.py +6 -0
  87. arpakitlib/_arpakit_project_template/src/api/start_api_for_dev.py +17 -0
  88. arpakitlib/_arpakit_project_template/src/api/start_api_for_dev_with_reload.py +9 -0
  89. arpakitlib/_arpakit_project_template/src/api/transmitted_api_data.py +9 -0
  90. arpakitlib/_arpakit_project_template/src/api/util.py +0 -0
  91. arpakitlib/_arpakit_project_template/src/business_service/__init__.py +0 -0
  92. arpakitlib/_arpakit_project_template/src/core/__init__.py +0 -0
  93. arpakitlib/_arpakit_project_template/src/core/const.py +48 -0
  94. arpakitlib/_arpakit_project_template/src/core/settings.py +86 -0
  95. arpakitlib/_arpakit_project_template/src/core/util.py +58 -0
  96. arpakitlib/_arpakit_project_template/src/db/__init__.py +0 -0
  97. arpakitlib/_arpakit_project_template/src/db/sqlalchemy_model.py +8 -0
  98. arpakitlib/_arpakit_project_template/src/db/util.py +21 -0
  99. arpakitlib/_arpakit_project_template/src/operation_execution/__init__.py +0 -0
  100. arpakitlib/_arpakit_project_template/src/operation_execution/const.py +9 -0
  101. arpakitlib/_arpakit_project_template/src/operation_execution/operation_executor.py +14 -0
  102. arpakitlib/_arpakit_project_template/src/operation_execution/scheduled_operations.py +25 -0
  103. arpakitlib/_arpakit_project_template/src/operation_execution/start_operation_executor_worker_for_dev.py +18 -0
  104. arpakitlib/_arpakit_project_template/src/operation_execution/start_scheduled_operation_creator_worker_for_dev.py +17 -0
  105. arpakitlib/_arpakit_project_template/src/operation_execution/util.py +21 -0
  106. arpakitlib/_arpakit_project_template/src/test_data/__init__.py +0 -0
  107. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_1.py +6 -0
  108. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_2.py +6 -0
  109. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_3.py +6 -0
  110. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_4.py +6 -0
  111. arpakitlib/_arpakit_project_template/src/test_data/make_test_data_5.py +6 -0
  112. arpakitlib/_arpakit_project_template/src/util/__init__.py +0 -0
  113. arpakitlib/api_key_util.py +21 -0
  114. arpakitlib/ar_additional_model_util.py +25 -2
  115. arpakitlib/ar_aiogram_util.py +10 -18
  116. arpakitlib/ar_arpakit_lib_module_util.py +6 -1
  117. arpakitlib/ar_arpakit_project_template_util.py +96 -0
  118. arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +24 -3
  119. arpakitlib/ar_arpakitlib_cli_util.py +79 -0
  120. arpakitlib/ar_base_worker_util.py +95 -48
  121. arpakitlib/ar_dream_ai_api_client_util.py +26 -52
  122. arpakitlib/ar_enumeration_util.py +11 -0
  123. arpakitlib/ar_exception_util.py +18 -0
  124. arpakitlib/ar_fastapi_static/healthcheck +1 -0
  125. arpakitlib/ar_fastapi_util.py +270 -137
  126. arpakitlib/ar_file_util.py +22 -0
  127. arpakitlib/ar_func_util.py +55 -0
  128. arpakitlib/ar_http_request_util.py +35 -6
  129. arpakitlib/ar_json_util.py +13 -7
  130. arpakitlib/ar_logging_util.py +5 -2
  131. arpakitlib/ar_need_type_util.py +12 -2
  132. arpakitlib/{ar_openai_util.py → ar_openai_api_client_util.py} +16 -2
  133. arpakitlib/ar_operation_execution_util.py +250 -105
  134. arpakitlib/ar_parse_command.py +25 -7
  135. arpakitlib/ar_schedule_uust_api_client_util.py +37 -23
  136. arpakitlib/ar_settings_util.py +37 -11
  137. arpakitlib/ar_sleep_util.py +0 -13
  138. arpakitlib/ar_sqlalchemy_model_util.py +47 -10
  139. arpakitlib/ar_sqlalchemy_util.py +4 -3
  140. arpakitlib/{ar_ssh_util.py → ar_ssh_runner_util.py} +2 -2
  141. arpakitlib/ar_str_util.py +43 -2
  142. arpakitlib/ar_type_util.py +68 -4
  143. arpakitlib/ar_yookassa_api_client_util.py +26 -44
  144. {arpakitlib-1.6.47.dist-info → arpakitlib-1.7.90.dist-info}/METADATA +17 -8
  145. arpakitlib-1.7.90.dist-info/NOTICE +16 -0
  146. arpakitlib-1.7.90.dist-info/RECORD +186 -0
  147. arpakitlib-1.7.90.dist-info/entry_points.txt +3 -0
  148. arpakitlib/AUTHOR.md +0 -7
  149. arpakitlib/NOTICE +0 -2
  150. arpakitlib/ar_arpakitlib_info.py +0 -13
  151. arpakitlib/ar_generate_env_example.py +0 -22
  152. arpakitlib-1.6.47.dist-info/NOTICE +0 -2
  153. arpakitlib-1.6.47.dist-info/RECORD +0 -70
  154. /arpakitlib/{LICENSE → _arpakit_project_template/LICENSE} +0 -0
  155. /arpakitlib/{ar_zabbix_util.py → ar_zabbix_api_client_util.py} +0 -0
  156. {arpakitlib-1.6.47.dist-info → arpakitlib-1.7.90.dist-info}/LICENSE +0 -0
  157. {arpakitlib-1.6.47.dist-info → arpakitlib-1.7.90.dist-info}/WHEEL +0 -0
@@ -0,0 +1,22 @@
1
+ import os
2
+
3
+ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
4
+
5
+
6
+ def raise_if_path_not_exists(path: str):
7
+ if not os.path.exists(path):
8
+ raise Exception(f"path {path} not exists")
9
+
10
+
11
+ def clear_text_file(filepath: str):
12
+ if not os.path.exists(filepath):
13
+ return
14
+ with open(filepath, mode="w") as f:
15
+ f.write("")
16
+
17
+
18
+ def create_text_file(filepath: str, text: str = ""):
19
+ if os.path.exists(filepath):
20
+ return
21
+ with open(filepath, mode="w") as f:
22
+ f.write(text)
@@ -0,0 +1,55 @@
1
+ import asyncio
2
+ import inspect
3
+ from typing import Callable, Any
4
+
5
+ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
6
+
7
+
8
+ def is_async_function(func: Callable) -> bool:
9
+ return asyncio.iscoroutinefunction(func)
10
+
11
+
12
+ def is_async_object(obj: object) -> bool:
13
+ return asyncio.iscoroutine(obj)
14
+
15
+
16
+ def is_sync_function(func: Callable) -> bool:
17
+ return inspect.isfunction(func) and not is_async_function(func)
18
+
19
+
20
+ def raise_if_not_async_func(func: Callable):
21
+ if not is_async_function(func):
22
+ raise TypeError(f"The provided function '{func.__name__}' is not an async function")
23
+
24
+
25
+ def raise_if_not_sync_func(func: Callable):
26
+ if not is_sync_function(func):
27
+ raise TypeError(f"The provided function '{func.__name__}' is not a sync function")
28
+
29
+
30
+ def raise_if_async_func(func: Callable):
31
+ if is_async_function(func):
32
+ raise TypeError(f"The provided function '{func.__name__}' should not be async")
33
+
34
+
35
+ def raise_if_sync_func(func: Callable):
36
+ if is_sync_function(func):
37
+ raise TypeError(f"The provided function '{func.__name__}' should not be sync")
38
+
39
+
40
+ def __example():
41
+ def one():
42
+ pass
43
+
44
+ async def two():
45
+ pass
46
+
47
+ print(is_sync_function(one))
48
+ print(is_sync_function(two))
49
+
50
+ print(is_async_function(one))
51
+ print(is_async_function(two))
52
+
53
+
54
+ if __name__ == '__main__':
55
+ __example()
@@ -3,6 +3,7 @@
3
3
  import asyncio
4
4
  import logging
5
5
  from datetime import timedelta
6
+ from typing import Any
6
7
 
7
8
  import aiohttp
8
9
  import requests
@@ -20,10 +21,13 @@ def sync_make_http_request(
20
21
  *,
21
22
  method: str = "GET",
22
23
  url: str,
24
+ headers: dict[str, Any] | None = None,
25
+ params: dict[str, Any] | None = None,
23
26
  max_tries_: int = 9,
24
27
  proxy_url_: str | None = None,
25
28
  raise_for_status_: bool = False,
26
29
  timeout_: timedelta | float = timedelta(seconds=15).total_seconds(),
30
+ enable_logging_: bool = False,
27
31
  **kwargs
28
32
  ) -> requests.Response:
29
33
  if isinstance(timeout_, float):
@@ -34,26 +38,37 @@ def sync_make_http_request(
34
38
 
35
39
  kwargs["method"] = method
36
40
  kwargs["url"] = url
37
- if timeout_ is not None:
38
- kwargs["timeout"] = timeout_.total_seconds()
41
+ if headers is not None:
42
+ kwargs["headers"] = headers
43
+ if params is not None:
44
+ kwargs["params"] = params
39
45
  if proxy_url_:
40
46
  kwargs["proxies"] = {
41
47
  "http": proxy_url_,
42
48
  "https": proxy_url_
43
49
  }
50
+ if timeout_ is not None:
51
+ kwargs["timeout"] = timeout_.total_seconds()
44
52
  if "allow_redirects" not in kwargs:
45
53
  kwargs["allow_redirects"] = True
46
54
 
55
+ if enable_logging_:
56
+ _logger.info(f"TRY HTTP {method} {url} {params}")
57
+
47
58
  while True:
48
59
  tries_counter += 1
49
- _logger.info(f"{method} {url} {kwargs.get('params')}")
50
60
  try:
51
61
  response = requests.request(**kwargs)
52
62
  if raise_for_status_:
53
63
  response.raise_for_status()
64
+ if enable_logging_:
65
+ _logger.info(f"GOOD TRY HTTP {method} {url} {params}")
54
66
  return response
55
67
  except BaseException as exception:
56
- _logger.warning(f"{tries_counter}/{max_tries_} {method} {url} {exception}")
68
+ if enable_logging_:
69
+ _logger.warning(
70
+ f"{tries_counter}/{max_tries_}. RETRY {method} {url} {params}, exception={exception}"
71
+ )
57
72
  if tries_counter >= max_tries_:
58
73
  raise exception
59
74
  sync_safe_sleep(timedelta(seconds=0.1).total_seconds())
@@ -64,16 +79,23 @@ async def async_make_http_request(
64
79
  *,
65
80
  method: str = "GET",
66
81
  url: str,
82
+ headers: dict[str, Any] | None = None,
83
+ params: dict[str, Any] | None = None,
67
84
  max_tries_: int = 9,
68
85
  proxy_url_: str | None = None,
69
86
  raise_for_status_: bool = False,
70
87
  timeout_: timedelta | None = timedelta(seconds=15),
88
+ enable_logging_: bool = False,
71
89
  **kwargs
72
90
  ) -> aiohttp.ClientResponse:
73
91
  tries_counter = 0
74
92
 
75
93
  kwargs["method"] = method
76
94
  kwargs["url"] = url
95
+ if headers is not None:
96
+ kwargs["headers"] = headers
97
+ if params is not None:
98
+ kwargs["params"] = params
77
99
  if timeout_ is not None:
78
100
  kwargs["timeout"] = aiohttp.ClientTimeout(total=timeout_.total_seconds())
79
101
  if "allow_redirects" not in kwargs:
@@ -83,18 +105,25 @@ async def async_make_http_request(
83
105
  if proxy_url_:
84
106
  proxy_connector = ProxyConnector.from_url(proxy_url_)
85
107
 
108
+ if enable_logging_:
109
+ _logger.info(f"TRY HTTP {method} {url} {params}")
110
+
86
111
  while True:
87
112
  tries_counter += 1
88
- _logger.info(f"{method} {url} {kwargs.get('params')}")
89
113
  try:
90
114
  async with aiohttp.ClientSession(connector=proxy_connector) as session:
91
115
  async with session.request(**kwargs) as response:
92
116
  if raise_for_status_:
93
117
  response.raise_for_status()
94
118
  await response.read()
119
+ if enable_logging_:
120
+ _logger.info(f"GOOD TRY HTTP {method} {url} {params}")
95
121
  return response
96
122
  except BaseException as exception:
97
- _logger.warning(f"{tries_counter}/{max_tries_} {method} {url} {exception}")
123
+ if enable_logging_:
124
+ _logger.warning(
125
+ f"{tries_counter}/{max_tries_}. RETRY HTTP {method} {url} {params}, exception={exception}"
126
+ )
98
127
  if tries_counter >= max_tries_:
99
128
  raise exception
100
129
  await async_safe_sleep(timedelta(seconds=0.1).total_seconds())
@@ -1,25 +1,31 @@
1
1
  # arpakit
2
2
 
3
3
  import json
4
- from typing import Union, Any
4
+ from typing import Any
5
5
 
6
6
  _ARPAKIT_LIB_MODULE_VERSION = "3.0"
7
7
 
8
8
 
9
- def safely_transfer_to_json_obj(data: str) -> Union[dict, list]:
9
+ def safely_transfer_str_to_json_obj(data: str) -> dict[Any, Any] | list[Any] | None:
10
10
  if not isinstance(data, str):
11
11
  raise ValueError("not isinstance(data, str)")
12
12
  return json.loads(data)
13
13
 
14
14
 
15
- def safely_transfer_to_json_str(data: Union[dict[str, Any], list[Any]]) -> str:
16
- if not isinstance(data, dict) and not isinstance(data, list):
17
- raise ValueError("not isinstance(data, dict) and not isinstance(data, list)")
15
+ def safely_transfer_obj_to_json_str(data: dict[Any, Any] | list[Any] | None) -> str:
16
+ if not isinstance(data, dict) and not isinstance(data, list) and data is not None:
17
+ raise ValueError("not isinstance(data, dict) and not isinstance(data, list) and data is not None")
18
18
  return json.dumps(data, ensure_ascii=False, indent=2, default=str)
19
19
 
20
20
 
21
- def safely_transfer_to_json_str_to_json_obj(data: Union[dict[str, Any], list[Any]]) -> Union[dict, list]:
22
- return safely_transfer_to_json_obj(safely_transfer_to_json_str(data))
21
+ def safely_transfer_obj_to_json_str_to_json_obj(
22
+ data: dict[Any, Any] | list[Any] | None
23
+ ) -> dict[Any, Any] | list[Any] | None:
24
+ return safely_transfer_str_to_json_obj(safely_transfer_obj_to_json_str(data))
25
+
26
+
27
+ def safely_transfer_str_to_json_obj_to_json_str(data: str) -> str:
28
+ return safely_transfer_obj_to_json_str(safely_transfer_str_to_json_obj(data))
23
29
 
24
30
 
25
31
  def __example():
@@ -8,6 +8,9 @@ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
8
8
 
9
9
 
10
10
  def init_log_file(*, log_filepath: str):
11
+ directory = os.path.dirname(log_filepath)
12
+ if directory and not os.path.exists(directory):
13
+ os.makedirs(directory, exist_ok=True)
11
14
  if not os.path.exists(path=log_filepath):
12
15
  with open(file=log_filepath, mode="w") as file:
13
16
  file.write("")
@@ -30,7 +33,7 @@ def setup_normal_logging(log_filepath: Optional[str] = None):
30
33
  stream_handler = logging.StreamHandler()
31
34
  stream_handler.setLevel(logging.INFO)
32
35
  stream_formatter = logging.Formatter(
33
- "%(asctime)s | %(levelname)s | %(name)s - %(message)s",
36
+ "%(asctime)s | %(levelname)s | %(filename)s | %(funcName)s:%(lineno)d - %(message)s",
34
37
  datefmt="%d.%m.%Y %I:%M:%S%p"
35
38
  )
36
39
  stream_handler.setFormatter(stream_formatter)
@@ -40,7 +43,7 @@ def setup_normal_logging(log_filepath: Optional[str] = None):
40
43
  file_handler = logging.FileHandler(log_filepath)
41
44
  file_handler.setLevel(logging.WARNING)
42
45
  file_formatter = logging.Formatter(
43
- "%(asctime)s | %(levelname)s | %(name)s | %(filename)s:%(lineno)d - %(message)s",
46
+ "%(asctime)s | %(levelname)s | %(filename)s | %(funcName)s:%(lineno)d - %(message)s",
44
47
  datefmt="%d.%m.%Y %I:%M:%S%p"
45
48
  )
46
49
  file_handler.setFormatter(file_formatter)
@@ -19,7 +19,10 @@ class NeedTypes(Enumeration):
19
19
  json = "json"
20
20
 
21
21
 
22
- def parse_need_type(value: Any, need_type: str) -> Any:
22
+ def parse_need_type(value: Any, need_type: str, allow_none: bool = False) -> Any:
23
+ if allow_none and value is None:
24
+ return None
25
+
23
26
  NeedTypes.parse_and_validate_values(need_type)
24
27
 
25
28
  if need_type == NeedTypes.str_:
@@ -53,7 +56,14 @@ def parse_need_type(value: Any, need_type: str) -> Any:
53
56
 
54
57
 
55
58
  def __example():
56
- pass
59
+ print(parse_need_type(value=123, need_type="int"))
60
+ print(parse_need_type(value="True", need_type="bool"))
61
+ print(parse_need_type(value=123.456, need_type="float"))
62
+ print(parse_need_type(value='[1, 2, 3]', need_type="list_of_int"))
63
+ print(parse_need_type(value='["a", "b", "c"]', need_type="list_of_str"))
64
+ print(parse_need_type(value='[1.1, 2.2, 3.3]', need_type="list_of_float"))
65
+ print(parse_need_type(value='{"key": "value"}', need_type="json"))
66
+ print(parse_need_type(value="hello world", need_type="str"))
57
67
 
58
68
 
59
69
  if __name__ == '__main__':
@@ -49,11 +49,25 @@ class OpenAIAPIClient:
49
49
 
50
50
 
51
51
  def __example():
52
- pass
52
+ open_ai = OpenAI(api_key="your-api-key")
53
+ client = OpenAIAPIClient(open_ai=open_ai)
54
+
55
+ print("Checking OpenAI API connection...")
56
+ if client.is_conn_good():
57
+ print("Connection to OpenAI API is good")
58
+ else:
59
+ print("Failed to connect to OpenAI API")
53
60
 
54
61
 
55
62
  async def __async_example():
56
- pass
63
+ async_open_ai = AsyncOpenAI(api_key="your-api-key")
64
+ client = OpenAIAPIClient(async_open_ai=async_open_ai)
65
+
66
+ print("Checking OpenAI API async connection...")
67
+ if await client.async_is_conn_good():
68
+ print("Async connection to OpenAI API is good")
69
+ else:
70
+ print("Failed to async connect to OpenAI API")
57
71
 
58
72
 
59
73
  if __name__ == '__main__':