prediction-market-agent-tooling 0.64.5__py3-none-any.whl → 0.64.6__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.
@@ -28,6 +28,8 @@ from prediction_market_agent_tooling.tools.datetime_utc import DatetimeUTC
28
28
  from prediction_market_agent_tooling.tools.db.db_manager import DBManager
29
29
  from prediction_market_agent_tooling.tools.utils import utcnow
30
30
 
31
+ DB_CACHE_LOG_PREFIX = "[db-cache]"
32
+
31
33
  FunctionT = TypeVar("FunctionT", bound=Callable[..., Any])
32
34
 
33
35
 
@@ -173,7 +175,7 @@ def db_cache(
173
175
  if cached_result:
174
176
  logger.info(
175
177
  # Keep the special [case-hit] identifier so we can easily track it in GCP.
176
- f"[cache-hit] Cache hit for {full_function_name} with args {args_dict} and output {cached_result.result}"
178
+ f"{DB_CACHE_LOG_PREFIX} [cache-hit] Cache hit for {full_function_name} with args {args_dict} and output {cached_result.result}"
177
179
  )
178
180
  if is_pydantic_model:
179
181
  # If the output contains any Pydantic models, we need to initialise them.
@@ -184,7 +186,7 @@ def db_cache(
184
186
  except ValueError as e:
185
187
  # In case of backward-incompatible pydantic model, just treat it as cache miss, to not error out.
186
188
  logger.warning(
187
- f"Can not validate {cached_result=} into {return_type=} because {e=}, treating as cache miss."
189
+ f"{DB_CACHE_LOG_PREFIX} [cache-miss] Can not validate {cached_result=} into {return_type=} because {e=}, treating as cache miss."
188
190
  )
189
191
  cached_result = None
190
192
  else:
@@ -194,7 +196,7 @@ def db_cache(
194
196
  computed_result = func(*args, **kwargs)
195
197
  # Keep the special [case-miss] identifier so we can easily track it in GCP.
196
198
  logger.info(
197
- f"[cache-miss] Cache miss for {full_function_name} with args {args_dict}, computed the output {computed_result}"
199
+ f"{DB_CACHE_LOG_PREFIX} [cache-miss] Cache miss for {full_function_name} with args {args_dict}, computed the output {computed_result}"
198
200
  )
199
201
 
200
202
  # If postgres access was specified, save it.
@@ -212,16 +214,18 @@ def db_cache(
212
214
  with DBManager(
213
215
  api_keys.sqlalchemy_db_url.get_secret_value()
214
216
  ).get_session() as session:
215
- logger.info(f"Saving {cache_entry} into database.")
217
+ logger.info(
218
+ f"{DB_CACHE_LOG_PREFIX} [cache-info] Saving {cache_entry} into database."
219
+ )
216
220
  session.add(cache_entry)
217
221
  session.commit()
218
222
  except (DataError, psycopg2.errors.UntranslatableCharacter) as e:
219
223
  (logger.error if log_error_on_unsavable_data else logger.warning)(
220
- f"Failed to save {cache_entry} into database, ignoring, because: {e}"
224
+ f"{DB_CACHE_LOG_PREFIX} [cache-error] Failed to save {cache_entry} into database, ignoring, because: {e}"
221
225
  )
222
226
  except Exception:
223
227
  logger.exception(
224
- f"Failed to save {cache_entry} into database, ignoring."
228
+ f"{DB_CACHE_LOG_PREFIX} [cache-error] Failed to save {cache_entry} into database, ignoring."
225
229
  )
226
230
 
227
231
  return computed_result
@@ -23,25 +23,27 @@ def generate_image(
23
23
  raise ImportError(
24
24
  "openai not installed, please install extras `openai` to use this function."
25
25
  )
26
- response = (
27
- OpenAI(
28
- api_key=APIKeys().openai_api_key.get_secret_value(),
29
- )
30
- .images.generate(
31
- model=model,
32
- prompt=prompt,
33
- size=size,
34
- quality=quality,
35
- response_format="b64_json",
36
- n=1,
37
- )
38
- .data[0]
26
+ response = OpenAI(
27
+ api_key=APIKeys().openai_api_key.get_secret_value(),
28
+ ).images.generate(
29
+ model=model,
30
+ prompt=prompt,
31
+ size=size,
32
+ quality=quality,
33
+ response_format="b64_json",
34
+ n=1,
39
35
  )
36
+
37
+ if response.data is None or len(response.data) == 0:
38
+ raise ValueError("No image data returned from the API.")
39
+
40
+ image_data = response.data[0]
41
+
40
42
  image = Image.open(
41
43
  io.BytesIO(
42
44
  base64.b64decode(
43
45
  check_not_none(
44
- response.b64_json, "Can't be none if response_format is b64_json."
46
+ image_data.b64_json, "Can't be none if response_format is b64_json."
45
47
  )
46
48
  )
47
49
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.64.5
3
+ Version: 0.64.6
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.13
@@ -86,7 +86,7 @@ prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256
86
86
  prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py,sha256=-FUSuQQgjcWSSnoFxnlAyTeilY6raJABJVM2QKkFqAY,438
87
87
  prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py,sha256=THMXwFlskvzbjnX_OiYtDSzI8XVFyULWfP2525_9UGc,429
88
88
  prediction_market_agent_tooling/tools/betting_strategies/utils.py,sha256=68zFWUj43GUaSpOPowVrbI-t6qbCE29RsVHNzCVuJ9U,175
89
- prediction_market_agent_tooling/tools/caches/db_cache.py,sha256=e7CLFPTlxYFx0pM3x5sWyn_g9pIigPSvrP0mMmiOhUg,11859
89
+ prediction_market_agent_tooling/tools/caches/db_cache.py,sha256=rZIGhgijquwwPtp_qncSAPR1SDF2XxIVZL1ir0fgzWw,12127
90
90
  prediction_market_agent_tooling/tools/caches/inmemory_cache.py,sha256=ZW5iI5rmjqeAebu5T7ftRnlkxiL02IC-MxCfDB80x7w,1506
91
91
  prediction_market_agent_tooling/tools/caches/serializers.py,sha256=vFDx4fsPxclXp2q0sv27j4al_M_Tj9aR2JJP-xNHQXA,2151
92
92
  prediction_market_agent_tooling/tools/contract.py,sha256=Yex8MVYvdBTMZLESLqKpwEyT8EGAfkJRri5kCaPqrBM,21235
@@ -98,7 +98,7 @@ prediction_market_agent_tooling/tools/db/db_manager.py,sha256=GtzHH1NLl8HwqC8Z7s
98
98
  prediction_market_agent_tooling/tools/google_utils.py,sha256=D-6FB2HRtmxaKZJ_Za-qj6VZCp5XU18rF4wLMMrqEUg,2557
99
99
  prediction_market_agent_tooling/tools/hexbytes_custom.py,sha256=ytwr4N8t-9UF1F4wXsln3IV1HBKgaYirsErc3NsKL-M,2119
100
100
  prediction_market_agent_tooling/tools/httpx_cached_client.py,sha256=RxD-hwtZCMctnMwfzy8t51W9Z9gxFGtDYxBIMChazpc,406
101
- prediction_market_agent_tooling/tools/image_gen/image_gen.py,sha256=HzRwBx62hOXBOmrtpkXaP9Qq1Ku03uUGdREocyjLQ_k,1266
101
+ prediction_market_agent_tooling/tools/image_gen/image_gen.py,sha256=i7ole0NMprELk-I3qJQLqFNZjiqM1w6s11IqM4Ctaqw,1349
102
102
  prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py,sha256=jgOow4zw6g8dIJrog6Tp-3NQs4wjUJ3VgVKyMQv-0QM,1286
103
103
  prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py,sha256=CTTMfTvs_8PH4kAtlQby2aeEKwgpmxtuGbd4oYIdJ2A,1201
104
104
  prediction_market_agent_tooling/tools/is_invalid.py,sha256=TAHQXiiusAU45xJ11ZyEP7PnEfcjfzVG7qHRbsHiAd0,5335
@@ -124,8 +124,8 @@ prediction_market_agent_tooling/tools/tokens/usd.py,sha256=yuW8iPPtcpP4eLH2nORMD
124
124
  prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
125
125
  prediction_market_agent_tooling/tools/utils.py,sha256=AC2a68jwASMWuQi-w8twl8b_M52YwrEJ81abmuEaqMY,6661
126
126
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=zRq-eeBGWt8uUGN9G_WfjmJ0eVvO8aWE9S0Pz_Y6AOA,12342
127
- prediction_market_agent_tooling-0.64.5.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
128
- prediction_market_agent_tooling-0.64.5.dist-info/METADATA,sha256=EPfSPw78Gf7zr3qLdKFha7YltbMwA-EvW4PkI8lykMU,8741
129
- prediction_market_agent_tooling-0.64.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
130
- prediction_market_agent_tooling-0.64.5.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
131
- prediction_market_agent_tooling-0.64.5.dist-info/RECORD,,
127
+ prediction_market_agent_tooling-0.64.6.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
128
+ prediction_market_agent_tooling-0.64.6.dist-info/METADATA,sha256=2r_sU6cc-W140QZ1PCjAsOpNpua3ocBXIFDwXED2zq4,8741
129
+ prediction_market_agent_tooling-0.64.6.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
130
+ prediction_market_agent_tooling-0.64.6.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
131
+ prediction_market_agent_tooling-0.64.6.dist-info/RECORD,,