prediction-market-agent-tooling 0.64.8__py3-none-any.whl → 0.64.10__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/logprobs_parser.py +117 -0
- prediction_market_agent_tooling/markets/omen/omen.py +2 -1
- {prediction_market_agent_tooling-0.64.8.dist-info → prediction_market_agent_tooling-0.64.10.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.64.8.dist-info → prediction_market_agent_tooling-0.64.10.dist-info}/RECORD +7 -6
- {prediction_market_agent_tooling-0.64.8.dist-info → prediction_market_agent_tooling-0.64.10.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.64.8.dist-info → prediction_market_agent_tooling-0.64.10.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.64.8.dist-info → prediction_market_agent_tooling-0.64.10.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
import math
|
2
|
+
from itertools import product
|
3
|
+
from typing import Any, Tuple
|
4
|
+
|
5
|
+
from pydantic import BaseModel
|
6
|
+
|
7
|
+
from prediction_market_agent_tooling.loggers import logger
|
8
|
+
|
9
|
+
|
10
|
+
class LogprobKey(BaseModel):
|
11
|
+
name: str
|
12
|
+
key_type: type
|
13
|
+
valid_values: set[Any] | None
|
14
|
+
|
15
|
+
|
16
|
+
class LogprobsParser:
|
17
|
+
def _get_logprobs_key_index(
|
18
|
+
self, logprobs: list[dict[str, Any]], key: LogprobKey
|
19
|
+
) -> int:
|
20
|
+
key_candidate = ""
|
21
|
+
for i, token in enumerate(logprobs):
|
22
|
+
if token["token"] in key.name:
|
23
|
+
key_candidate = key_candidate + token["token"]
|
24
|
+
else:
|
25
|
+
key_candidate = ""
|
26
|
+
if key_candidate == key.name:
|
27
|
+
return i
|
28
|
+
|
29
|
+
return -1
|
30
|
+
|
31
|
+
def _get_logprobs_indexes_for_result(
|
32
|
+
self, logprobs: list[dict[str, Any]], key_index: int
|
33
|
+
) -> Tuple[int, int]:
|
34
|
+
result_start_index = next(
|
35
|
+
(
|
36
|
+
i
|
37
|
+
for i in range(key_index + 1, len(logprobs))
|
38
|
+
if logprobs[i]["token"] in {":", ",", " ", ' "', '"', "\t", "\u00A0"}
|
39
|
+
),
|
40
|
+
-1,
|
41
|
+
)
|
42
|
+
result_end_index = next(
|
43
|
+
(
|
44
|
+
i
|
45
|
+
for i in range(result_start_index, len(logprobs))
|
46
|
+
if logprobs[i]["token"] in {",", '"', ",\n", "\",\n'", '",\n'}
|
47
|
+
),
|
48
|
+
-1,
|
49
|
+
)
|
50
|
+
return result_start_index + 1, result_end_index
|
51
|
+
|
52
|
+
def _is_correct_type(self, token: str, key_type: type) -> bool:
|
53
|
+
try:
|
54
|
+
key_type(token)
|
55
|
+
return True
|
56
|
+
except ValueError:
|
57
|
+
return False
|
58
|
+
|
59
|
+
def _parse_valid_tokens_with__agg_probs(
|
60
|
+
self, logprobs_list: list[tuple[dict[str, Any]]], key: LogprobKey
|
61
|
+
) -> list[dict[str, Any]]:
|
62
|
+
results: list[dict[str, Any]] = [
|
63
|
+
{
|
64
|
+
"token": "".join(str(logprob["token"]) for logprob in logprobs),
|
65
|
+
"logprob": sum(float(logprob["logprob"]) for logprob in logprobs),
|
66
|
+
"prob": math.exp(
|
67
|
+
sum(float(logprob["logprob"]) for logprob in logprobs)
|
68
|
+
),
|
69
|
+
}
|
70
|
+
for logprobs in logprobs_list
|
71
|
+
]
|
72
|
+
|
73
|
+
results_filtered: list[dict[str, Any]] = [
|
74
|
+
result
|
75
|
+
for result in results
|
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)
|
78
|
+
]
|
79
|
+
|
80
|
+
return sorted(results_filtered, key=lambda x: x["logprob"], reverse=True)[
|
81
|
+
: len(logprobs_list[0])
|
82
|
+
]
|
83
|
+
|
84
|
+
def parse_logprobs(
|
85
|
+
self, logprobs: list[dict[str, Any]], keys: list[LogprobKey]
|
86
|
+
) -> list[dict[str, Any]]:
|
87
|
+
results_for_keys = []
|
88
|
+
|
89
|
+
for key in keys:
|
90
|
+
key_index = self._get_logprobs_key_index(logprobs, key)
|
91
|
+
if key_index < 0:
|
92
|
+
logger.warning(f"Key {key.name} not found in logprobs")
|
93
|
+
continue
|
94
|
+
|
95
|
+
(
|
96
|
+
result_start_index,
|
97
|
+
result_end_index,
|
98
|
+
) = self._get_logprobs_indexes_for_result(logprobs, key_index)
|
99
|
+
if result_start_index < 0 or result_end_index < 0:
|
100
|
+
logger.warning(f"Error in parsing result for {key.name} in logprobs")
|
101
|
+
continue
|
102
|
+
|
103
|
+
valid_logprobs = [
|
104
|
+
logprobs[i]["top_logprobs"]
|
105
|
+
for i in range(result_start_index, result_end_index)
|
106
|
+
]
|
107
|
+
|
108
|
+
results_for_keys.append(
|
109
|
+
{
|
110
|
+
"key": key.name,
|
111
|
+
"logprobs": self._parse_valid_tokens_with__agg_probs(
|
112
|
+
list(product(*valid_logprobs)), key
|
113
|
+
),
|
114
|
+
}
|
115
|
+
)
|
116
|
+
|
117
|
+
return results_for_keys
|
@@ -89,7 +89,8 @@ from prediction_market_agent_tooling.tools.utils import (
|
|
89
89
|
from prediction_market_agent_tooling.tools.web3_utils import get_receipt_block_timestamp
|
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.001)
|
93
94
|
|
94
95
|
|
95
96
|
class OmenAgentMarket(AgentMarket):
|
@@ -36,6 +36,7 @@ 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=sXIwkA5O_fpBP3Civ891rTa0yRcbs3qNcNsY5MJpL68,3734
|
39
40
|
prediction_market_agent_tooling/markets/agent_market.py,sha256=1NomilM0GCXcRq_1N_cr2AbSK5ONTowFeRbrhc7V5zE,14929
|
40
41
|
prediction_market_agent_tooling/markets/base_subgraph_handler.py,sha256=7RaYO_4qAmQ6ZGM8oPK2-CkiJfKmV9MxM-rJlduaecU,1971
|
41
42
|
prediction_market_agent_tooling/markets/blockchain_utils.py,sha256=qm21scopQ6dfewkoqQF6lWLDGg2BblsKUdC9aG93Hmc,2249
|
@@ -54,7 +55,7 @@ prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=86TIx6cavE
|
|
54
55
|
prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
56
|
prediction_market_agent_tooling/markets/omen/cow_contracts.py,sha256=sl1L4cK5nAJwZ2wdhLzqh8p7h_IEValNvLwKUlInKxw,957
|
56
57
|
prediction_market_agent_tooling/markets/omen/data_models.py,sha256=4YEOpU-ypq8IBxlEr_qgrKKWwE7wKG6VE_Dq-UKVdOE,30513
|
57
|
-
prediction_market_agent_tooling/markets/omen/omen.py,sha256=
|
58
|
+
prediction_market_agent_tooling/markets/omen/omen.py,sha256=V_ETqDDjiByGE-4VXC39OMND70sIl2Dw489MwYUVHLU,51734
|
58
59
|
prediction_market_agent_tooling/markets/omen/omen_constants.py,sha256=D9oflYKafLQiHYtB5sScMHqmXyzM8JP8J0yATmc4SQQ,233
|
59
60
|
prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=dnefjlqw03x7nr9TAmC4NSfAL6GtBn72_Qkmy8fQPCk,29552
|
60
61
|
prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=Cyi9Ci-Z-K8WCZWVLs9oSuJC6qRobi_CpqDCno_5F-0,10238
|
@@ -124,8 +125,8 @@ prediction_market_agent_tooling/tools/tokens/usd.py,sha256=yuW8iPPtcpP4eLH2nORMD
|
|
124
125
|
prediction_market_agent_tooling/tools/transaction_cache.py,sha256=K5YKNL2_tR10Iw2TD9fuP-CTGpBbZtNdgbd0B_R7pjg,1814
|
125
126
|
prediction_market_agent_tooling/tools/utils.py,sha256=AC2a68jwASMWuQi-w8twl8b_M52YwrEJ81abmuEaqMY,6661
|
126
127
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=zRq-eeBGWt8uUGN9G_WfjmJ0eVvO8aWE9S0Pz_Y6AOA,12342
|
127
|
-
prediction_market_agent_tooling-0.64.
|
128
|
-
prediction_market_agent_tooling-0.64.
|
129
|
-
prediction_market_agent_tooling-0.64.
|
130
|
-
prediction_market_agent_tooling-0.64.
|
131
|
-
prediction_market_agent_tooling-0.64.
|
128
|
+
prediction_market_agent_tooling-0.64.10.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
129
|
+
prediction_market_agent_tooling-0.64.10.dist-info/METADATA,sha256=GsqFlqHhZTBcjYEhPLPMujf8TqDtdPF9z64mwaGT_rc,8742
|
130
|
+
prediction_market_agent_tooling-0.64.10.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
131
|
+
prediction_market_agent_tooling-0.64.10.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
132
|
+
prediction_market_agent_tooling-0.64.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|