prediction-market-agent-tooling 0.56.2.dev145__py3-none-any.whl → 0.56.2.dev146__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.
@@ -1,13 +1,16 @@
1
1
  import builtins
2
2
  import logging
3
+ import sys
3
4
  import typing as t
4
5
  import warnings
5
6
  from enum import Enum
6
7
 
8
+ from loguru import logger
7
9
  from pydantic_settings import BaseSettings, SettingsConfigDict
8
10
 
9
11
 
10
12
  class LogFormat(str, Enum):
13
+ DEFAULT = "default"
11
14
  GCP = "gcp"
12
15
 
13
16
 
@@ -24,8 +27,8 @@ class LogConfig(BaseSettings):
24
27
  env_file=".env", env_file_encoding="utf-8", extra="ignore"
25
28
  )
26
29
 
27
- LOG_FORMAT: LogFormat = LogFormat.GCP
28
- LOG_LEVEL: LogLevel = LogLevel.INFO
30
+ LOG_FORMAT: LogFormat = LogFormat.DEFAULT
31
+ LOG_LEVEL: LogLevel = LogLevel.DEBUG
29
32
 
30
33
 
31
34
  class NoNewLineStreamHandler(logging.StreamHandler): # type: ignore # StreamHandler is not typed in the standard library.
@@ -33,15 +36,18 @@ class NoNewLineStreamHandler(logging.StreamHandler): # type: ignore # StreamHan
33
36
  return super().format(record).replace("\n", " ")
34
37
 
35
38
 
39
+ GCP_LOG_LOGURU_FORMAT = (
40
+ "{level:<.1}{time:MMDD HH:mm:ss} {process} {name}:{line}] {message}"
41
+ )
36
42
  GCP_LOG_LOGGING_FORMAT, GCP_LOG_FORMAT_LOGGING_DATEFMT = (
37
- "%(levelname).1s%(asctime)s %(process)d %(name)s:%(pathname)s:%(funcName)s:%(lineno)d] %(message)s"
43
+ "%(levelname).1s%(asctime)s %(process)d %(name)s:%(lineno)d] %(message)s"
38
44
  ), "%m%d %H:%M:%S"
39
45
 
40
46
 
41
47
  def patch_logger() -> None:
42
48
  """
43
49
  Function to patch loggers according to the deployed environment.
44
- Patches Python's default logger, warnings library and also monkey-patch print function as many libraries just use it.
50
+ Patches Loguru's logger, Python's default logger, warnings library and also monkey-patch print function as many libraries just use it.
45
51
  """
46
52
  if not getattr(logger, "_patched", False):
47
53
  logger._patched = True # type: ignore[attr-defined] # Hacky way to store a flag on the logger object, to not patch it multiple times.
@@ -51,34 +57,52 @@ def patch_logger() -> None:
51
57
  config = LogConfig()
52
58
 
53
59
  if config.LOG_FORMAT == LogFormat.GCP:
60
+ format_loguru = GCP_LOG_LOGURU_FORMAT
54
61
  format_logging = GCP_LOG_LOGGING_FORMAT
55
62
  datefmt_logging = GCP_LOG_FORMAT_LOGGING_DATEFMT
56
- print_logging = print_using_logger
63
+ print_logging = print_using_loguru_info
57
64
  handlers = [NoNewLineStreamHandler()]
58
65
 
66
+ elif config.LOG_FORMAT == LogFormat.DEFAULT:
67
+ format_loguru, format_logging, datefmt_logging = None, None, None
68
+ print_logging = None
69
+ handlers = None
70
+
59
71
  else:
60
72
  raise ValueError(f"Unknown log format: {config.LOG_FORMAT}")
61
73
 
62
74
  # Change built-in logging.
63
- logging.basicConfig(
64
- level=config.LOG_LEVEL.value,
65
- format=format_logging,
66
- datefmt=datefmt_logging,
67
- handlers=handlers,
68
- )
75
+ if format_logging is not None:
76
+ logging.basicConfig(
77
+ level=config.LOG_LEVEL.value,
78
+ format=format_logging,
79
+ datefmt=datefmt_logging,
80
+ handlers=handlers,
81
+ )
82
+
83
+ # Change loguru.
84
+ if format_loguru is not None:
85
+ logger.remove()
86
+ logger.add(
87
+ sys.stdout,
88
+ format=format_loguru,
89
+ level=config.LOG_LEVEL.value,
90
+ colorize=True,
91
+ )
69
92
 
70
93
  # Change warning formatting to a simpler one (no source code in a new line).
71
94
  warnings.formatwarning = simple_warning_format
72
95
  # Use logging module for warnings.
73
96
  logging.captureWarnings(True)
74
97
 
