prediction-market-agent-tooling 0.56.1__py3-none-any.whl → 0.56.2.dev136__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.
@@ -53,7 +53,7 @@ class APIKeys(BaseSettings):
53
53
 
54
54
  SQLALCHEMY_DB_URL: t.Optional[SecretStr] = None
55
55
 
56
- ENABLE_CACHE: bool = True
56
+ ENABLE_CACHE: bool = False
57
57
  CACHE_DIR: str = "./.cache"
58
58
 
59
59
  @property
@@ -22,6 +22,7 @@ from sqlmodel import Field, Session, SQLModel, create_engine, desc, select
22
22
  from prediction_market_agent_tooling.config import APIKeys
23
23
  from prediction_market_agent_tooling.loggers import logger
24
24
  from prediction_market_agent_tooling.tools.datetime_utc import DatetimeUTC
25
+ from prediction_market_agent_tooling.tools.pickle_utils import InitialiseNonPickable
25
26
  from prediction_market_agent_tooling.tools.utils import utcnow
26
27
 
27
28
  FunctionT = TypeVar("FunctionT", bound=Callable[..., Any])
@@ -90,6 +91,17 @@ def db_cache(
90
91
  return decorator
91
92
 
92
93
  api_keys = api_keys if api_keys is not None else APIKeys()
94
+ wrapped_engine = InitialiseNonPickable(
95
+ lambda: create_engine(
96
+ api_keys.sqlalchemy_db_url.get_secret_value(),
97
+ # Use custom json serializer and deserializer, because otherwise, for example `datetime` serialization would fail.
98
+ json_serializer=json_serializer,
99
+ json_deserializer=json_deserializer,
100
+ )
101
+ )
102
+
103
+ if api_keys.ENABLE_CACHE:
104
+ SQLModel.metadata.create_all(wrapped_engine.get_value())
93
105
 
94
106
  @wraps(func)
95
107
  def wrapper(*args: Any, **kwargs: Any) -> Any:
@@ -97,15 +109,7 @@ def db_cache(
97
109
  if not api_keys.ENABLE_CACHE:
98
110
  return func(*args, **kwargs)
99
111
 
100
- engine = create_engine(
101
- api_keys.sqlalchemy_db_url.get_secret_value(),
102
- # Use custom json serializer and deserializer, because otherwise, for example `datetime` serialization would fail.
103
- json_serializer=json_serializer,
104
- json_deserializer=json_deserializer,
105
- )
106
-
107
- # Create table if it doesn't exist
108
- SQLModel.metadata.create_all(engine)
112
+ engine = wrapped_engine.get_value()
109
113
 
110
114
  # Convert *args and **kwargs to a single dictionary, where we have names for arguments passed as args as well.
111
115
  signature = inspect.signature(func)
@@ -195,7 +199,7 @@ def db_cache(
195
199
  )
196
200
 
197
201
  # If postgres access was specified, save it.
198
- if engine is not None and (cache_none or computed_result is not None):
202
+ if cache_none or computed_result is not None:
199
203
  cache_entry = FunctionCache(
200
204
  function_name=function_name,
201
205
  full_function_name=full_function_name,
@@ -0,0 +1,31 @@
1
+ import typing as t
2
+
3
+ InitialisedValue = t.TypeVar("InitialisedValue")
4
+
5
+
6
+ class InitialiseNonPickable(t.Generic[InitialisedValue]):
7
+ """
8
+ Use this class to wrap values that you want to be shared within a thread,
9
+ but they are re-initialised for a new processes.
10
+
11
+ Initialiser for the value still needs to be pickable.
12
+ """
13
+
14
+ def __init__(self, initialiser: t.Callable[[], InitialisedValue]) -> None:
15
+ self.value: InitialisedValue | None = None
16
+ self.initialiser = initialiser
17
+
18
+ def __getstate__(self) -> dict[str, t.Any]:
19
+ # During pickling, always return `value` as just None, which is pickable and this class will re-initialise it in `get_value` when called.
20
+ return {"value": None, "initialiser": self.initialiser}
21
+
22
+ def __setstate__(self, d: dict[str, t.Any]) -> None:
23
+ self.value = d["value"]
24
+ self.initialiser = d["initialiser"]
25
+
26
+ def get_value(self) -> InitialisedValue:
27
+ """Use this function to get the wrapped value, which will be initialised if necessary."""
28
+ if self.value is None:
29
+ self.value = self.initialiser()
30
+
31
+ return self.value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.56.1
3
+ Version: 0.56.2.dev136
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -16,7 +16,7 @@ prediction_market_agent_tooling/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-
16
16
  prediction_market_agent_tooling/benchmark/agents.py,sha256=B1-uWdyeN4GGKMWGK_-CcAFJg1m9Y_XuaeIHPB29QR8,3971
17
17
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=MqTiaaJ3cYiOLUVR7OyImLWxcEya3Rl5JyFYW-K0lwM,17097
18
18
  prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9tcKT7JTtwwOp-63zuCBVuc,2880
19
- prediction_market_agent_tooling/config.py,sha256=114f3V9abaok27p5jX3UVr5b5gRUiSxBIYn8Snid34I,6731
19
+ prediction_market_agent_tooling/config.py,sha256=6iB8A4byexiemUajIw2SzRDQ8E8w0catyg7aH_mHpsY,6732
20
20
  prediction_market_agent_tooling/deploy/agent.py,sha256=dpc94DUo8Gq1LdRdw6k78vm_47OeJIfomG9CRVpgzk0,22757
21
21
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
22
22
  prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=kMrIE3wMv_IB6nJd_1DmDXDkEZhsXFOgyTd7JZ0gqHI,13068
@@ -71,7 +71,7 @@ prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256
71
71
  prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py,sha256=-FUSuQQgjcWSSnoFxnlAyTeilY6raJABJVM2QKkFqAY,438
72
72
  prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py,sha256=THMXwFlskvzbjnX_OiYtDSzI8XVFyULWfP2525_9UGc,429
73
73
  prediction_market_agent_tooling/tools/betting_strategies/utils.py,sha256=kpIb-ci67Vc1Yqqaa-_S4OUkbhWSIYog4_Iwp69HU_k,97
74
- prediction_market_agent_tooling/tools/caches/db_cache.py,sha256=KOhwgd4wDiNifJBb3iXRMlxxp7j9l-eSFZvgQ5_Y7xg,12687
74
+ prediction_market_agent_tooling/tools/caches/db_cache.py,sha256=x3v-ZnMpnSzmdwnzubh9oQ7ebExONXjWSFqY48CYQwc,12847
75
75
  prediction_market_agent_tooling/tools/caches/inmemory_cache.py,sha256=tGHHd9HCiE_hCCtPtloHZQdDfBuiow9YsqJNYi2Tx_0,499
76
76
  prediction_market_agent_tooling/tools/contract.py,sha256=s3yo8IbXTcvAJcPfLM0_NbgaEsWwLsPmyVnOgyjq_xI,20919
77
77
  prediction_market_agent_tooling/tools/costs.py,sha256=EaAJ7v9laD4VEV3d8B44M4u3_oEO_H16jRVCdoZ93Uw,954
@@ -89,6 +89,7 @@ prediction_market_agent_tooling/tools/langfuse_.py,sha256=jI_4ROxqo41CCnWGS1vN_A
89
89
  prediction_market_agent_tooling/tools/langfuse_client_utils.py,sha256=B0PhAQyviFnVbtOCYMxYmcCn66cu9nbqAOIAZcdgiRI,5771
90
90
  prediction_market_agent_tooling/tools/omen/reality_accuracy.py,sha256=M1SF7iSW1gVlQSTskdVFTn09uPLST23YeipVIWj54io,2236
91
91
  prediction_market_agent_tooling/tools/parallelism.py,sha256=6Gou0hbjtMZrYvxjTDFUDZuxmE2nqZVbb6hkg1hF82A,1022
92
+ prediction_market_agent_tooling/tools/pickle_utils.py,sha256=PUNRJGdURUnLlzbZoSCiOrikRbEC596hi--Z3q8Wt84,1144
92
93
  prediction_market_agent_tooling/tools/relevant_news_analysis/data_models.py,sha256=95l84aztFaxcRLLcRQ46yKJbIlOEuDAbIGLouyliDzA,1316
93
94
  prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py,sha256=CddJem7tk15NAudJDwmuL8znTycbR-YI8kTNtd3LzG8,5474
94
95
  prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_cache.py,sha256=2yxtBIDyMT_6CsTpZyuIv_2dy2B9WgEOaTT1fSloBu0,3223
@@ -99,8 +100,8 @@ prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=5ldQs1pZe6u
99
100
  prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=Kw2mXNkMTYTEe1MBSTqhQmLoeXtgb6CkmHlcAJvhtqE,3809
100
101
  prediction_market_agent_tooling/tools/utils.py,sha256=1VvunbTmzGzpIlRukFhArreFNxJPbsg4lLtQNk0r2bY,7185
101
102
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=44W8siSLNQxeib98bbwAe7V5C609NHNlUuxwuWIRDiY,11838
102
- prediction_market_agent_tooling-0.56.1.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
103
- prediction_market_agent_tooling-0.56.1.dist-info/METADATA,sha256=fGK0gWUcUB0hphd3qfYiurnr3dl549L6qQiYKgCpczM,8106
104
- prediction_market_agent_tooling-0.56.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
105
- prediction_market_agent_tooling-0.56.1.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
106
- prediction_market_agent_tooling-0.56.1.dist-info/RECORD,,
103
+ prediction_market_agent_tooling-0.56.2.dev136.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
104
+ prediction_market_agent_tooling-0.56.2.dev136.dist-info/METADATA,sha256=vtNRo-GxixSshRSkmcyqEtshchlB4-rwVWS2mDrNiA4,8113
105
+ prediction_market_agent_tooling-0.56.2.dev136.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
106
+ prediction_market_agent_tooling-0.56.2.dev136.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
107
+ prediction_market_agent_tooling-0.56.2.dev136.dist-info/RECORD,,