prediction-market-agent-tooling 0.47.1__tar.gz → 0.48.1__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.
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/PKG-INFO +6 -3
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/config.py +16 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/data_models.py +1 -1
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/markets.py +2 -1
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/langfuse/langfuse_wrapper.py +1 -1
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/monitor.py +2 -1
- prediction_market_agent_tooling-0.48.1/prediction_market_agent_tooling/tools/tavily_storage/tavily_models.py +135 -0
- prediction_market_agent_tooling-0.48.1/prediction_market_agent_tooling/tools/tavily_storage/tavily_storage.py +97 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/pyproject.toml +9 -4
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/README.md +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/depositablewrapper_erc20.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/erc20.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/erc4626.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_dxdao.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_fpmm.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_fpmm_conditionaltokens.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_fpmm_factory.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_kleros.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_oracle.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_realitio.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/omen_thumbnailmapping.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/abis/proxy.abi.json +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/benchmark/__init__.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/benchmark/agents.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/benchmark/benchmark.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/benchmark/utils.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/deploy/agent.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/deploy/agent_example.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/deploy/constants.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/deploy/gcp/deploy.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/deploy/gcp/kubernetes_models.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/deploy/gcp/utils.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/gtypes.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/loggers.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/agent_market.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/categorize.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/manifold/__init__.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/manifold/api.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/manifold/data_models.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/manifold/manifold.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/manifold/utils.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/metaculus/api.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/metaculus/data_models.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/metaculus/metaculus.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/omen/__init__.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/omen/data_models.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/omen/omen.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/omen/omen_contracts.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/omen/omen_resolving.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/polymarket/api.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/polymarket/data_models.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/polymarket/data_models_web.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/polymarket/polymarket.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/markets/polymarket/utils.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/markets/manifold.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/markets/metaculus.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/markets/omen.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/markets/polymarket.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/monitor_app.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/monitor/monitor_settings.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/py.typed +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/balances.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/betting_strategies/market_moving.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/cache.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/contract.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/costs.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/gnosis_rpc.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/google.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/hexbytes_custom.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/image_gen/image_gen.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/is_predictable.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/parallelism.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/safe.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/singleton.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/streamlit_user_login.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/prediction_market_agent_tooling/tools/utils.py +0 -0
- {prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/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.
|
3
|
+
Version: 0.48.1
|
4
4
|
Summary: Tools to benchmark, deploy and monitor prediction market agents.
|
5
5
|
Author: Gnosis
|
6
6
|
Requires-Python: >=3.10,<3.12
|
@@ -11,9 +11,9 @@ Provides-Extra: google
|
|
11
11
|
Provides-Extra: langchain
|
12
12
|
Provides-Extra: openai
|
13
13
|
Requires-Dist: autoflake (>=2.2.1,<3.0.0)
|
14
|
-
Requires-Dist: base58 (>=
|
14
|
+
Requires-Dist: base58 (>=1.0.2,<2.0)
|
15
15
|
Requires-Dist: cron-validator (>=1.0.8,<2.0.0)
|
16
|
-
Requires-Dist: eth-account (>=0.
|
16
|
+
Requires-Dist: eth-account (>=0.11.2,<0.12.0)
|
17
17
|
Requires-Dist: eth-typing (>=3.0.0,<4.0.0)
|
18
18
|
Requires-Dist: functions-framework (>=3.5.0,<4.0.0)
|
19
19
|
Requires-Dist: google-api-python-client (==2.95.0) ; extra == "google"
|
@@ -29,14 +29,17 @@ Requires-Dist: loguru (>=0.7.2,<0.8.0)
|
|
29
29
|
Requires-Dist: numpy (>=1.26.4,<2.0.0)
|
30
30
|
Requires-Dist: openai (>=1.0.0,<2.0.0) ; extra == "openai"
|
31
31
|
Requires-Dist: prompt-toolkit (>=3.0.43,<4.0.0)
|
32
|
+
Requires-Dist: psycopg2-binary (>=2.9.9,<3.0.0)
|
32
33
|
Requires-Dist: pydantic (>=2.6.1,<3.0.0)
|
33
34
|
Requires-Dist: pydantic-settings (>=2.1.0,<3.0.0)
|
34
35
|
Requires-Dist: safe-cli (>=1.0.0,<2.0.0)
|
35
36
|
Requires-Dist: safe-eth-py (>=6.0.0b14,<7.0.0)
|
36
37
|
Requires-Dist: scikit-learn (>=1.3.1,<2.0.0)
|
38
|
+
Requires-Dist: sqlmodel (>=0.0.21,<0.0.22)
|
37
39
|
Requires-Dist: streamlit (>=1.31.0,<2.0.0)
|
38
40
|
Requires-Dist: subgrounds (>=1.9.1,<2.0.0)
|
39
41
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
42
|
+
Requires-Dist: tavily-python (>=0.3.9,<0.4.0)
|
40
43
|
Requires-Dist: tqdm (>=4.66.2,<5.0.0)
|
41
44
|
Requires-Dist: typer (>=0.9.0,<1.0.0)
|
42
45
|
Requires-Dist: types-pytz (>=2024.1.0.20240203,<2025.0.0.0)
|
@@ -43,6 +43,10 @@ class APIKeys(BaseSettings):
|
|
43
43
|
LANGFUSE_PUBLIC_KEY: t.Optional[SecretStr] = None
|
44
44
|
LANGFUSE_HOST: t.Optional[str] = None
|
45
45
|
|
46
|
+
TAVILY_API_KEY: t.Optional[SecretStr] = None
|
47
|
+
|
48
|
+
SQLALCHEMY_DB_URL: t.Optional[SecretStr] = None
|
49
|
+
|
46
50
|
ENABLE_CACHE: bool = True
|
47
51
|
CACHE_DIR: str = "./.cache"
|
48
52
|
|
@@ -134,6 +138,18 @@ class APIKeys(BaseSettings):
|
|
134
138
|
self.LANGFUSE_HOST, "LANGFUSE_HOST missing in the environment."
|
135
139
|
)
|
136
140
|
|
141
|
+
@property
|
142
|
+
def tavily_api_key(self) -> SecretStr:
|
143
|
+
return check_not_none(
|
144
|
+
self.TAVILY_API_KEY, "TAVILY_API_KEY missing in the environment."
|
145
|
+
)
|
146
|
+
|
147
|
+
@property
|
148
|
+
def sqlalchemy_db_url(self) -> SecretStr:
|
149
|
+
return check_not_none(
|
150
|
+
self.SQLALCHEMY_DB_URL, "SQLALCHEMY_DB_URL missing in the environment."
|
151
|
+
)
|
152
|
+
|
137
153
|
def model_dump_public(self) -> dict[str, t.Any]:
|
138
154
|
return {
|
139
155
|
k: v
|
@@ -30,8 +30,9 @@ from prediction_market_agent_tooling.tools.utils import should_not_happen, utcno
|
|
30
30
|
|
31
31
|
|
32
32
|
class MarketType(str, Enum):
|
33
|
-
|
33
|
+
# Note: Always keep the omen market first, as it is the main market for us.
|
34
34
|
OMEN = "omen"
|
35
|
+
MANIFOLD = "manifold"
|
35
36
|
POLYMARKET = "polymarket"
|
36
37
|
METACULUS = "metaculus"
|
37
38
|
|
@@ -10,7 +10,7 @@ from prediction_market_agent_tooling.tools.utils import utcnow
|
|
10
10
|
class LangfuseWrapper(BaseModel):
|
11
11
|
agent_name: str
|
12
12
|
|
13
|
-
@computed_field # type: ignore[
|
13
|
+
@computed_field # type: ignore[prop-decorator] # Mypy issue: https://github.com/python/mypy/issues/14461
|
14
14
|
@cached_property
|
15
15
|
def session_id(self) -> str:
|
16
16
|
return f"{self.agent_name} - {utcnow()}"
|
@@ -229,7 +229,8 @@ def monitor_agent(agent: DeployedAgent) -> None:
|
|
229
229
|
)
|
230
230
|
.interactive()
|
231
231
|
)
|
232
|
-
|
232
|
+
|
233
|
+
st.altair_chart( # type: ignore
|
233
234
|
per_day_accuracy_chart.mark_line()
|
234
235
|
+ per_day_accuracy_chart.transform_loess("x-axis-day", "Is Correct").mark_line(
|
235
236
|
color="red", strokeDash=[5, 5]
|
@@ -0,0 +1,135 @@
|
|
1
|
+
import typing as t
|
2
|
+
from datetime import datetime
|
3
|
+
|
4
|
+
from loguru import logger
|
5
|
+
from pydantic import BaseModel
|
6
|
+
from sqlalchemy import Column
|
7
|
+
from sqlalchemy.dialects.postgresql import JSONB
|
8
|
+
from sqlmodel import ARRAY, Field, Session, SQLModel, String, create_engine
|
9
|
+
|
10
|
+
from prediction_market_agent_tooling.config import APIKeys
|
11
|
+
|
12
|
+
|
13
|
+
class TavilyResult(BaseModel):
|
14
|
+
title: str
|
15
|
+
url: str
|
16
|
+
content: str
|
17
|
+
score: float
|
18
|
+
raw_content: str
|
19
|
+
|
20
|
+
|
21
|
+
class TavilyResponse(BaseModel):
|
22
|
+
query: str
|
23
|
+
follow_up_questions: None = None
|
24
|
+
answer: str
|
25
|
+
images: list[str]
|
26
|
+
results: list[TavilyResult]
|
27
|
+
response_time: float
|
28
|
+
|
29
|
+
|
30
|
+
class TavilyResponseModel(SQLModel, table=True):
|
31
|
+
__tablename__ = "tavily_response"
|
32
|
+
__table_args__ = {"extend_existing": True}
|
33
|
+
id: int | None = Field(None, primary_key=True)
|
34
|
+
agent_id: str = Field(index=True, nullable=False)
|
35
|
+
# Parameters used to execute the search
|
36
|
+
query: str
|
37
|
+
search_depth: str
|
38
|
+
topic: str
|
39
|
+
max_results: int
|
40
|
+
include_domains: list[str] | None = Field(
|
41
|
+
None, sa_column=Column(ARRAY(String), nullable=True)
|
42
|
+
)
|
43
|
+
exclude_domains: list[str] | None = Field(
|
44
|
+
None, sa_column=Column(ARRAY(String), nullable=True)
|
45
|
+
)
|
46
|
+
include_answer: bool
|
47
|
+
include_raw_content: bool
|
48
|
+
include_images: bool
|
49
|
+
use_cache: bool
|
50
|
+
# Datetime at the time of search response and response from the search
|
51
|
+
datetime_: datetime = Field(index=True, nullable=False)
|
52
|
+
response: dict[str, t.Any] = Field(sa_column=Column(JSONB, nullable=False))
|
53
|
+
|
54
|
+
@staticmethod
|
55
|
+
def from_model(
|
56
|
+
agent_id: str,
|
57
|
+
query: str,
|
58
|
+
search_depth: t.Literal["basic", "advanced"],
|
59
|
+
topic: t.Literal["general", "news"],
|
60
|
+
max_results: int,
|
61
|
+
include_domains: t.Sequence[str] | None,
|
62
|
+
exclude_domains: t.Sequence[str] | None,
|
63
|
+
include_answer: bool,
|
64
|
+
include_raw_content: bool,
|
65
|
+
include_images: bool,
|
66
|
+
use_cache: bool,
|
67
|
+
response: TavilyResponse,
|
68
|
+
) -> "TavilyResponseModel":
|
69
|
+
return TavilyResponseModel(
|
70
|
+
agent_id=agent_id,
|
71
|
+
query=query,
|
72
|
+
search_depth=search_depth,
|
73
|
+
topic=topic,
|
74
|
+
max_results=max_results,
|
75
|
+
include_domains=sorted(include_domains) if include_domains else None,
|
76
|
+
exclude_domains=sorted(exclude_domains) if exclude_domains else None,
|
77
|
+
include_answer=include_answer,
|
78
|
+
include_raw_content=include_raw_content,
|
79
|
+
include_images=include_images,
|
80
|
+
use_cache=use_cache,
|
81
|
+
datetime_=datetime.now(),
|
82
|
+
response=response.model_dump(),
|
83
|
+
)
|
84
|
+
|
85
|
+
|
86
|
+
class TavilyStorage:
|
87
|
+
def __init__(self, agent_id: str, sqlalchemy_db_url: str | None = None):
|
88
|
+
self.agent_id = agent_id
|
89
|
+
self.engine = create_engine(
|
90
|
+
sqlalchemy_db_url
|
91
|
+
if sqlalchemy_db_url
|
92
|
+
else APIKeys().sqlalchemy_db_url.get_secret_value()
|
93
|
+
)
|
94
|
+
self._initialize_db()
|
95
|
+
|
96
|
+
def _initialize_db(self) -> None:
|
97
|
+
"""
|
98
|
+
Creates the tables if they don't exist
|
99
|
+
"""
|
100
|
+
|
101
|
+
# trick for making models import mandatory - models must be imported for metadata.create_all to work
|
102
|
+
logger.debug(f"tables being added {TavilyResponseModel}")
|
103
|
+
SQLModel.metadata.create_all(self.engine)
|
104
|
+
|
105
|
+
def save(
|
106
|
+
self,
|
107
|
+
query: str,
|
108
|
+
search_depth: t.Literal["basic", "advanced"],
|
109
|
+
topic: t.Literal["general", "news"],
|
110
|
+
max_results: int,
|
111
|
+
include_domains: t.Sequence[str] | None,
|
112
|
+
exclude_domains: t.Sequence[str] | None,
|
113
|
+
include_answer: bool,
|
114
|
+
include_raw_content: bool,
|
115
|
+
include_images: bool,
|
116
|
+
use_cache: bool,
|
117
|
+
response: TavilyResponse,
|
118
|
+
) -> None:
|
119
|
+
db_item = TavilyResponseModel.from_model(
|
120
|
+
agent_id=self.agent_id,
|
121
|
+
query=query,
|
122
|
+
search_depth=search_depth,
|
123
|
+
topic=topic,
|
124
|
+
max_results=max_results,
|
125
|
+
include_domains=include_domains,
|
126
|
+
exclude_domains=exclude_domains,
|
127
|
+
include_answer=include_answer,
|
128
|
+
include_raw_content=include_raw_content,
|
129
|
+
include_images=include_images,
|
130
|
+
use_cache=use_cache,
|
131
|
+
response=response,
|
132
|
+
)
|
133
|
+
with Session(self.engine) as session:
|
134
|
+
session.add(db_item)
|
135
|
+
session.commit()
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import typing as t
|
2
|
+
|
3
|
+
import tenacity
|
4
|
+
from tavily import TavilyClient
|
5
|
+
|
6
|
+
from prediction_market_agent_tooling.config import APIKeys
|
7
|
+
from prediction_market_agent_tooling.tools.tavily_storage.tavily_models import (
|
8
|
+
TavilyResponse,
|
9
|
+
TavilyStorage,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
def tavily_search(
|
14
|
+
query: str,
|
15
|
+
search_depth: t.Literal["basic", "advanced"] = "advanced",
|
16
|
+
topic: t.Literal["general", "news"] = "general",
|
17
|
+
max_results: int = 5,
|
18
|
+
include_domains: t.Sequence[str] | None = None,
|
19
|
+
exclude_domains: t.Sequence[str] | None = None,
|
20
|
+
include_answer: bool = True,
|
21
|
+
include_raw_content: bool = True,
|
22
|
+
include_images: bool = True,
|
23
|
+
use_cache: bool = False,
|
24
|
+
api_keys: APIKeys | None = None,
|
25
|
+
tavily_storage: TavilyStorage | None = None,
|
26
|
+
) -> TavilyResponse:
|
27
|
+
"""
|
28
|
+
Wrapper around Tavily's search method that will save the response to `TavilyResponseCache`, if provided.
|
29
|
+
|
30
|
+
Argument default values are different from the original method, to return everything by default, because it can be handy in the future and it doesn't increase the costs.
|
31
|
+
"""
|
32
|
+
response = _tavily_search(
|
33
|
+
query=query,
|
34
|
+
search_depth=search_depth,
|
35
|
+
topic=topic,
|
36
|
+
max_results=max_results,
|
37
|
+
include_domains=include_domains,
|
38
|
+
exclude_domains=exclude_domains,
|
39
|
+
include_answer=include_answer,
|
40
|
+
include_raw_content=include_raw_content,
|
41
|
+
include_images=include_images,
|
42
|
+
use_cache=use_cache,
|
43
|
+
api_keys=api_keys,
|
44
|
+
)
|
45
|
+
response_parsed = TavilyResponse.model_validate(response)
|
46
|
+
if tavily_storage:
|
47
|
+
tavily_storage.save(
|
48
|
+
query=query,
|
49
|
+
search_depth=search_depth,
|
50
|
+
topic=topic,
|
51
|
+
max_results=max_results,
|
52
|
+
include_domains=include_domains,
|
53
|
+
exclude_domains=exclude_domains,
|
54
|
+
include_answer=include_answer,
|
55
|
+
include_raw_content=include_raw_content,
|
56
|
+
include_images=include_images,
|
57
|
+
use_cache=use_cache,
|
58
|
+
response=response_parsed,
|
59
|
+
)
|
60
|
+
return response_parsed
|
61
|
+
|
62
|
+
|
63
|
+
@tenacity.retry(
|
64
|
+
stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_fixed(1), reraise=True
|
65
|
+
)
|
66
|
+
def _tavily_search(
|
67
|
+
query: str,
|
68
|
+
search_depth: t.Literal["basic", "advanced"],
|
69
|
+
topic: t.Literal["general", "news"],
|
70
|
+
max_results: int,
|
71
|
+
include_domains: t.Sequence[str] | None,
|
72
|
+
exclude_domains: t.Sequence[str] | None,
|
73
|
+
include_answer: bool,
|
74
|
+
include_raw_content: bool,
|
75
|
+
include_images: bool,
|
76
|
+
use_cache: bool,
|
77
|
+
api_keys: APIKeys | None = None,
|
78
|
+
) -> dict[str, t.Any]:
|
79
|
+
"""
|
80
|
+
Internal minimalistic wrapper around Tavily's search method, that will retry if the call fails.
|
81
|
+
"""
|
82
|
+
tavily = TavilyClient(
|
83
|
+
api_key=(api_keys or APIKeys()).tavily_api_key.get_secret_value()
|
84
|
+
)
|
85
|
+
response: dict[str, t.Any] = tavily.search(
|
86
|
+
query=query,
|
87
|
+
search_depth=search_depth,
|
88
|
+
topic=topic,
|
89
|
+
max_results=max_results,
|
90
|
+
include_domains=include_domains,
|
91
|
+
exclude_domains=exclude_domains,
|
92
|
+
include_answer=include_answer,
|
93
|
+
include_raw_content=include_raw_content,
|
94
|
+
include_images=include_images,
|
95
|
+
use_cache=use_cache,
|
96
|
+
)
|
97
|
+
return response
|
{prediction_market_agent_tooling-0.47.1 → prediction_market_agent_tooling-0.48.1}/pyproject.toml
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "prediction-market-agent-tooling"
|
3
|
-
version = "0.
|
3
|
+
version = "0.48.1"
|
4
4
|
description = "Tools to benchmark, deploy and monitor prediction market agents."
|
5
5
|
authors = ["Gnosis"]
|
6
6
|
readme = "README.md"
|
@@ -37,12 +37,15 @@ google-api-python-client = { version = "2.95.0", optional = true}
|
|
37
37
|
subgrounds = "^1.9.1"
|
38
38
|
loguru = "^0.7.2"
|
39
39
|
safe-eth-py = "^6.0.0b14"
|
40
|
-
eth-account = "^0.
|
40
|
+
eth-account = "^0.11.2"
|
41
41
|
prompt-toolkit = "^3.0.43"
|
42
42
|
safe-cli = "^1.0.0"
|
43
43
|
langfuse = "^2.27.1"
|
44
44
|
openai = { version = "^1.0.0", optional = true}
|
45
|
-
|
45
|
+
tavily-python = "^0.3.9"
|
46
|
+
sqlmodel = "^0.0.21"
|
47
|
+
psycopg2-binary = "^2.9.9"
|
48
|
+
base58 = ">=1.0.2,<2.0"
|
46
49
|
|
47
50
|
[tool.poetry.extras]
|
48
51
|
openai = ["openai"]
|
@@ -51,8 +54,10 @@ google = ["google-api-python-client"]
|
|
51
54
|
|
52
55
|
[tool.poetry.group.dev.dependencies]
|
53
56
|
pytest = "*"
|
54
|
-
mypy = "^1.
|
57
|
+
mypy = "^1.11.1"
|
55
58
|
black = "^23.12.1"
|
59
|
+
ape-foundry = "^0.8.2"
|
60
|
+
eth-ape = "^0.8.10"
|
56
61
|
|
57
62
|
[build-system]
|
58
63
|
requires = ["poetry-core"]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|