prediction-market-agent-tooling 0.55.2.dev120__py3-none-any.whl → 0.56.0__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.
Files changed (25) hide show
  1. prediction_market_agent_tooling/deploy/agent.py +17 -7
  2. prediction_market_agent_tooling/jobs/jobs_models.py +27 -2
  3. prediction_market_agent_tooling/jobs/omen/omen_jobs.py +67 -41
  4. prediction_market_agent_tooling/markets/agent_market.py +8 -2
  5. prediction_market_agent_tooling/markets/markets.py +12 -0
  6. prediction_market_agent_tooling/markets/metaculus/metaculus.py +1 -1
  7. prediction_market_agent_tooling/markets/omen/data_models.py +11 -2
  8. prediction_market_agent_tooling/markets/omen/omen.py +16 -9
  9. prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py +14 -0
  10. prediction_market_agent_tooling/tools/caches/db_cache.py +351 -0
  11. prediction_market_agent_tooling/tools/google.py +3 -2
  12. prediction_market_agent_tooling/tools/is_invalid.py +2 -2
  13. prediction_market_agent_tooling/tools/is_predictable.py +3 -3
  14. prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py +6 -10
  15. prediction_market_agent_tooling/tools/tavily/tavily_models.py +0 -66
  16. prediction_market_agent_tooling/tools/tavily/tavily_search.py +12 -44
  17. prediction_market_agent_tooling/tools/utils.py +2 -0
  18. {prediction_market_agent_tooling-0.55.2.dev120.dist-info → prediction_market_agent_tooling-0.56.0.dist-info}/METADATA +2 -1
  19. {prediction_market_agent_tooling-0.55.2.dev120.dist-info → prediction_market_agent_tooling-0.56.0.dist-info}/RECORD +23 -24
  20. prediction_market_agent_tooling/jobs/jobs.py +0 -45
  21. prediction_market_agent_tooling/tools/tavily/tavily_storage.py +0 -105
  22. /prediction_market_agent_tooling/tools/{cache.py → caches/inmemory_cache.py} +0 -0
  23. {prediction_market_agent_tooling-0.55.2.dev120.dist-info → prediction_market_agent_tooling-0.56.0.dist-info}/LICENSE +0 -0
  24. {prediction_market_agent_tooling-0.55.2.dev120.dist-info → prediction_market_agent_tooling-0.56.0.dist-info}/WHEEL +0 -0
  25. {prediction_market_agent_tooling-0.55.2.dev120.dist-info → prediction_market_agent_tooling-0.56.0.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prediction-market-agent-tooling
3
- Version: 0.55.2.dev120
3
+ Version: 0.56.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
@@ -36,6 +36,7 @@ Requires-Dist: psycopg2-binary (>=2.9.9,<3.0.0)
36
36
  Requires-Dist: pydantic (>=2.6.1,<3.0.0)
37
37
  Requires-Dist: pydantic-settings (>=2.4.0,<3.0.0)
38
38
  Requires-Dist: pymongo (>=4.8.0,<5.0.0)
39
+ Requires-Dist: pytest-postgresql (>=6.1.1,<7.0.0)
39
40
  Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
40
41
  Requires-Dist: safe-cli (>=1.0.0,<2.0.0)
41
42
  Requires-Dist: safe-eth-py (>=6.0.0b41,<7.0.0)
@@ -17,7 +17,7 @@ prediction_market_agent_tooling/benchmark/agents.py,sha256=B1-uWdyeN4GGKMWGK_-Cc
17
17
  prediction_market_agent_tooling/benchmark/benchmark.py,sha256=MqTiaaJ3cYiOLUVR7OyImLWxcEya3Rl5JyFYW-K0lwM,17097
18
18
  prediction_market_agent_tooling/benchmark/utils.py,sha256=D0MfUkVZllmvcU0VOurk9tcKT7JTtwwOp-63zuCBVuc,2880
19
19
  prediction_market_agent_tooling/config.py,sha256=114f3V9abaok27p5jX3UVr5b5gRUiSxBIYn8Snid34I,6731
20
- prediction_market_agent_tooling/deploy/agent.py,sha256=2IbMDMSXT_2r3rgIc9CHrd65DoPhbcvTTrNoat1iP5w,22550
20
+ prediction_market_agent_tooling/deploy/agent.py,sha256=dpc94DUo8Gq1LdRdw6k78vm_47OeJIfomG9CRVpgzk0,22757
21
21
  prediction_market_agent_tooling/deploy/agent_example.py,sha256=dIIdZashExWk9tOdyDjw87AuUcGyM7jYxNChYrVK2dM,1001
22
22
  prediction_market_agent_tooling/deploy/betting_strategy.py,sha256=kMrIE3wMv_IB6nJd_1DmDXDkEZhsXFOgyTd7JZ0gqHI,13068
23
23
  prediction_market_agent_tooling/deploy/constants.py,sha256=M5ty8URipYMGe_G-RzxRydK3AFL6CyvmqCraJUrLBnE,82
@@ -27,11 +27,10 @@ prediction_market_agent_tooling/deploy/gcp/utils.py,sha256=oyW0jgrUT2Tr49c7GlpcM
27
27
  prediction_market_agent_tooling/deploy/trade_interval.py,sha256=Xk9j45alQ_vrasGvsNyuW70XHIQ7wfvjoxNR3F6HYCw,1155
28
28
  prediction_market_agent_tooling/gtypes.py,sha256=tqp03PyY0Yhievl4XELfwAn0xOoecaTvBZ1Co6b-A7o,2541
29
29
  prediction_market_agent_tooling/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
- prediction_market_agent_tooling/jobs/jobs.py,sha256=I07yh0GJ-xhlvQaOUQB8xlSnihhcbU2c7DZ4ZND14c0,1246
31
- prediction_market_agent_tooling/jobs/jobs_models.py,sha256=I5uBTHJ2S1Wi3H4jDxxU7nsswSIP9r3BevHmljLh5Pg,1370
32
- prediction_market_agent_tooling/jobs/omen/omen_jobs.py,sha256=I2_vGrEJj1reSI8M377ab5QCsYNp_l4l4QeYEmDBkFM,3989
30
+ prediction_market_agent_tooling/jobs/jobs_models.py,sha256=GOtsNm7URhzZM5fPY64r8m8Gz-sSsUhG1qmDoC7wGL8,2231
31
+ prediction_market_agent_tooling/jobs/omen/omen_jobs.py,sha256=N0_jGDyXQeVXXlYg4oA_pOfqIjscHsLQbr0pBwFGoRo,5178
33
32
  prediction_market_agent_tooling/loggers.py,sha256=Am6HHXRNO545BO3l7Ue9Wb2TkYE1OK8KKhGbI3XypVU,3751
34
- prediction_market_agent_tooling/markets/agent_market.py,sha256=OgB6bvDGfTAxbh6cDGD3XFO0iy0MAaOQvXEP6nw8xW8,12817
33
+ prediction_market_agent_tooling/markets/agent_market.py,sha256=W2ME57-CSAhrt8qm8-b5r7yLq-Sk7R_BZMaApvjhrUE,12901
35
34
  prediction_market_agent_tooling/markets/base_subgraph_handler.py,sha256=IxDTwX4tej9j5olNkXcLIE0RCF1Nh2icZQUT2ERMmZo,1937
36
35
  prediction_market_agent_tooling/markets/categorize.py,sha256=jsoHWvZk9pU6n17oWSCcCxNNYVwlb_NXsZxKRI7vmsk,1301
37
36
  prediction_market_agent_tooling/markets/data_models.py,sha256=jMqrSFO_w2z-5N3PFVgZqTHdVdkzSDhhzky2lHsGGKA,3621
@@ -41,16 +40,16 @@ prediction_market_agent_tooling/markets/manifold/data_models.py,sha256=ylXIEHymx
41
40
  prediction_market_agent_tooling/markets/manifold/manifold.py,sha256=qemQIwuFg4yf6egGWFp9lWpz1lXr02QiBeZ2akcT6II,5026
42
41
  prediction_market_agent_tooling/markets/manifold/utils.py,sha256=cPPFWXm3vCYH1jy7_ctJZuQH9ZDaPL4_AgAYzGWkoow,513
43
42
  prediction_market_agent_tooling/markets/market_fees.py,sha256=Q64T9uaJx0Vllt0BkrPmpMEz53ra-hMVY8Czi7CEP7s,1227
44
- prediction_market_agent_tooling/markets/markets.py,sha256=mwubc567OIlA32YKqlIdTloYV8FGJia9gPv0wE0xUEA,3368
43
+ prediction_market_agent_tooling/markets/markets.py,sha256=_b-BAfoKIcXl5ZXVODi1ywMhRCbc52022csH1nQT084,3893
45
44
  prediction_market_agent_tooling/markets/metaculus/api.py,sha256=4TRPGytQQbSdf42DCg2M_JWYPAuNjqZ3eBqaQBLkNks,2736
46
45
  prediction_market_agent_tooling/markets/metaculus/data_models.py,sha256=Suxa7xELdYuFNKqvGvFh8qyfVtAg79E-vaQ6dqNZOtA,3261
47
- prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=E_TUf5q73lWzdMp40Ne-3w4MjEd7AHcaif4pvFh9FMU,4360
46
+ prediction_market_agent_tooling/markets/metaculus/metaculus.py,sha256=86TIx6cavEWc8Cv4KpZxSvwiSw9oFybXE3YB49pg-CA,4377
48
47
  prediction_market_agent_tooling/markets/omen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- prediction_market_agent_tooling/markets/omen/data_models.py,sha256=nCjsc-ylIzQOCK_1BW-5NoYrS-NIXz2Hg9N1-IqhhC8,27516
50
- prediction_market_agent_tooling/markets/omen/omen.py,sha256=LqNZjngo6LoktKecfYmGmJJ9D5rj-s0Poy4x4_GZfp0,51116
48
+ prediction_market_agent_tooling/markets/omen/data_models.py,sha256=0eky-RO0TuJysUXHd52A6DSU2mx1ZWiJvvntS4xQsUc,27794
49
+ prediction_market_agent_tooling/markets/omen/omen.py,sha256=uOuV2DgQmxz6kzPcMovyGg0xYS0c6x12fEFNtLmN-uY,51260
51
50
  prediction_market_agent_tooling/markets/omen/omen_contracts.py,sha256=Zq7SncCq-hvpgXKsVruGBGCn1OhKZTe7r1qLdCTrT2w,28297
52
51
  prediction_market_agent_tooling/markets/omen/omen_resolving.py,sha256=iDWdjICGkt968exwCjY-6nsnQyrrNAg3YjnDdP430GQ,9415
53
- prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=UjKZir1z8wsr493kYm5kswC4kGFpR9H8tsq9DOgaaT4,35886
52
+ prediction_market_agent_tooling/markets/omen/omen_subgraph_handler.py,sha256=cXgtBfc5uv7d8598SJ537LxFGVfF_mv-VoQoqI4_G84,36330
54
53
  prediction_market_agent_tooling/markets/polymarket/api.py,sha256=UZ4_TG8ceb9Y-qgsOKs8Qiv8zDt957QkT8IX2c83yqo,4800
55
54
  prediction_market_agent_tooling/markets/polymarket/data_models.py,sha256=Fd5PI5y3mJM8VHExBhWFWEnuuIKxQmIAXgBuoPDvNjw,4341
56
55
  prediction_market_agent_tooling/markets/polymarket/data_models_web.py,sha256=VZhVccTApygSKMmy6Au2G02JCJOKJnR_oVeKlaesuSg,12548
@@ -72,36 +71,36 @@ prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256
72
71
  prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py,sha256=-FUSuQQgjcWSSnoFxnlAyTeilY6raJABJVM2QKkFqAY,438
73
72
  prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py,sha256=THMXwFlskvzbjnX_OiYtDSzI8XVFyULWfP2525_9UGc,429
74
73
  prediction_market_agent_tooling/tools/betting_strategies/utils.py,sha256=kpIb-ci67Vc1Yqqaa-_S4OUkbhWSIYog4_Iwp69HU_k,97
75
- prediction_market_agent_tooling/tools/cache.py,sha256=tGHHd9HCiE_hCCtPtloHZQdDfBuiow9YsqJNYi2Tx_0,499
74
+ prediction_market_agent_tooling/tools/caches/db_cache.py,sha256=l-Ghs434NuDZKkYQlQo6sh5-8eAgE-55I_ojc4Hxcmk,13185
75
+ prediction_market_agent_tooling/tools/caches/inmemory_cache.py,sha256=tGHHd9HCiE_hCCtPtloHZQdDfBuiow9YsqJNYi2Tx_0,499
76
76
  prediction_market_agent_tooling/tools/contract.py,sha256=s3yo8IbXTcvAJcPfLM0_NbgaEsWwLsPmyVnOgyjq_xI,20919
77
77
  prediction_market_agent_tooling/tools/costs.py,sha256=EaAJ7v9laD4VEV3d8B44M4u3_oEO_H16jRVCdoZ93Uw,954
78
78
  prediction_market_agent_tooling/tools/datetime_utc.py,sha256=2JSWF7AXQnv04_D_cu9Vmdkq0TWmGJ1QcK9AeqrA-U8,2765
79
79
  prediction_market_agent_tooling/tools/gnosis_rpc.py,sha256=ctBfB1os-MvZ1tm0Rwdyn9b3dvFnlM9naKvZmzywc3A,197
80
- prediction_market_agent_tooling/tools/google.py,sha256=SfVDxb3oEOUK8mpd0l3mTX9ybrdrTPNM6HjfJ7kfNjA,1794
80
+ prediction_market_agent_tooling/tools/google.py,sha256=jwXhu4lKfF0cuu02fMX-mGCRntRgiGQWkZ2CstaprK4,1828
81
81
  prediction_market_agent_tooling/tools/hexbytes_custom.py,sha256=Bp94qgPjvjWf1Vb4lNzGFDXRdThw1rJ91vL6r2PWq5E,2096
82
82
  prediction_market_agent_tooling/tools/httpx_cached_client.py,sha256=0-N1r0zcGKlY9Rk-Ab8hbqwc54eMbsoa3jXL0_yCCiM,355
83
83
  prediction_market_agent_tooling/tools/image_gen/image_gen.py,sha256=HzRwBx62hOXBOmrtpkXaP9Qq1Ku03uUGdREocyjLQ_k,1266
84
84
  prediction_market_agent_tooling/tools/image_gen/market_thumbnail_gen.py,sha256=8A3U2uxsCsOfLjru-6R_PPIAuiKY4qFkWp_GSBPV6-s,1280
85
85
  prediction_market_agent_tooling/tools/ipfs/ipfs_handler.py,sha256=CTTMfTvs_8PH4kAtlQby2aeEKwgpmxtuGbd4oYIdJ2A,1201
86
- prediction_market_agent_tooling/tools/is_invalid.py,sha256=Tg5XZC3i3qNHmAjFvCZbuYsSCopEjUsbosbFgSbC_1E,5347
87
- prediction_market_agent_tooling/tools/is_predictable.py,sha256=NIoR2bTNMmADcyNY2aKNMWkiDw7Z_9kZMcFXEdyewy4,6771
86
+ prediction_market_agent_tooling/tools/is_invalid.py,sha256=GSMwSWUZy-xviaFoIl0L34AVfLLTdh7zegjsTFE7_1M,5323
87
+ prediction_market_agent_tooling/tools/is_predictable.py,sha256=VGkxSoJ8CSLknloOLzm5J4-us7XImYxVzvpsAzxbpCc,6730
88
88
  prediction_market_agent_tooling/tools/langfuse_.py,sha256=jI_4ROxqo41CCnWGS1vN_AeDVhRzLMaQLxH3kxDu3L8,1153
89
89
  prediction_market_agent_tooling/tools/langfuse_client_utils.py,sha256=B0PhAQyviFnVbtOCYMxYmcCn66cu9nbqAOIAZcdgiRI,5771
90
90
  prediction_market_agent_tooling/tools/omen/reality_accuracy.py,sha256=M1SF7iSW1gVlQSTskdVFTn09uPLST23YeipVIWj54io,2236
91
91
  prediction_market_agent_tooling/tools/parallelism.py,sha256=6Gou0hbjtMZrYvxjTDFUDZuxmE2nqZVbb6hkg1hF82A,1022
92
92
  prediction_market_agent_tooling/tools/relevant_news_analysis/data_models.py,sha256=95l84aztFaxcRLLcRQ46yKJbIlOEuDAbIGLouyliDzA,1316
93
- prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py,sha256=OWLzwCbQS2b9hjwTRXTOjjplWXcGXFf3yjKEeK4kGbQ,5720
93
+ prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_analysis.py,sha256=CddJem7tk15NAudJDwmuL8znTycbR-YI8kTNtd3LzG8,5474
94
94
  prediction_market_agent_tooling/tools/relevant_news_analysis/relevant_news_cache.py,sha256=2yxtBIDyMT_6CsTpZyuIv_2dy2B9WgEOaTT1fSloBu0,3223
95
95
  prediction_market_agent_tooling/tools/safe.py,sha256=9vxGGLvSPnfy-sxUFDpBTe8omqpGXP7MzvGPp6bRxrU,5197
96
96
  prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0rnVhtQGzwoUdAgn_7u_GBM,729
97
97
  prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
98
- prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=Rz4tZzwCRzPaq49SFT33SCRQrqHXtqWdD9ajb2tGCWc,2723
99
- prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=UPSp0S5Sql52X6UlU2Ki_iO-gmDJSMs5enn9AV_IZRM,4896
100
- prediction_market_agent_tooling/tools/tavily/tavily_storage.py,sha256=t-tZzbCzBBdFedRZDuVBn3A3mIDX8Z5wza6SxWswu_E,4093
101
- prediction_market_agent_tooling/tools/utils.py,sha256=W-9SqeCKd51BYMRhDjYPQ7lfNO_zE9EvYpmu2r5WXGA,7163
98
+ prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=5ldQs1pZe6uJ5eDAuP4OLpzmcqYShlIV67kttNFvGS0,342
99
+ prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=Kw2mXNkMTYTEe1MBSTqhQmLoeXtgb6CkmHlcAJvhtqE,3809
100
+ prediction_market_agent_tooling/tools/utils.py,sha256=1VvunbTmzGzpIlRukFhArreFNxJPbsg4lLtQNk0r2bY,7185
102
101
  prediction_market_agent_tooling/tools/web3_utils.py,sha256=44W8siSLNQxeib98bbwAe7V5C609NHNlUuxwuWIRDiY,11838
103
- prediction_market_agent_tooling-0.55.2.dev120.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
104
- prediction_market_agent_tooling-0.55.2.dev120.dist-info/METADATA,sha256=xUQyruFo82CnvirDLBDHfpEj3SjUzsL-nwrK8BOzTUc,8063
105
- prediction_market_agent_tooling-0.55.2.dev120.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
106
- prediction_market_agent_tooling-0.55.2.dev120.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
107
- prediction_market_agent_tooling-0.55.2.dev120.dist-info/RECORD,,
102
+ prediction_market_agent_tooling-0.56.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
103
+ prediction_market_agent_tooling-0.56.0.dist-info/METADATA,sha256=FmWAg9sc322halWtR79LiDoJeRoz1bybzOJh4UynFuI,8106
104
+ prediction_market_agent_tooling-0.56.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
105
+ prediction_market_agent_tooling-0.56.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
106
+ prediction_market_agent_tooling-0.56.0.dist-info/RECORD,,
@@ -1,45 +0,0 @@
1
- import typing as t
2
-
3
- from prediction_market_agent_tooling.jobs.jobs_models import JobAgentMarket
4
- from prediction_market_agent_tooling.jobs.omen.omen_jobs import OmenJobAgentMarket
5
- from prediction_market_agent_tooling.markets.agent_market import FilterBy, SortBy
6
- from prediction_market_agent_tooling.markets.markets import MarketType
7
-
8
- JOB_MARKET_TYPE_TO_JOB_AGENT_MARKET: dict[MarketType, type[JobAgentMarket]] = {
9
- MarketType.OMEN: OmenJobAgentMarket,
10
- }
11
-
12
-
13
- @t.overload
14
- def get_jobs(
15
- market_type: t.Literal[MarketType.OMEN],
16
- limit: int | None,
17
- filter_by: FilterBy = FilterBy.OPEN,
18
- sort_by: SortBy = SortBy.NONE,
19
- ) -> t.Sequence[OmenJobAgentMarket]:
20
- ...
21
-
22
-
23
- @t.overload
24
- def get_jobs(
25
- market_type: MarketType,
26
- limit: int | None,
27
- filter_by: FilterBy = FilterBy.OPEN,
28
- sort_by: SortBy = SortBy.NONE,
29
- ) -> t.Sequence[JobAgentMarket]:
30
- ...
31
-
32
-
33
- def get_jobs(
34
- market_type: MarketType,
35
- limit: int | None,
36
- filter_by: FilterBy = FilterBy.OPEN,
37
- sort_by: SortBy = SortBy.NONE,
38
- ) -> t.Sequence[JobAgentMarket]:
39
- job_class = JOB_MARKET_TYPE_TO_JOB_AGENT_MARKET[market_type]
40
- markets = job_class.get_jobs(
41
- limit=limit,
42
- sort_by=sort_by,
43
- filter_by=filter_by,
44
- )
45
- return markets
@@ -1,105 +0,0 @@
1
- import typing as t
2
- from datetime import timedelta
3
-
4
- import tenacity
5
- from sqlmodel import Session, SQLModel, create_engine, desc, select
6
-
7
- from prediction_market_agent_tooling.config import APIKeys
8
- from prediction_market_agent_tooling.loggers import logger
9
- from prediction_market_agent_tooling.tools.tavily.tavily_models import (
10
- TavilyResponse,
11
- TavilyResponseModel,
12
- )
13
- from prediction_market_agent_tooling.tools.utils import utcnow
14
-
15
-
16
- class TavilyStorage:
17
- def __init__(self, agent_id: str, sqlalchemy_db_url: str | None = None):
18
- self.agent_id = agent_id
19
- self.engine = create_engine(
20
- sqlalchemy_db_url
21
- if sqlalchemy_db_url
22
- else APIKeys().sqlalchemy_db_url.get_secret_value()
23
- )
24
- self._initialize_db()
25
-
26
- def _initialize_db(self) -> None:
27
- """
28
- Creates the tables if they don't exist
29
- """
30
-
31
- # trick for making models import mandatory - models must be imported for metadata.create_all to work
32
- logger.debug(f"tables being added {TavilyResponseModel}")
33
- SQLModel.metadata.create_all(self.engine)
34
-
35
- @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_fixed(1))
36
- def save(
37
- self,
38
- query: str,
39
- search_depth: t.Literal["basic", "advanced"],
40
- topic: t.Literal["general", "news"],
41
- days: int | None,
42
- max_results: int,
43
- include_domains: t.Sequence[str] | None,
44
- exclude_domains: t.Sequence[str] | None,
45
- include_answer: bool,
46
- include_raw_content: bool,
47
- include_images: bool,
48
- use_cache: bool,
49
- response: TavilyResponse,
50
- ) -> None:
51
- db_item = TavilyResponseModel.from_model(
52
- agent_id=self.agent_id,
53
- query=query,
54
- search_depth=search_depth,
55
- topic=topic,
56
- max_results=max_results,
57
- days=days,
58
- include_domains=include_domains,
59
- exclude_domains=exclude_domains,
60
- include_answer=include_answer,
61
- include_raw_content=include_raw_content,
62
- include_images=include_images,
63
- use_cache=use_cache,
64
- response=response,
65
- )
66
- with Session(self.engine) as session:
67
- session.add(db_item)
68
- session.commit()
69
-
70
- @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_fixed(1))
71
- def find(
72
- self,
73
- query: str,
74
- search_depth: t.Literal["basic", "advanced"],
75
- topic: t.Literal["general", "news"],
76
- days: int | None,
77
- max_results: int,
78
- include_domains: t.Sequence[str] | None,
79
- exclude_domains: t.Sequence[str] | None,
80
- include_answer: bool,
81
- include_raw_content: bool,
82
- include_images: bool,
83
- use_cache: bool,
84
- max_age: timedelta = timedelta(days=1),
85
- ) -> TavilyResponse | None:
86
- with Session(self.engine) as session:
87
- sql_query = (
88
- select(TavilyResponseModel)
89
- .where(TavilyResponseModel.query == query)
90
- .where(TavilyResponseModel.search_depth == search_depth)
91
- .where(TavilyResponseModel.topic == topic)
92
- .where(TavilyResponseModel.days == days)
93
- .where(TavilyResponseModel.max_results == max_results)
94
- .where(TavilyResponseModel.include_domains == include_domains)
95
- .where(TavilyResponseModel.exclude_domains == exclude_domains)
96
- .where(TavilyResponseModel.include_answer == include_answer)
97
- .where(TavilyResponseModel.include_raw_content == include_raw_content)
98
- .where(TavilyResponseModel.include_images == include_images)
99
- .where(TavilyResponseModel.use_cache == use_cache)
100
- .where(TavilyResponseModel.datetime_ >= utcnow() - max_age)
101
- )
102
- item = session.exec(
103
- sql_query.order_by(desc(TavilyResponseModel.datetime_))
104
- ).first()
105
- return TavilyResponse.model_validate(item.response) if item else None