prediction-market-agent-tooling 0.36.0__tar.gz → 0.37.0__tar.gz

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 (74) hide show
  1. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/PKG-INFO +3 -1
  2. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/config.py +7 -0
  3. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/omen/omen.py +29 -15
  4. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +21 -10
  5. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/balances.py +4 -0
  6. prediction_market_agent_tooling-0.37.0/prediction_market_agent_tooling/tools/image_gen/image_gen.py +49 -0
  7. prediction_market_agent_tooling-0.37.0/prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py +30 -0
  8. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/pyproject.toml +3 -1
  9. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/LICENSE +0 -0
  10. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/README.md +0 -0
  11. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/erc20.abi.json +0 -0
  12. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_dxdao.abi.json +0 -0
  13. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_fpmm.abi.json +0 -0
  14. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_fpmm_conditionaltokens.abi.json +0 -0
  15. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_fpmm_factory.abi.json +0 -0
  16. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_kleros.abi.json +0 -0
  17. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_oracle.abi.json +0 -0
  18. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/omen_realitio.abi.json +0 -0
  19. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/abis/wxdai.abi.json +0 -0
  20. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/benchmark/__init__.py +0 -0
  21. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/benchmark/agents.py +0 -0
  22. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/benchmark/benchmark.py +0 -0
  23. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/benchmark/utils.py +0 -0
  24. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/deploy/agent.py +0 -0
  25. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/deploy/agent_example.py +0 -0
  26. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/deploy/constants.py +0 -0
  27. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/deploy/gcp/deploy.py +0 -0
  28. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py +0 -0
  29. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/deploy/gcp/utils.py +0 -0
  30. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/gtypes.py +0 -0
  31. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/loggers.py +0 -0
  32. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/agent_market.py +0 -0
  33. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/categorize.py +0 -0
  34. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/data_models.py +0 -0
  35. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/manifold/__init__.py +0 -0
  36. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/manifold/api.py +0 -0
  37. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/manifold/data_models.py +0 -0
  38. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/manifold/manifold.py +0 -0
  39. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/manifold/utils.py +0 -0
  40. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/markets.py +0 -0
  41. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/omen/__init__.py +0 -0
  42. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/omen/data_models.py +0 -0
  43. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/omen/omen_contracts.py +0 -0
  44. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/omen/omen_resolving.py +0 -0
  45. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/polymarket/api.py +0 -0
  46. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/polymarket/data_models.py +0 -0
  47. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/polymarket/data_models_web.py +0 -0
  48. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/polymarket/polymarket.py +0 -0
  49. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/markets/polymarket/utils.py +0 -0
  50. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/langfuse/langfuse_wrapper.py +0 -0
  51. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/markets/manifold.py +0 -0
  52. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/markets/omen.py +0 -0
  53. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/markets/polymarket.py +0 -0
  54. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/monitor.py +0 -0
  55. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/monitor_app.py +0 -0
  56. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/monitor/monitor_settings.py +0 -0
  57. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/py.typed +0 -0
  58. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +0 -0
  59. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +0 -0
  60. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py +0 -0
  61. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py +0 -0
  62. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/cache.py +0 -0
  63. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/contract.py +0 -0
  64. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/costs.py +0 -0
  65. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/gnosis_rpc.py +0 -0
  66. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/google.py +0 -0
  67. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/hexbytes_custom.py +0 -0
  68. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/is_predictable.py +0 -0
  69. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/parallelism.py +0 -0
  70. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/safe.py +0 -0
  71. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/singleton.py +0 -0
  72. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/streamlit_user_login.py +0 -0
  73. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/utils.py +0 -0
  74. {prediction_market_agent_tooling-0.36.0 → prediction_market_agent_tooling-0.37.0}/prediction_market_agent_tooling/tools/web3_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.36.0
3
+ Version: 0.37.0
4
4
  Summary: Tools to benchmark, deploy and monitor prediction market agents.
5
5
  Author: Gnosis
6
6
  Requires-Python: >=3.10,<3.12
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3.10
9
9
  Classifier: Programming Language :: Python :: 3.11
10
10
  Provides-Extra: google
11
11
  Provides-Extra: langchain
12
+ Provides-Extra: openai
12
13
  Requires-Dist: autoflake (>=2.2.1,<3.0.0)
13
14
  Requires-Dist: cron-validator (>=1.0.8,<2.0.0)
14
15
  Requires-Dist: eth-account (>=0.8.0,<0.9.0)
@@ -25,6 +26,7 @@ Requires-Dist: langchain-openai (>=0.0.5,<0.0.6) ; extra == "langchain"
25
26
  Requires-Dist: langfuse (>=2.27.1,<3.0.0)
