aiverify-moonshot 0.4.1__py3-none-any.whl → 0.4.2__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 (59) hide show
  1. {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/METADATA +2 -2
  2. {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/RECORD +59 -49
  3. moonshot/__main__.py +77 -35
  4. moonshot/api.py +14 -0
  5. moonshot/integrations/cli/benchmark/benchmark.py +29 -13
  6. moonshot/integrations/cli/benchmark/cookbook.py +36 -6
  7. moonshot/integrations/cli/benchmark/datasets.py +33 -3
  8. moonshot/integrations/cli/benchmark/metrics.py +33 -3
  9. moonshot/integrations/cli/benchmark/recipe.py +36 -6
  10. moonshot/integrations/cli/benchmark/result.py +33 -3
  11. moonshot/integrations/cli/benchmark/run.py +34 -3
  12. moonshot/integrations/cli/common/common.py +12 -6
  13. moonshot/integrations/cli/common/connectors.py +73 -9
  14. moonshot/integrations/cli/common/prompt_template.py +38 -3
  15. moonshot/integrations/cli/redteam/attack_module.py +75 -24
  16. moonshot/integrations/cli/redteam/context_strategy.py +77 -23
  17. moonshot/integrations/cli/redteam/prompt_template.py +1 -1
  18. moonshot/integrations/cli/redteam/redteam.py +52 -6
  19. moonshot/integrations/cli/redteam/session.py +539 -43
  20. moonshot/integrations/web_api/__main__.py +2 -0
  21. moonshot/integrations/web_api/app.py +6 -6
  22. moonshot/integrations/web_api/container.py +12 -2
  23. moonshot/integrations/web_api/routes/bookmark.py +173 -0
  24. moonshot/integrations/web_api/schemas/bookmark_create_dto.py +13 -0
  25. moonshot/integrations/web_api/services/bookmark_service.py +90 -0
  26. moonshot/integrations/web_api/services/utils/file_manager.py +52 -0
  27. moonshot/integrations/web_api/status_updater/moonshot_ui_webhook.py +0 -1
  28. moonshot/integrations/web_api/temp/.gitkeep +0 -0
  29. moonshot/src/api/api_bookmark.py +95 -0
  30. moonshot/src/api/api_connector_endpoint.py +1 -1
  31. moonshot/src/api/api_context_strategy.py +2 -2
  32. moonshot/src/api/api_session.py +1 -1
  33. moonshot/src/bookmark/bookmark.py +257 -0
  34. moonshot/src/bookmark/bookmark_arguments.py +38 -0
  35. moonshot/src/configs/env_variables.py +12 -2
  36. moonshot/src/connectors/connector.py +15 -7
  37. moonshot/src/connectors_endpoints/connector_endpoint.py +65 -49
  38. moonshot/src/cookbooks/cookbook.py +57 -37
  39. moonshot/src/datasets/dataset.py +9 -5
  40. moonshot/src/metrics/metric.py +8 -4
  41. moonshot/src/metrics/metric_interface.py +8 -2
  42. moonshot/src/prompt_templates/prompt_template.py +5 -1
  43. moonshot/src/recipes/recipe.py +38 -25
  44. moonshot/src/redteaming/attack/attack_module.py +18 -8
  45. moonshot/src/redteaming/attack/context_strategy.py +6 -2
  46. moonshot/src/redteaming/session/session.py +15 -11
  47. moonshot/src/results/result.py +7 -3
  48. moonshot/src/runners/runner.py +65 -42
  49. moonshot/src/runs/run.py +15 -11
  50. moonshot/src/runs/run_progress.py +7 -3
  51. moonshot/src/storage/db_interface.py +14 -0
  52. moonshot/src/storage/storage.py +33 -2
  53. moonshot/src/utils/find_feature.py +45 -0
  54. moonshot/src/utils/log.py +66 -0
  55. moonshot/src/utils/timeit.py +8 -1
  56. {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/WHEEL +0 -0
  57. {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/licenses/AUTHORS.md +0 -0
  58. {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/licenses/LICENSE.md +0 -0
  59. {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/licenses/NOTICES.md +0 -0
@@ -0,0 +1,66 @@
1
+ import logging
2
+ import os
3
+ from pathlib import Path
4
+
5
+
6
+ def configure_logger(name: str):
7
+ """
8
+ Configures and returns a logger with a specified name.
9
+
10
+ This function creates a logger and sets its level to INFO. It also creates a console handler,
11
+ sets its level to INFO, and assigns a specific formatter to it. The formatter includes the
12
+ timestamp, log level, filename, function name, line number, and the log message. Finally, the
13
+ console handler is added to the logger.
14
+
15
+ Args:
16
+ name (str): The name of the logger to be created and configured.
17
+
18
+ Returns:
19
+ logging.Logger: The configured logger with the specified name.
20
+ """
21
+ log_extension = ".log"
22
+
23
+ # Read environment variable
24
+ log_filename = os.getenv("MS_LOG_NAME", "moonshot").lower()
25
+ log_level = os.getenv("MS_LOG_LEVEL", "INFO").upper()
26
+ log_write_to_file = os.getenv("MS_LOG_TO_FILE", "false").lower() == "true"
27
+
28
+ # Create a formatter
29
+ formatter = logging.Formatter(
30
+ "%(asctime)s [%(levelname)s][%(filename)s::%(funcName)s(%(lineno)d)] %(message)s"
31
+ )
32
+
33
+ # Check name is valid
34
+ if not name or not isinstance(name, str) or name is None:
35
+ name = Path(__file__).stem
36
+
37
+ # Check log level is valid
38
+ valid_log_levels = ["DEBUG", "INFO", "WARNING", "ERROR"]
39
+ if log_level not in valid_log_levels:
40
+ log_level = "INFO"
41
+
42
+ # Check log filename is valid
43
+ if not log_filename or not isinstance(log_filename, str) or log_filename is None:
44
+ log_filename = "moonshot"
45
+
46
+ logger = logging.getLogger(name)
47
+ logger.setLevel(log_level)
48
+ logger.propagate = False
49
+
50
+ # Create a console handler
51
+ console_handler = logging.StreamHandler()
52
+ console_handler.setLevel(log_level)
53
+ console_handler.setFormatter(formatter)
54
+ logger.addHandler(console_handler)
55
+
56
+ # Create a file handler if required
57
+ if log_write_to_file:
58
+ file_path = Path(".").joinpath(log_filename).with_suffix(log_extension)
59
+ file_handler = logging.FileHandler(
60
+ str(file_path)
61
+ ) # Convert Path object to string
62
+ file_handler.setLevel(log_level)
63
+ file_handler.setFormatter(formatter)
64
+ logger.addHandler(file_handler)
65
+
66
+ return logger
@@ -1,6 +1,11 @@
1
1
  import time
2
2
  from functools import wraps
3
3
 
4
+ from moonshot.src.utils.log import configure_logger
5
+
6
+ # Create a logger for this module
7
+ logger = configure_logger(__name__)
8
+
4
9
 
5
10
  def timeit(func):
6
11
  @wraps(func)
@@ -19,7 +24,9 @@ def timeit(func):
19
24
  result = func(*args, **kwargs)
20
25
  end_time = time.perf_counter()
21
26
  total_time = end_time - start_time
22
- print(f"[{func.__module__}] Running [{func.__name__}] took {total_time:.4f}s")
27
+ logger.debug(
28
+ f"[{func.__module__}] Running [{func.__name__}] took {total_time:.4f}s"
29
+ )
23
30
  return result
24
31
 
25
32
  return timeit_wrapper