75
- # Use logger for prints.
76
- builtins.print = print_logging # type: ignore[assignment] # Monkey patching, it's messy but it works.
98
+ # Use loguru for prints.
99
+ if print_logging is not None:
100
+ builtins.print = print_logging # type: ignore[assignment] # Monkey patching, it's messy but it works.
77
101
 
78
102
  logger.info(f"Patched logger for {config.LOG_FORMAT.value} format.")
79
103
 
80
104
 
81
- def print_using_logger(
105
+ def print_using_loguru_info(
82
106
  *values: object,
83
107
  sep: str = " ",
84
108
  end: str = "\n",
@@ -97,6 +121,4 @@ def simple_warning_format(message, category, filename, lineno, line=None): # ty
97
121
  ) # Escape new lines, because otherwise logs will be broken.
98
122
 
99
123
 
100
- logger = logging.getLogger("prediction-market-agent-tooling")
101
-
102
124
  patch_logger()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.56.2.dev145
3
+ Version: 0.56.2.dev146
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -26,6 +26,7 @@ Requires-Dist: langchain (>=0.2.6,<0.3.0) ; extra == "langchain"
26
26
  Requires-Dist: langchain-community (>=0.0.19)
27
27
  Requires-Dist: langchain-openai (>=0.1.0,<0.2.0) ; extra == "langchain"
28
28
  Requires-Dist: langfuse (>=2.42.0,<3.0.0)
29
+ Requires-Dist: loguru (>=0.7.2,<0.8.0)
29
30
  Requires-Dist: loky (>=3.4.1,<4.0.0)
30
31
  Requires-Dist: numpy (>=1.26.4,<2.0.0)
31
32
  Requires-Dist: openai (>=1.0.0,<2.0.0) ; extra == "openai"
@@ -29,7 +29,7 @@ prediction_market_agent_tooling/gtypes.py,sha256=tqp03PyY0Yhievl4XELfwAn0xOoecaT
29
29
  prediction_market_agent_tooling/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  prediction_market_agent_tooling/jobs/jobs_models.py,sha256=GOtsNm7URhzZM5fPY64r8m8Gz-sSsUhG1qmDoC7wGL8,2231
31
31
  prediction_market_agent_tooling/jobs/omen/omen_jobs.py,sha256=N0_jGDyXQeVXXlYg4oA_pOfqIjscHsLQbr0pBwFGoRo,5178
32
- prediction_market_agent_tooling/loggers.py,sha256=i_CMm31EPvM734YDMSmgn0MI4NYS2kHp_FDaL1h-Z5M,3089
32
+ prediction_market_agent_tooling/loggers.py,sha256=Am6HHXRNO545BO3l7Ue9Wb2TkYE1OK8KKhGbI3XypVU,3751
33
33
  prediction_market_agent_tooling/markets/agent_market.py,sha256=W2ME57-CSAhrt8qm8-b5r7yLq-Sk7R_BZMaApvjhrUE,12901
34
34
  prediction_market_agent_tooling/markets/base_subgraph_handler.py,sha256=IxDTwX4tej9j5olNkXcLIE0RCF1Nh2icZQUT2ERMmZo,1937
35
35
  prediction_market_agent_tooling/markets/categorize.py,sha256=jsoHWvZk9pU6n17oWSCcCxNNYVwlb_NXsZxKRI7vmsk,1301
@@ -100,8 +100,8 @@ prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=5ldQs1pZe6u
100
100
  prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=Kw2mXNkMTYTEe1MBSTqhQmLoeXtgb6CkmHlcAJvhtqE,3809
101
101
  prediction_market_agent_tooling/tools/utils.py,sha256=1VvunbTmzGzpIlRukFhArreFNxJPbsg4lLtQNk0r2bY,7185
102
102
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=44W8siSLNQxeib98bbwAe7V5C609NHNlUuxwuWIRDiY,11838
103
- prediction_market_agent_tooling-0.56.2.dev145.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
104
- prediction_market_agent_tooling-0.56.2.dev145.dist-info/METADATA,sha256=QluPksTg71v0W8QNWlGRF-x_hkfT9waaCli9BBvGeIo,8074
105
- prediction_market_agent_tooling-0.56.2.dev145.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
106
- prediction_market_agent_tooling-0.56.2.dev145.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
107
- prediction_market_agent_tooling-0.56.2.dev145.dist-info/RECORD,,
103
+ prediction_market_agent_tooling-0.56.2.dev146.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
104
+ prediction_market_agent_tooling-0.56.2.dev146.dist-info/METADATA,sha256=hip-pKuofFriAygKgWq5Af5ppLtNNW0oom1nnrTDqcg,8113
105
+ prediction_market_agent_tooling-0.56.2.dev146.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
106
+ prediction_market_agent_tooling-0.56.2.dev146.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
107
+ prediction_market_agent_tooling-0.56.2.dev146.dist-info/RECORD,,