prediction-market-agent-tooling 0.64.11__py3-none-any.whl → 0.64.11.dev653__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.
- prediction_market_agent_tooling/config.py +15 -0
- prediction_market_agent_tooling/logprobs_parser.py +33 -71
- prediction_market_agent_tooling/markets/data_models.py +0 -2
- {prediction_market_agent_tooling-0.64.11.dist-info → prediction_market_agent_tooling-0.64.11.dev653.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.64.11.dist-info → prediction_market_agent_tooling-0.64.11.dev653.dist-info}/RECORD +8 -8
- {prediction_market_agent_tooling-0.64.11.dist-info → prediction_market_agent_tooling-0.64.11.dev653.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.64.11.dist-info → prediction_market_agent_tooling-0.64.11.dev653.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.64.11.dist-info → prediction_market_agent_tooling-0.64.11.dev653.dist-info}/entry_points.txt +0 -0
@@ -278,9 +278,16 @@ class RPCConfig(BaseSettings):
|
|
278
278
|
env_file=".env", env_file_encoding="utf-8", extra="ignore"
|
279
279
|
)
|
280
280
|
|
281
|
+
ETHEREUM_RPC_URL: URI = Field(default=URI("https://ethereum-rpc.publicnode.com"))
|
281
282
|
GNOSIS_RPC_URL: URI = Field(default=URI("https://rpc.gnosischain.com"))
|
282
283
|
CHAIN_ID: ChainID = Field(default=ChainID(100))
|
283
284
|
|
285
|
+
@property
|
286
|
+
def ethereum_rpc_url(self) -> URI:
|
287
|
+
return check_not_none(
|
288
|
+
self.ETHEREUM_RPC_URL, "ETHEREUM_RPC_URL missing in the environment."
|
289
|
+
)
|
290
|
+
|
284
291
|
@property
|
285
292
|
def gnosis_rpc_url(self) -> URI:
|
286
293
|
return check_not_none(
|
@@ -291,6 +298,14 @@ class RPCConfig(BaseSettings):
|
|
291
298
|
def chain_id(self) -> ChainID:
|
292
299
|
return check_not_none(self.CHAIN_ID, "CHAIN_ID missing in the environment.")
|
293
300
|
|
301
|
+
def chain_id_to_rpc_url(self, chain_id: ChainID) -> URI:
|
302
|
+
if chain_id == ChainID(1):
|
303
|
+
return self.ethereum_rpc_url
|
304
|
+
elif chain_id == ChainID(100):
|
305
|
+
return self.gnosis_rpc_url
|
306
|
+
else:
|
307
|
+
raise ValueError(f"Unsupported chain ID: {chain_id}")
|
308
|
+
|
294
309
|
def get_web3(self) -> Web3:
|
295
310
|
return Web3(Web3.HTTPProvider(self.gnosis_rpc_url))
|
296
311
|
|
@@ -1,47 +1,29 @@
|
|
1
1
|
import math
|
2
2
|
from itertools import product
|
3
|
-
from typing import Any, Tuple
|
3
|
+
from typing import Any, Tuple
|
4
4
|
|
5
|
-
from pydantic import BaseModel
|
6
|
-
from pydantic.fields import FieldInfo
|
7
|
-
from pydantic.type_adapter import TypeAdapter
|
5
|
+
from pydantic import BaseModel
|
8
6
|
|
9
7
|
from prediction_market_agent_tooling.loggers import logger
|
10
8
|
|
11
9
|
|
12
|
-
class
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
class FieldLogprobs(BaseModel):
|
19
|
-
key: str
|
20
|
-
logprobs: list[LogprobDetail]
|
10
|
+
class LogprobKey(BaseModel):
|
11
|
+
name: str
|
12
|
+
key_type: type
|
13
|
+
valid_values: set[Any] | None
|
21
14
|
|
22
15
|
|
23
16
|
class LogprobsParser:
|
24
|
-
def __init__(
|
25
|
-
self,
|
26
|
-
skip_fields: list[str] | None = None,
|
27
|
-
max_top_logprobs_length: int = 3,
|
28
|
-
max_logprobs_length: int = 5,
|
29
|
-
):
|
30
|
-
base_skip_fields = ["logprobs"]
|
31
|
-
self.skip_fields = base_skip_fields + (skip_fields or [])
|
32
|
-
self.max_top_logprobs_length = max_top_logprobs_length
|
33
|
-
self.max_logprobs_length = max_logprobs_length
|
34
|
-
|
35
17
|
def _get_logprobs_key_index(
|
36
|
-
self, logprobs: list[dict[str, Any]],
|
18
|
+
self, logprobs: list[dict[str, Any]], key: LogprobKey
|
37
19
|
) -> int:
|
38
20
|
key_candidate = ""
|
39
21
|
for i, token in enumerate(logprobs):
|
40
|
-
if token["token"] in
|
22
|
+
if token["token"] in key.name:
|
41
23
|
key_candidate = key_candidate + token["token"]
|
42
24
|
else:
|
43
25
|
key_candidate = ""
|
44
|
-
if key_candidate ==
|
26
|
+
if key_candidate == key.name:
|
45
27
|
return i
|
46
28
|
|
47
29
|
return -1
|
@@ -63,25 +45,19 @@ class LogprobsParser:
|
|
63
45
|
for i in range(result_start_index, len(logprobs))
|
64
46
|
if logprobs[i]["token"] in {",", '"', ",\n", "\",\n'", '",\n'}
|
65
47
|
),
|
66
|
-
|
48
|
+
-1,
|
67
49
|
)
|
68
50
|
return result_start_index + 1, result_end_index
|
69
51
|
|
70
|
-
def _is_correct_type(self, token: str, key_type: type
|
71
|
-
if key_type is None:
|
72
|
-
return True
|
73
|
-
|
52
|
+
def _is_correct_type(self, token: str, key_type: type) -> bool:
|
74
53
|
try:
|
75
|
-
|
54
|
+
key_type(token)
|
76
55
|
return True
|
77
|
-
except
|
56
|
+
except ValueError:
|
78
57
|
return False
|
79
58
|
|
80
59
|
def _parse_valid_tokens_with__agg_probs(
|
81
|
-
self,
|
82
|
-
logprobs_list: list[tuple[dict[str, Any]]],
|
83
|
-
field_info: FieldInfo,
|
84
|
-
top_logprobs: int,
|
60
|
+
self, logprobs_list: list[tuple[dict[str, Any]]], key: LogprobKey
|
85
61
|
) -> list[dict[str, Any]]:
|
86
62
|
results: list[dict[str, Any]] = [
|
87
63
|
{
|
@@ -97,59 +73,45 @@ class LogprobsParser:
|
|
97
73
|
results_filtered: list[dict[str, Any]] = [
|
98
74
|
result
|
99
75
|
for result in results
|
100
|
-
if self._is_correct_type(result["token"],
|
76
|
+
if self._is_correct_type(result["token"], key.key_type)
|
77
|
+
and (key.valid_values is None or result["token"] in key.valid_values)
|
101
78
|
]
|
102
79
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
return (
|
107
|
-
sorted_results[:top_logprobs]
|
108
|
-
if len(sorted_results) > top_logprobs
|
109
|
-
else sorted_results
|
110
|
-
)
|
80
|
+
return sorted(results_filtered, key=lambda x: x["logprob"], reverse=True)[
|
81
|
+
: len(logprobs_list[0])
|
82
|
+
]
|
111
83
|
|
112
84
|
def parse_logprobs(
|
113
|
-
self, logprobs: list[dict[str, Any]],
|
114
|
-
) -> list[
|
85
|
+
self, logprobs: list[dict[str, Any]], keys: list[LogprobKey]
|
86
|
+
) -> list[dict[str, Any]]:
|
115
87
|
results_for_keys = []
|
116
88
|
|
117
|
-
for
|
118
|
-
|
119
|
-
continue
|
120
|
-
|
121
|
-
key_index = self._get_logprobs_key_index(logprobs, field_name)
|
122
|
-
|
89
|
+
for key in keys:
|
90
|
+
key_index = self._get_logprobs_key_index(logprobs, key)
|
123
91
|
if key_index < 0:
|
124
|
-
logger.warning(f"Key {
|
92
|
+
logger.warning(f"Key {key.name} not found in logprobs")
|
125
93
|
continue
|
126
94
|
|
127
95
|
(
|
128
96
|
result_start_index,
|
129
97
|
result_end_index,
|
130
98
|
) = self._get_logprobs_indexes_for_result(logprobs, key_index)
|
131
|
-
|
132
99
|
if result_start_index < 0 or result_end_index < 0:
|
133
|
-
logger.warning(f"Error in parsing result for {
|
100
|
+
logger.warning(f"Error in parsing result for {key.name} in logprobs")
|
134
101
|
continue
|
135
102
|
|
136
|
-
|
137
|
-
logprobs[i]["top_logprobs"]
|
103
|
+
valid_logprobs = [
|
104
|
+
logprobs[i]["top_logprobs"]
|
138
105
|
for i in range(result_start_index, result_end_index)
|
139
|
-
if logprobs[i]["top_logprobs"] is not None
|
140
106
|
]
|
141
107
|
|
142
|
-
parsed_logprobs_data = self._parse_valid_tokens_with__agg_probs(
|
143
|
-
list(product(*valid_logprobs_raw[: self.max_logprobs_length])),
|
144
|
-
field_info,
|
145
|
-
min(len(sublist) for sublist in valid_logprobs_raw),
|
146
|
-
)
|
147
|
-
|
148
108
|
results_for_keys.append(
|
149
|
-
|
150
|
-
key
|
151
|
-
logprobs
|
152
|
-
|
109
|
+
{
|
110
|
+
"key": key.name,
|
111
|
+
"logprobs": self._parse_valid_tokens_with__agg_probs(
|
112
|
+
list(product(*valid_logprobs)), key
|
113
|
+
),
|
114
|
+
}
|
153
115
|
)
|
154
116
|
|
155
117
|
return results_for_keys
|
@@ -10,7 +10,6 @@ from prediction_market_agent_tooling.gtypes import (
|
|
10
10
|
OutcomeToken,
|
11
11
|
Probability,
|
12
12
|
)
|
13
|
-
from prediction_market_agent_tooling.logprobs_parser import FieldLogprobs
|
14
13
|
from prediction_market_agent_tooling.tools.utils import DatetimeUTC
|
15
14
|
|
16
15
|
|
@@ -78,7 +77,6 @@ class ProbabilisticAnswer(BaseModel):
|
|
78
77
|
p_yes: Probability
|
79
78
|
confidence: float
|
80
79
|
reasoning: str | None = None
|
81
|
-
logprobs: list[FieldLogprobs] | None = None
|
82
80
|
|
83
81
|
@property
|
84
82
|
def p_no(self) -> Probability:
|
@@ -22,7 +22,7 @@ prediction_market_agent_tooling/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-
|
|
22
22
|
prediction_market_agent_tooling/benchmark/agents.py,sha256=B1-uWdyeN4GGKMWGK_-CcAFJg1m9Y_XuaeIHPB29QR8,3971
|
23
23
|
prediction_market_agent_tooling/benchmark/benchmark.py,sha256=MqTiaaJ3cYiOLUVR7OyImLWxcEya3Rl5JyFYW-K0lwM,17097
|
24
24
|
prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9tcKT7JTtwwOp-63zuCBVuc,2880
|
25
|
-
prediction_market_agent_tooling/config.py,sha256=
|
25
|
+
prediction_market_agent_tooling/config.py,sha256=h2aJITajiqtnuWbIZSYBGBAiSuU_apwf_kUseDsFaog,10742
|
26
26
|
prediction_market_agent_tooling/deploy/agent.py,sha256=dobqPUQkaDPhsvMmXwibNKu4hSSTXTvmfa3F46ylLBc,26560
|
27
27
|
prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
|
28
28
|
prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=p25t7VU7I4hSkSl6SpzI_W55kLbYEySQdBqeschmARY,12918
|
@@ -36,12 +36,12 @@ prediction_market_agent_tooling/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeu
|
|
36
36
|
prediction_market_agent_tooling/jobs/jobs_models.py,sha256=8vYafsK1cqMWQtjBoq9rruroF84xAVD00vBTMWH6QMg,2166
|
37
37
|
prediction_market_agent_tooling/jobs/omen/omen_jobs.py,sha256=Pf6QxPXGyie-2l_wZUjaGPTjZTlpv50_JhP40mULBaU,5048
|
38
38
|
prediction_market_agent_tooling/loggers.py,sha256=hF_n-E5iMSqh3dY5G6LkQRHyReMYGPNTLu82dDFh1PU,5187
|
39
|
-
prediction_market_agent_tooling/logprobs_parser.py,sha256=
|
39
|
+
prediction_market_agent_tooling/logprobs_parser.py,sha256=sXIwkA5O_fpBP3Civ891rTa0yRcbs3qNcNsY5MJpL68,3734
|
40
40
|
prediction_market_agent_tooling/markets/agent_market.py,sha256=1NomilM0GCXcRq_1N_cr2AbSK5ONTowFeRbrhc7V5zE,14929
|
41
41
|
prediction_market_agent_tooling/markets/base_subgraph_handler.py,sha256=7RaYO_4qAmQ6ZGM8oPK2-CkiJfKmV9MxM-rJlduaecU,1971
|
42
42
|
prediction_market_agent_tooling/markets/blockchain_utils.py,sha256=qm21scopQ6dfewkoqQF6lWLDGg2BblsKUdC9aG93Hmc,2249
|
43
43
|
prediction_market_agent_tooling/markets/categorize.py,sha256=jsoHWvZk9pU6n17oWSCcCxNNYVwlb_NXsZxKRI7vmsk,1301
|
44
|
-
prediction_market_agent_tooling/markets/data_models.py,sha256=
|
44
|
+
prediction_market_agent_tooling/markets/data_models.py,sha256=_R9Hr5zwGLpZLPXq0Jo2wZRNRQyOnSi3WVQJZ81syuk,4541
|
45
45
|
prediction_market_agent_tooling/markets/manifold/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
46
46
|
prediction_market_agent_tooling/markets/manifold/api.py,sha256=ih92UTZdSbmy6tTUgSCps_HqYQXpMSsfne5Np5znVEM,7217
|
47
47
|
prediction_market_agent_tooling/markets/manifold/data_models.py,sha256=DWNvK6Qdxz7Lxqpe-qQE4X-mw8GFGpukGfnjT_ohcZA,6364
|
@@ -125,8 +125,8 @@ prediction_market_agent_tooling/tools/tokens/usd.py,sha256=yuW8iPPtcpP4eLH2nORMD
|
|
125
125
|
prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
|
126
126
|
prediction_market_agent_tooling/tools/utils.py,sha256=AC2a68jwASMWuQi-w8twl8b_M52YwrEJ81abmuEaqMY,6661
|
127
127
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=zRq-eeBGWt8uUGN9G_WfjmJ0eVvO8aWE9S0Pz_Y6AOA,12342
|
128
|
-
prediction_market_agent_tooling-0.64.11.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
129
|
-
prediction_market_agent_tooling-0.64.11.dist-info/METADATA,sha256=
|
130
|
-
prediction_market_agent_tooling-0.64.11.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
131
|
-
prediction_market_agent_tooling-0.64.11.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
132
|
-
prediction_market_agent_tooling-0.64.11.dist-info/RECORD,,
|
128
|
+
prediction_market_agent_tooling-0.64.11.dev653.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
129
|
+
prediction_market_agent_tooling-0.64.11.dev653.dist-info/METADATA,sha256=dvLhCSpUWXLrS13lCWL6nhcQZ5Ql7ogyRqf0sjr5p1s,8749
|
130
|
+
prediction_market_agent_tooling-0.64.11.dev653.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
131
|
+
prediction_market_agent_tooling-0.64.11.dev653.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
132
|
+
prediction_market_agent_tooling-0.64.11.dev653.dist-info/RECORD,,
|
File without changes
|
File without changes
|