prediction-market-agent-tooling 0.64.11.dev653__py3-none-any.whl → 0.64.11.dev657__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 +2 -2
- prediction_market_agent_tooling/logprobs_parser.py +71 -33
- prediction_market_agent_tooling/markets/data_models.py +2 -0
- prediction_market_agent_tooling/markets/omen/omen.py +1 -1
- {prediction_market_agent_tooling-0.64.11.dev653.dist-info → prediction_market_agent_tooling-0.64.11.dev657.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.64.11.dev653.dist-info → prediction_market_agent_tooling-0.64.11.dev657.dist-info}/RECORD +9 -9
- {prediction_market_agent_tooling-0.64.11.dev653.dist-info → prediction_market_agent_tooling-0.64.11.dev657.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.64.11.dev653.dist-info → prediction_market_agent_tooling-0.64.11.dev657.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.64.11.dev653.dist-info → prediction_market_agent_tooling-0.64.11.dev657.dist-info}/entry_points.txt +0 -0
@@ -278,8 +278,8 @@ 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://
|
282
|
-
GNOSIS_RPC_URL: URI = Field(default=URI("https://rpc.
|
281
|
+
ETHEREUM_RPC_URL: URI = Field(default=URI("https://rpc.eth.gateway.fm"))
|
282
|
+
GNOSIS_RPC_URL: URI = Field(default=URI("https://rpc.gnosis.gateway.fm"))
|
283
283
|
CHAIN_ID: ChainID = Field(default=ChainID(100))
|
284
284
|
|
285
285
|
@property
|
@@ -1,29 +1,47 @@
|
|
1
1
|
import math
|
2
2
|
from itertools import product
|
3
|
-
from typing import Any, Tuple
|
3
|
+
from typing import Any, Tuple, Type
|
4
4
|
|
5
|
-
from pydantic import BaseModel
|
5
|
+
from pydantic import BaseModel, ValidationError
|
6
|
+
from pydantic.fields import FieldInfo
|
7
|
+
from pydantic.type_adapter import TypeAdapter
|
6
8
|
|
7
9
|
from prediction_market_agent_tooling.loggers import logger
|
8
10
|
|
9
11
|
|
10
|
-
class
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
class LogprobDetail(BaseModel):
|
13
|
+
token: str
|
14
|
+
logprob: float
|
15
|
+
prob: float
|
16
|
+
|
17
|
+
|
18
|
+
class FieldLogprobs(BaseModel):
|
19
|
+
key: str
|
20
|
+
logprobs: list[LogprobDetail]
|
14
21
|
|
15
22
|
|
16
23
|
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
|
+
|
17
35
|
def _get_logprobs_key_index(
|
18
|
-
self, logprobs: list[dict[str, Any]],
|
36
|
+
self, logprobs: list[dict[str, Any]], field_name: str
|
19
37
|
) -> int:
|
20
38
|
key_candidate = ""
|
21
39
|
for i, token in enumerate(logprobs):
|
22
|
-
if token["token"] in
|
40
|
+
if token["token"] in field_name:
|
23
41
|
key_candidate = key_candidate + token["token"]
|
24
42
|
else:
|
25
43
|
key_candidate = ""
|
26
|
-
if key_candidate ==
|
44
|
+
if key_candidate == field_name:
|
27
45
|
return i
|
28
46
|
|
29
47
|
return -1
|
@@ -45,19 +63,25 @@ class LogprobsParser:
|
|
45
63
|
for i in range(result_start_index, len(logprobs))
|
46
64
|
if logprobs[i]["token"] in {",", '"', ",\n", "\",\n'", '",\n'}
|
47
65
|
),
|
48
|
-
-1,
|
66
|
+
len(logprobs) - 1,
|
49
67
|
)
|
50
68
|
return result_start_index + 1, result_end_index
|
51
69
|
|
52
|
-
def _is_correct_type(self, token: str, key_type: type) -> bool:
|
70
|
+
def _is_correct_type(self, token: str, key_type: type | None) -> bool:
|
71
|
+
if key_type is None:
|
72
|
+
return True
|
73
|
+
|
53
74
|
try:
|
54
|
-
key_type(token)
|
75
|
+
TypeAdapter(key_type).validate_python(token)
|
55
76
|
return True
|
56
|
-
except
|
77
|
+
except ValidationError:
|
57
78
|
return False
|
58
79
|
|
59
80
|
def _parse_valid_tokens_with__agg_probs(
|
60
|
-
self,
|
81
|
+
self,
|
82
|
+
logprobs_list: list[tuple[dict[str, Any]]],
|
83
|
+
field_info: FieldInfo,
|
84
|
+
top_logprobs: int,
|
61
85
|
) -> list[dict[str, Any]]:
|
62
86
|
results: list[dict[str, Any]] = [
|
63
87
|
{
|
@@ -73,45 +97,59 @@ class LogprobsParser:
|
|
73
97
|
results_filtered: list[dict[str, Any]] = [
|
74
98
|
result
|
75
99
|
for result in results
|
76
|
-
if self._is_correct_type(result["token"],
|
77
|
-
and (key.valid_values is None or result["token"] in key.valid_values)
|
100
|
+
if self._is_correct_type(result["token"], field_info.annotation)
|
78
101
|
]
|
79
102
|
|
80
|
-
|
81
|
-
:
|
82
|
-
|
103
|
+
sorted_results = sorted(
|
104
|
+
results_filtered, key=lambda x: x["logprob"], reverse=True
|
105
|
+
)
|
106
|
+
return (
|
107
|
+
sorted_results[:top_logprobs]
|
108
|
+
if len(sorted_results) > top_logprobs
|
109
|
+
else sorted_results
|
110
|
+
)
|
83
111
|
|
84
112
|
def parse_logprobs(
|
85
|
-
self, logprobs: list[dict[str, Any]],
|
86
|
-
) -> list[
|
113
|
+
self, logprobs: list[dict[str, Any]], target_model_cls: Type[BaseModel]
|
114
|
+
) -> list[FieldLogprobs]:
|
87
115
|
results_for_keys = []
|
88
116
|
|
89
|
-
for
|
90
|
-
|
117
|
+
for field_name, field_info in target_model_cls.model_fields.items():
|
118
|
+
if field_name in self.skip_fields:
|
119
|
+
continue
|
120
|
+
|
121
|
+
key_index = self._get_logprobs_key_index(logprobs, field_name)
|
122
|
+
|
91
123
|
if key_index < 0:
|
92
|
-
logger.warning(f"Key {
|
124
|
+
logger.warning(f"Key {field_name} not found in logprobs")
|
93
125
|
continue
|
94
126
|
|
95
127
|
(
|
96
128
|
result_start_index,
|
97
129
|
result_end_index,
|
98
130
|
) = self._get_logprobs_indexes_for_result(logprobs, key_index)
|
131
|
+
|
99
132
|
if result_start_index < 0 or result_end_index < 0:
|
100
|
-
logger.warning(f"Error in parsing result for {
|
133
|
+
logger.warning(f"Error in parsing result for {field_name} in logprobs")
|
101
134
|
continue
|
102
135
|
|
103
|
-
|
104
|
-
logprobs[i]["top_logprobs"]
|
136
|
+
valid_logprobs_raw = [
|
137
|
+
logprobs[i]["top_logprobs"][: self.max_top_logprobs_length]
|
105
138
|
for i in range(result_start_index, result_end_index)
|
139
|
+
if logprobs[i]["top_logprobs"] is not None
|
106
140
|
]
|
107
141
|
|
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
|
+
|
108
148
|
results_for_keys.append(
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
),
|
114
|
-
}
|
149
|
+
FieldLogprobs(
|
150
|
+
key=field_name,
|
151
|
+
logprobs=[LogprobDetail(**item) for item in parsed_logprobs_data],
|
152
|
+
)
|
115
153
|
)
|
116
154
|
|
117
155
|
return results_for_keys
|
@@ -10,6 +10,7 @@ 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
|
13
14
|
from prediction_market_agent_tooling.tools.utils import DatetimeUTC
|
14
15
|
|
15
16
|
|
@@ -77,6 +78,7 @@ class ProbabilisticAnswer(BaseModel):
|
|
77
78
|
p_yes: Probability
|
78
79
|
confidence: float
|
79
80
|
reasoning: str | None = None
|
81
|
+
logprobs: list[FieldLogprobs] | None = None
|
80
82
|
|
81
83
|
@property
|
82
84
|
def p_no(self) -> Probability:
|
@@ -90,7 +90,7 @@ from prediction_market_agent_tooling.tools.web3_utils import get_receipt_block_t
|
|
90
90
|
|
91
91
|
OMEN_DEFAULT_REALITIO_BOND_VALUE = xDai(0.01)
|
92
92
|
# Too low value would work with the Omen contract, but causes CoW orders (when buying the specific market's tokens) to fail.
|
93
|
-
OMEN_TINY_BET_AMOUNT = USD(0.
|
93
|
+
OMEN_TINY_BET_AMOUNT = USD(0.01)
|
94
94
|
|
95
95
|
|
96
96
|
class OmenAgentMarket(AgentMarket):
|
@@ -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=4nhDV_IkGl2-tK_yif4P3sTZm7cIvx2dWUlraSRtMwQ,10735
|
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=Du1Yc-fAVSixQX_Zx6KWpgSzI_ZYhv5tS1b8IcOPPr8,4979
|
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=OZdq7VfTenxPk_3mI7DvpGMFMBPrq2pvFwcMb47BnNY,4663
|
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
|
@@ -55,7 +55,7 @@ prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=86TIx6cavE
|
|
55
55
|
prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
56
56
|
prediction_market_agent_tooling/markets/omen/cow_contracts.py,sha256=sl1L4cK5nAJwZ2wdhLzqh8p7h_IEValNvLwKUlInKxw,957
|
57
57
|
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=4YEOpU-ypq8IBxlEr_qgrKKWwE7wKG6VE_Dq-UKVdOE,30513
|
58
|
-
prediction_market_agent_tooling/markets/omen/omen.py,sha256=
|
58
|
+
prediction_market_agent_tooling/markets/omen/omen.py,sha256=NKeTT2gU6uZ9a4gGpa9Dxy6msFQp_41Ug85hIdCmQy4,51733
|
59
59
|
prediction_market_agent_tooling/markets/omen/omen_constants.py,sha256=D9oflYKafLQiHYtB5sScMHqmXyzM8JP8J0yATmc4SQQ,233
|
60
60
|
prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=dnefjlqw03x7nr9TAmC4NSfAL6GtBn72_Qkmy8fQPCk,29552
|
61
61
|
prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=Cyi9Ci-Z-K8WCZWVLs9oSuJC6qRobi_CpqDCno_5F-0,10238
|
@@ -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.
|
129
|
-
prediction_market_agent_tooling-0.64.11.
|
130
|
-
prediction_market_agent_tooling-0.64.11.
|
131
|
-
prediction_market_agent_tooling-0.64.11.
|
132
|
-
prediction_market_agent_tooling-0.64.11.
|
128
|
+
prediction_market_agent_tooling-0.64.11.dev657.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
129
|
+
prediction_market_agent_tooling-0.64.11.dev657.dist-info/METADATA,sha256=ttU6Mz9EhbftcOKumK1IJbT5LJB0gMAKtKejFPr-ImA,8749
|
130
|
+
prediction_market_agent_tooling-0.64.11.dev657.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
131
|
+
prediction_market_agent_tooling-0.64.11.dev657.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
132
|
+
prediction_market_agent_tooling-0.64.11.dev657.dist-info/RECORD,,
|
File without changes
|
File without changes
|