26
27
  Requires-Dist: loguru (>=0.7.2,<0.8.0)
27
28
  Requires-Dist: numpy (>=1.26.4,<2.0.0)
29
+ Requires-Dist: openai (>=1.0.0,<2.0.0) ; extra == "openai"
28
30
  Requires-Dist: prompt-toolkit (>=3.0.43,<4.0.0)
29
31
  Requires-Dist: pydantic (>=2.6.1,<3.0.0)
30
32
  Requires-Dist: pydantic-settings (>=2.1.0,<3.0.0)
@@ -27,6 +27,7 @@ class APIKeys(BaseSettings):
27
27
  BET_FROM_PRIVATE_KEY: t.Optional[PrivateKey] = None
28
28
  SAFE_ADDRESS: t.Optional[ChecksumAddress] = None
29
29
  OPENAI_API_KEY: t.Optional[SecretStr] = None
30
+ GRAPH_API_KEY: t.Optional[SecretStr] = None
30
31
 
31
32
  GOOGLE_SEARCH_API_KEY: t.Optional[SecretStr] = None
32
33
  GOOGLE_SEARCH_ENGINE_ID: t.Optional[SecretStr] = None
@@ -72,6 +73,12 @@ class APIKeys(BaseSettings):
72
73
  self.OPENAI_API_KEY, "OPENAI_API_KEY missing in the environment."
73
74
  )
74
75
 
76
+ @property
77
+ def graph_api_key(self) -> SecretStr:
78
+ return check_not_none(
79
+ self.GRAPH_API_KEY, "GRAPH_API_KEY missing in the environment."
80
+ )
81
+
75
82
  @property
76
83
  def google_search_api_key(self) -> SecretStr:
77
84
  return check_not_none(
@@ -10,7 +10,6 @@ from prediction_market_agent_tooling.gtypes import (
10
10
  ChecksumAddress,
11
11
  HexAddress,
12
12
  HexStr,
13
- OmenOutcomeToken,
14
13
  OutcomeStr,
15
14
  Probability,
16
15
  Wei,
@@ -84,7 +83,6 @@ class OmenAgentMarket(AgentMarket):
84
83
  finalized_time: datetime | None
85
84
  created_time: datetime
86
85
  close_time: datetime
87
- outcome_token_amounts: list[OmenOutcomeToken]
88
86
  fee: float # proportion, from 0 to 1
89
87
 
90
88
  INVALID_MARKET_ANSWER: HexStr = HexStr(
@@ -144,6 +142,7 @@ class OmenAgentMarket(AgentMarket):
144
142
  amount: BetAmount,
145
143
  omen_auto_deposit: bool = True,
146
144
  web3: Web3 | None = None,
145
+ api_keys: APIKeys | None = None,
147
146
  ) -> None:
148
147
  if not self.can_be_traded():
149
148
  raise ValueError(
@@ -153,7 +152,7 @@ class OmenAgentMarket(AgentMarket):
153
152
  raise ValueError(f"Omen bets are made in xDai. Got {amount.currency}.")
154
153
  amount_xdai = xDai(amount.amount)
155
154
  binary_omen_buy_outcome_tx(
156
- api_keys=APIKeys(),
155
+ api_keys=api_keys if api_keys is not None else APIKeys(),
157
156
  amount=amount_xdai,
158
157
  market=self,
159
158
  binary_outcome=outcome,
@@ -161,20 +160,34 @@ class OmenAgentMarket(AgentMarket):
161
160
  web3=web3,
162
161
  )
163
162
 
163
+ def buy_tokens(
164
+ self,
165
+ outcome: bool,
166
+ amount: TokenAmount,
167
+ web3: Web3 | None = None,
168
+ api_keys: APIKeys | None = None,
169
+ ) -> None:
170
+ return self.place_bet(
171
+ outcome=outcome,
172
+ amount=amount,
173
+ web3=web3,
174
+ api_keys=api_keys,
175
+ )
176
+
164
177
  def calculate_sell_amount_in_collateral(
165
- self, amount: TokenAmount, outcome: bool
178
+ self, amount: TokenAmount, outcome: bool, web3: Web3 | None = None
166
179
  ) -> xDai:
167
- if len(self.outcome_token_amounts) != 2:
168
- raise ValueError(
169
- f"Market {self.id} has {len(self.outcome_token_amounts)} "
170
- f"outcomes. This method only supports binary markets."
171
- )
172
- sell_index = self.yes_index if outcome else self.no_index
173
- other_index = self.no_index if outcome else self.yes_index
180
+ pool_balance = get_conditional_tokens_balance_for_market(
181
+ self, self.market_maker_contract_address_checksummed, web3=web3
182
+ )
183
+
184
+ sell_str = self.outcomes[self.yes_index if outcome else self.no_index]
185
+ other_str = self.outcomes[self.no_index if outcome else self.yes_index]
186
+
174
187
  collateral = calculate_sell_amount_in_collateral(
175
188
  shares_to_sell=amount.amount,
176
- holdings=wei_to_xdai(Wei(self.outcome_token_amounts[sell_index])),
177
- other_holdings=wei_to_xdai(Wei(self.outcome_token_amounts[other_index])),
189
+ holdings=wei_to_xdai(pool_balance[self.get_index_set(sell_str)]),
190
+ other_holdings=wei_to_xdai(pool_balance[self.get_index_set(other_str)]),
178
191
  fee=self.fee,
179
192
  )
180
193
  return xDai(collateral)
@@ -197,6 +210,7 @@ class OmenAgentMarket(AgentMarket):
197
210
  collateral = self.calculate_sell_amount_in_collateral(
198
211
  amount=amount,
199
212
  outcome=outcome,
213
+ web3=web3,
200
214
  )
201
215
  binary_omen_sell_outcome_tx(
202
216
  amount=collateral,
@@ -282,7 +296,6 @@ class OmenAgentMarket(AgentMarket):
282
296
  url=model.url,
283
297
  volume=wei_to_xdai(model.collateralVolume),
284
298
  close_time=model.close_time,
285
- outcome_token_amounts=model.outcomeTokenAmounts,
286
299
  fee=float(wei_to_xdai(model.fee)) if model.fee is not None else 0.0,
287
300
  )
288
301
 
@@ -462,8 +475,9 @@ def omen_buy_outcome_tx(
462
475
  for_address=from_address_checksummed, web3=web3
463
476
  )
464
477
  if auto_deposit and collateral_token_balance < amount_wei:
478
+ deposit_amount_wei = Wei(amount_wei - collateral_token_balance)
465
479
  collateral_token_contract.deposit(
466
- api_keys=api_keys, amount_wei=amount_wei, web3=web3
480
+ api_keys=api_keys, amount_wei=deposit_amount_wei, web3=web3
467
481
  )
468
482
  # Buy shares using the deposited xDai in the collateral token.
469
483
  market_contract.buy(
@@ -6,6 +6,7 @@ import tenacity
6
6
  from eth_typing import ChecksumAddress
7
7
  from subgrounds import FieldPath, Subgrounds
8
8
 
9
+ from prediction_market_agent_tooling.config import APIKeys
9
10
  from prediction_market_agent_tooling.gtypes import HexAddress, HexBytes, Wei, wei_type
10
11
  from prediction_market_agent_tooling.loggers import logger
11
12
  from prediction_market_agent_tooling.markets.agent_market import FilterBy, SortBy
@@ -29,13 +30,11 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
29
30
  Class responsible for handling interactions with Omen subgraphs (trades, conditionalTokens).
30
31
  """
31
32
 
32
- OMEN_TRADES_SUBGRAPH = "https://api.thegraph.com/subgraphs/name/protofire/omen-xdai"
33
- CONDITIONAL_TOKENS_SUBGRAPH = (
34
- "https://api.thegraph.com/subgraphs/name/gnosis/conditional-tokens-gc"
35
- )
36
- REALITYETH_GRAPH_URL = (
37
- "https://api.thegraph.com/subgraphs/name/realityeth/realityeth-gnosis"
38
- )
33
+ OMEN_TRADES_SUBGRAPH = "https://gateway-arbitrum.network.thegraph.com/api/{graph_api_key}/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz"
34
+
35
+ CONDITIONAL_TOKENS_SUBGRAPH = "https://gateway-arbitrum.network.thegraph.com/api/{graph_api_key}/subgraphs/id/7s9rGBffUTL8kDZuxvvpuc46v44iuDarbrADBFw5uVp2"
36
+
37
+ REALITYETH_GRAPH_URL = "https://gateway-arbitrum.network.thegraph.com/api/{graph_api_key}/subgraphs/id/E7ymrCnNcQdAAgLbdFWzGE5mvr5Mb5T9VfT43FqA7bNh"
39
38
 
40
39
  INVALID_ANSWER = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
41
40
 
@@ -49,12 +48,24 @@ class OmenSubgraphHandler(metaclass=SingletonMeta):
49
48
  after=lambda x: logger.debug(f"query_json failed, {x.attempt_number=}."),
50
49
  )(self.sg.query_json)
51
50
 
51
+ keys = APIKeys()
52
+
52
53
  # Load the subgraph
53
- self.trades_subgraph = self.sg.load_subgraph(self.OMEN_TRADES_SUBGRAPH)
54
+ self.trades_subgraph = self.sg.load_subgraph(
55
+ self.OMEN_TRADES_SUBGRAPH.format(
56
+ graph_api_key=keys.graph_api_key.get_secret_value()
57
+ )
58
+ )
54
59
  self.conditional_tokens_subgraph = self.sg.load_subgraph(
55
- self.CONDITIONAL_TOKENS_SUBGRAPH
60
+ self.CONDITIONAL_TOKENS_SUBGRAPH.format(
61
+ graph_api_key=keys.graph_api_key.get_secret_value()
62
+ )
63
+ )
64
+ self.realityeth_subgraph = self.sg.load_subgraph(
65
+ self.REALITYETH_GRAPH_URL.format(
66
+ graph_api_key=keys.graph_api_key.get_secret_value()
67
+ )
56
68
  )
57
- self.realityeth_subgraph = self.sg.load_subgraph(self.REALITYETH_GRAPH_URL)
58
69
 
59
70
  def _get_fields_for_bets(self, bets_field: FieldPath) -> list[FieldPath]:
60
71
  markets = bets_field.fpmm
@@ -13,6 +13,10 @@ class Balances(BaseModel):
13
13
  xdai: xDai
14
14
  wxdai: xDai
15
15
 
16
+ @property
17
+ def total(self) -> xDai:
18
+ return xDai(self.xdai + self.wxdai)
19
+
16
20
 
17
21
  def get_balances(address: ChecksumAddress, web3: Web3 | None = None) -> Balances:
18
22
  if not web3:
@@ -0,0 +1,49 @@
1
+ import base64
2
+ import io
3
+ import typing as t
4
+
5
+ from PIL import Image
6
+ from PIL.Image import Image as ImageType
7
+
8
+ from prediction_market_agent_tooling.config import APIKeys
9
+ from prediction_market_agent_tooling.tools.utils import check_not_none
10
+
11
+
12
+ def generate_image(
13
+ prompt: str,
14
+ model: str = "dall-e-3",
15
+ size: t.Literal[
16
+ "256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"
17
+ ] = "1024x1024",
18
+ quality: t.Literal["standard", "hd"] = "standard",
19
+ ) -> ImageType:
20
+ try:
21
+ from openai import OpenAI
22
+ except ImportError:
23
+ raise ImportError(
24
+ "openai not installed, please install extras `openai` to use this function."
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]
39
+ )
40
+ image = Image.open(
41
+ io.BytesIO(
42
+ base64.b64decode(
43
+ check_not_none(
44
+ response.b64_json, "Can't be none if response_format is b64_json."
45
+ )
46
+ )
47
+ )
48
+ )
49
+ return image
@@ -0,0 +1,30 @@
1
+ from PIL.Image import Image as ImageType
2
+
3
+ from prediction_market_agent_tooling.config import APIKeys
4
+ from prediction_market_agent_tooling.tools.image_gen.image_gen import generate_image
5
+
6
+
7
+ def rewrite_question_into_image_generation_prompt(question: str) -> str:
8
+ try:
9
+ from langchain_openai import ChatOpenAI
10
+ except ImportError:
11
+ raise ImportError(
12
+ "openai not installed, please install extras `langchain` to use this function."
13
+ )
14
+ llm = ChatOpenAI(
15
+ model="gpt-4-turbo",
16
+ temperature=0.0,
17
+ api_key=APIKeys().openai_api_key.get_secret_value(),
18
+ )
19
+ rewritten = str(
20
+ llm.invoke(
21
+ f"Rewrite this prediction market question '{question}' into a form that will generate nice thumbnail with DALL-E-3."
22
+ "The thumbnail should be catchy and visually appealing. With a large object in the center of the image."
23
+ ).content
24
+ )
25
+ return rewritten
26
+
27
+
28
+ def generate_image_for_market(question: str) -> ImageType:
29
+ prompt = rewrite_question_into_image_generation_prompt(question)
30
+ return generate_image(prompt)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "prediction-market-agent-tooling"
3
- version = "0.36.0"
3
+ version = "0.37.0"
4
4
  description = "Tools to benchmark, deploy and monitor prediction market agents."
5
5
  authors = ["Gnosis"]
6
6
  readme = "README.md"
@@ -41,8 +41,10 @@ eth-account = "^0.8.0"
41
41
  prompt-toolkit = "^3.0.43"
42
42
  safe-cli = "^1.0.0"
43
43
  langfuse = "^2.27.1"
44
+ openai = { version = "^1.0.0", optional = true}
44
45
 
45
46
  [tool.poetry.extras]
47
+ openai = ["openai"]
46
48
  langchain = ["langchain", "langchain-openai"]
47
49
  google = ["google-api-python-client"]
48
50