prediction-market-agent-tooling 0.52.2__py3-none-any.whl → 0.53.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.
- prediction_market_agent_tooling/tools/tavily/tavily_models.py +84 -0
- prediction_market_agent_tooling/tools/{tavily_storage/tavily_storage.py → tavily/tavily_search.py} +28 -2
- prediction_market_agent_tooling/tools/{tavily_storage/tavily_models.py → tavily/tavily_storage.py} +10 -87
- {prediction_market_agent_tooling-0.52.2.dist-info → prediction_market_agent_tooling-0.53.0.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.52.2.dist-info → prediction_market_agent_tooling-0.53.0.dist-info}/RECORD +8 -7
- {prediction_market_agent_tooling-0.52.2.dist-info → prediction_market_agent_tooling-0.53.0.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.52.2.dist-info → prediction_market_agent_tooling-0.53.0.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.52.2.dist-info → prediction_market_agent_tooling-0.53.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
import typing as t
|
2
|
+
|
3
|
+
from pydantic import BaseModel
|
4
|
+
from sqlalchemy import Column
|
5
|
+
from sqlalchemy.dialects.postgresql import JSONB
|
6
|
+
from sqlmodel import ARRAY, Field, SQLModel, String
|
7
|
+
|
8
|
+
from prediction_market_agent_tooling.tools.utils import DatetimeUTC, utcnow
|
9
|
+
|
10
|
+
|
11
|
+
class TavilyResult(BaseModel):
|
12
|
+
title: str
|
13
|
+
url: str
|
14
|
+
content: str
|
15
|
+
score: float
|
16
|
+
raw_content: str | None
|
17
|
+
|
18
|
+
|
19
|
+
class TavilyResponse(BaseModel):
|
20
|
+
query: str
|
21
|
+
follow_up_questions: str | None = None
|
22
|
+
answer: str
|
23
|
+
images: list[str]
|
24
|
+
results: list[TavilyResult]
|
25
|
+
response_time: float
|
26
|
+
|
27
|
+
|
28
|
+
class TavilyResponseModel(SQLModel, table=True):
|
29
|
+
__tablename__ = "tavily_response"
|
30
|
+
__table_args__ = {"extend_existing": True}
|
31
|
+
id: int | None = Field(None, primary_key=True)
|
32
|
+
agent_id: str = Field(index=True, nullable=False)
|
33
|
+
# Parameters used to execute the search
|
34
|
+
query: str = Field(index=True, nullable=False)
|
35
|
+
search_depth: str
|
36
|
+
topic: str
|
37
|
+
days: int | None = Field(default=None, nullable=True)
|
38
|
+
max_results: int
|
39
|
+
include_domains: list[str] | None = Field(
|
40
|
+
None, sa_column=Column(ARRAY(String), nullable=True)
|
41
|
+
)
|
42
|
+
exclude_domains: list[str] | None = Field(
|
43
|
+
None, sa_column=Column(ARRAY(String), nullable=True)
|
44
|
+
)
|
45
|
+
include_answer: bool
|
46
|
+
include_raw_content: bool
|
47
|
+
include_images: bool
|
48
|
+
use_cache: bool
|
49
|
+
# Datetime at the time of search response and response from the search
|
50
|
+
datetime_: DatetimeUTC = Field(index=True, nullable=False)
|
51
|
+
response: dict[str, t.Any] = Field(sa_column=Column(JSONB, nullable=False))
|
52
|
+
|
53
|
+
@staticmethod
|
54
|
+
def from_model(
|
55
|
+
agent_id: str,
|
56
|
+
query: str,
|
57
|
+
search_depth: t.Literal["basic", "advanced"],
|
58
|
+
topic: t.Literal["general", "news"],
|
59
|
+
days: int | None,
|
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
|
+
days=days,
|
75
|
+
max_results=max_results,
|
76
|
+
include_domains=sorted(include_domains) if include_domains else None,
|
77
|
+
exclude_domains=sorted(exclude_domains) if exclude_domains else None,
|
78
|
+
include_answer=include_answer,
|
79
|
+
include_raw_content=include_raw_content,
|
80
|
+
include_images=include_images,
|
81
|
+
use_cache=use_cache,
|
82
|
+
datetime_=utcnow(),
|
83
|
+
response=response.model_dump(),
|
84
|
+
)
|
prediction_market_agent_tooling/tools/{tavily_storage/tavily_storage.py → tavily/tavily_search.py}
RENAMED
@@ -4,16 +4,20 @@ import tenacity
|
|
4
4
|
from tavily import TavilyClient
|
5
5
|
|
6
6
|
from prediction_market_agent_tooling.config import APIKeys
|
7
|
-
from prediction_market_agent_tooling.tools.
|
7
|
+
from prediction_market_agent_tooling.tools.tavily.tavily_models import (
|
8
8
|
TavilyResponse,
|
9
|
-
|
9
|
+
TavilyResult,
|
10
10
|
)
|
11
|
+
from prediction_market_agent_tooling.tools.tavily.tavily_storage import TavilyStorage
|
12
|
+
|
13
|
+
DEFAULT_SCORE_THRESHOLD = 0.75 # Based on some empirical testing, anything lower wasn't very relevant to the question being asked
|
11
14
|
|
12
15
|
|
13
16
|
def tavily_search(
|
14
17
|
query: str,
|
15
18
|
search_depth: t.Literal["basic", "advanced"] = "advanced",
|
16
19
|
topic: t.Literal["general", "news"] = "general",
|
20
|
+
days: int | None = None,
|
17
21
|
max_results: int = 5,
|
18
22
|
include_domains: t.Sequence[str] | None = None,
|
19
23
|
exclude_domains: t.Sequence[str] | None = None,
|
@@ -35,6 +39,7 @@ def tavily_search(
|
|
35
39
|
search_depth=search_depth,
|
36
40
|
topic=topic,
|
37
41
|
max_results=max_results,
|
42
|
+
days=days,
|
38
43
|
include_domains=include_domains,
|
39
44
|
exclude_domains=exclude_domains,
|
40
45
|
include_answer=include_answer,
|
@@ -49,6 +54,7 @@ def tavily_search(
|
|
49
54
|
search_depth=search_depth,
|
50
55
|
topic=topic,
|
51
56
|
max_results=max_results,
|
57
|
+
days=days,
|
52
58
|
include_domains=include_domains,
|
53
59
|
exclude_domains=exclude_domains,
|
54
60
|
include_answer=include_answer,
|
@@ -63,6 +69,7 @@ def tavily_search(
|
|
63
69
|
query=query,
|
64
70
|
search_depth=search_depth,
|
65
71
|
topic=topic,
|
72
|
+
days=days,
|
66
73
|
max_results=max_results,
|
67
74
|
include_domains=include_domains,
|
68
75
|
exclude_domains=exclude_domains,
|
@@ -80,6 +87,7 @@ def _tavily_search(
|
|
80
87
|
query: str,
|
81
88
|
search_depth: t.Literal["basic", "advanced"],
|
82
89
|
topic: t.Literal["general", "news"],
|
90
|
+
days: int | None,
|
83
91
|
max_results: int,
|
84
92
|
include_domains: t.Sequence[str] | None,
|
85
93
|
exclude_domains: t.Sequence[str] | None,
|
@@ -99,6 +107,7 @@ def _tavily_search(
|
|
99
107
|
query=query,
|
100
108
|
search_depth=search_depth,
|
101
109
|
topic=topic,
|
110
|
+
days=days,
|
102
111
|
max_results=max_results,
|
103
112
|
include_domains=include_domains,
|
104
113
|
exclude_domains=exclude_domains,
|
@@ -108,3 +117,20 @@ def _tavily_search(
|
|
108
117
|
use_cache=use_cache,
|
109
118
|
)
|
110
119
|
return response
|
120
|
+
|
121
|
+
|
122
|
+
def get_related_news_since(
|
123
|
+
question: str,
|
124
|
+
days_ago: int,
|
125
|
+
score_threshold: float = DEFAULT_SCORE_THRESHOLD,
|
126
|
+
max_results: int = 3,
|
127
|
+
tavily_storage: TavilyStorage | None = None,
|
128
|
+
) -> list[TavilyResult]:
|
129
|
+
news = tavily_search(
|
130
|
+
query=question,
|
131
|
+
days=days_ago,
|
132
|
+
max_results=max_results,
|
133
|
+
topic="news",
|
134
|
+
tavily_storage=tavily_storage,
|
135
|
+
)
|
136
|
+
return [r for r in news.results if r.score > score_threshold]
|
prediction_market_agent_tooling/tools/{tavily_storage/tavily_models.py → tavily/tavily_storage.py}
RENAMED
@@ -2,96 +2,15 @@ import typing as t
|
|
2
2
|
from datetime import timedelta
|
3
3
|
|
4
4
|
import tenacity
|
5
|
-
from
|
6
|
-
from sqlalchemy import Column
|
7
|
-
from sqlalchemy.dialects.postgresql import JSONB
|
8
|
-
from sqlmodel import (
|
9
|
-
ARRAY,
|
10
|
-
Field,
|
11
|
-
Session,
|
12
|
-
SQLModel,
|
13
|
-
String,
|
14
|
-
create_engine,
|
15
|
-
desc,
|
16
|
-
select,
|
17
|
-
)
|
5
|
+
from sqlmodel import Session, SQLModel, create_engine, desc, select
|
18
6
|
|
19
7
|
from prediction_market_agent_tooling.config import APIKeys
|
20
8
|
from prediction_market_agent_tooling.loggers import logger
|
21
|
-
from prediction_market_agent_tooling.tools.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
url: str
|
27
|
-
content: str
|
28
|
-
score: float
|
29
|
-
raw_content: str | None
|
30
|
-
|
31
|
-
|
32
|
-
class TavilyResponse(BaseModel):
|
33
|
-
query: str
|
34
|
-
follow_up_questions: None = None
|
35
|
-
answer: str
|
36
|
-
images: list[str]
|
37
|
-
results: list[TavilyResult]
|
38
|
-
response_time: float
|
39
|
-
|
40
|
-
|
41
|
-
class TavilyResponseModel(SQLModel, table=True):
|
42
|
-
__tablename__ = "tavily_response"
|
43
|
-
__table_args__ = {"extend_existing": True}
|
44
|
-
id: int | None = Field(None, primary_key=True)
|
45
|
-
agent_id: str = Field(index=True, nullable=False)
|
46
|
-
# Parameters used to execute the search
|
47
|
-
query: str = Field(index=True, nullable=False)
|
48
|
-
search_depth: str
|
49
|
-
topic: str
|
50
|
-
max_results: int
|
51
|
-
include_domains: list[str] | None = Field(
|
52
|
-
None, sa_column=Column(ARRAY(String), nullable=True)
|
53
|
-
)
|
54
|
-
exclude_domains: list[str] | None = Field(
|
55
|
-
None, sa_column=Column(ARRAY(String), nullable=True)
|
56
|
-
)
|
57
|
-
include_answer: bool
|
58
|
-
include_raw_content: bool
|
59
|
-
include_images: bool
|
60
|
-
use_cache: bool
|
61
|
-
# Datetime at the time of search response and response from the search
|
62
|
-
datetime_: DatetimeUTC = Field(index=True, nullable=False)
|
63
|
-
response: dict[str, t.Any] = Field(sa_column=Column(JSONB, nullable=False))
|
64
|
-
|
65
|
-
@staticmethod
|
66
|
-
def from_model(
|
67
|
-
agent_id: str,
|
68
|
-
query: str,
|
69
|
-
search_depth: t.Literal["basic", "advanced"],
|
70
|
-
topic: t.Literal["general", "news"],
|
71
|
-
max_results: int,
|
72
|
-
include_domains: t.Sequence[str] | None,
|
73
|
-
exclude_domains: t.Sequence[str] | None,
|
74
|
-
include_answer: bool,
|
75
|
-
include_raw_content: bool,
|
76
|
-
include_images: bool,
|
77
|
-
use_cache: bool,
|
78
|
-
response: TavilyResponse,
|
79
|
-
) -> "TavilyResponseModel":
|
80
|
-
return TavilyResponseModel(
|
81
|
-
agent_id=agent_id,
|
82
|
-
query=query,
|
83
|
-
search_depth=search_depth,
|
84
|
-
topic=topic,
|
85
|
-
max_results=max_results,
|
86
|
-
include_domains=sorted(include_domains) if include_domains else None,
|
87
|
-
exclude_domains=sorted(exclude_domains) if exclude_domains else None,
|
88
|
-
include_answer=include_answer,
|
89
|
-
include_raw_content=include_raw_content,
|
90
|
-
include_images=include_images,
|
91
|
-
use_cache=use_cache,
|
92
|
-
datetime_=utcnow(),
|
93
|
-
response=response.model_dump(),
|
94
|
-
)
|
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
|
95
14
|
|
96
15
|
|
97
16
|
class TavilyStorage:
|
@@ -119,6 +38,7 @@ class TavilyStorage:
|
|
119
38
|
query: str,
|
120
39
|
search_depth: t.Literal["basic", "advanced"],
|
121
40
|
topic: t.Literal["general", "news"],
|
41
|
+
days: int | None,
|
122
42
|
max_results: int,
|
123
43
|
include_domains: t.Sequence[str] | None,
|
124
44
|
exclude_domains: t.Sequence[str] | None,
|
@@ -134,6 +54,7 @@ class TavilyStorage:
|
|
134
54
|
search_depth=search_depth,
|
135
55
|
topic=topic,
|
136
56
|
max_results=max_results,
|
57
|
+
days=days,
|
137
58
|
include_domains=include_domains,
|
138
59
|
exclude_domains=exclude_domains,
|
139
60
|
include_answer=include_answer,
|
@@ -152,6 +73,7 @@ class TavilyStorage:
|
|
152
73
|
query: str,
|
153
74
|
search_depth: t.Literal["basic", "advanced"],
|
154
75
|
topic: t.Literal["general", "news"],
|
76
|
+
days: int | None,
|
155
77
|
max_results: int,
|
156
78
|
include_domains: t.Sequence[str] | None,
|
157
79
|
exclude_domains: t.Sequence[str] | None,
|
@@ -167,6 +89,7 @@ class TavilyStorage:
|
|
167
89
|
.where(TavilyResponseModel.query == query)
|
168
90
|
.where(TavilyResponseModel.search_depth == search_depth)
|
169
91
|
.where(TavilyResponseModel.topic == topic)
|
92
|
+
.where(TavilyResponseModel.days == days)
|
170
93
|
.where(TavilyResponseModel.max_results == max_results)
|
171
94
|
.where(TavilyResponseModel.include_domains == include_domains)
|
172
95
|
.where(TavilyResponseModel.exclude_domains == exclude_domains)
|
@@ -88,12 +88,13 @@ prediction_market_agent_tooling/tools/parallelism.py,sha256=6Gou0hbjtMZrYvxjTDFU
|
|
88
88
|
prediction_market_agent_tooling/tools/safe.py,sha256=h0xOO0eNtitClf0fPkn-0oTc6A_bflDTee98V_aiV-A,5195
|
89
89
|
prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0rnVhtQGzwoUdAgn_7u_GBM,729
|
90
90
|
prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
|
91
|
-
prediction_market_agent_tooling/tools/
|
92
|
-
prediction_market_agent_tooling/tools/
|
91
|
+
prediction_market_agent_tooling/tools/tavily/tavily_models.py,sha256=Rz4tZzwCRzPaq49SFT33SCRQrqHXtqWdD9ajb2tGCWc,2723
|
92
|
+
prediction_market_agent_tooling/tools/tavily/tavily_search.py,sha256=MK_ozeQbJ014HGiKFPDScjFYq0OGcjY1KPgc9A6qO0M,4511
|
93
|
+
prediction_market_agent_tooling/tools/tavily/tavily_storage.py,sha256=t-tZzbCzBBdFedRZDuVBn3A3mIDX8Z5wza6SxWswu_E,4093
|
93
94
|
prediction_market_agent_tooling/tools/utils.py,sha256=W-9SqeCKd51BYMRhDjYPQ7lfNO_zE9EvYpmu2r5WXGA,7163
|
94
95
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=dkcjG-LtuaWRh7WEMzRGmZ5B5rsxZTlliFOI6fj-EJ8,11842
|
95
|
-
prediction_market_agent_tooling-0.
|
96
|
-
prediction_market_agent_tooling-0.
|
97
|
-
prediction_market_agent_tooling-0.
|
98
|
-
prediction_market_agent_tooling-0.
|
99
|
-
prediction_market_agent_tooling-0.
|
96
|
+
prediction_market_agent_tooling-0.53.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
97
|
+
prediction_market_agent_tooling-0.53.0.dist-info/METADATA,sha256=RrGcyPVn2Gs6Xx9ezoDYzqUMAQfDZVlT63_Uq22GjSc,8056
|
98
|
+
prediction_market_agent_tooling-0.53.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
99
|
+
prediction_market_agent_tooling-0.53.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
100
|
+
prediction_market_agent_tooling-0.53.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|