kensho-kfinance 2.6.5__py3-none-any.whl → 2.7.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.
Potentially problematic release.
This version of kensho-kfinance might be problematic. Click here for more details.
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.7.0.dist-info}/METADATA +1 -1
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.7.0.dist-info}/RECORD +12 -12
- kfinance/CHANGELOG.md +3 -0
- kfinance/fetch.py +21 -0
- kfinance/kfinance.py +5 -0
- kfinance/tests/test_tools.py +28 -0
- kfinance/tool_calling/shared_models.py +19 -0
- kfinance/version.py +2 -2
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.7.0.dist-info}/WHEEL +0 -0
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.7.0.dist-info}/licenses/AUTHORS.md +0 -0
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.7.0.dist-info}/licenses/LICENSE +0 -0
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.7.0.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kensho-kfinance
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.7.0
|
|
4
4
|
Summary: Python CLI for kFinance
|
|
5
5
|
Author-email: Luke Brown <luke.brown@kensho.com>, Michelle Keoy <michelle.keoy@kensho.com>, Keith Page <keith.page@kensho.com>, Matthew Rosen <matthew.rosen@kensho.com>, Nick Roshdieh <nick.roshdieh@kensho.com>
|
|
6
6
|
Project-URL: source, https://github.com/kensho-technologies/kfinance
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
kensho_kfinance-2.
|
|
2
|
-
kensho_kfinance-2.
|
|
3
|
-
kfinance/CHANGELOG.md,sha256=
|
|
1
|
+
kensho_kfinance-2.7.0.dist-info/licenses/AUTHORS.md,sha256=0h9ClbI0pu1oKj1M28ROUsaxrbZg-6ukQGl6X4y9noI,68
|
|
2
|
+
kensho_kfinance-2.7.0.dist-info/licenses/LICENSE,sha256=bsY4blvSgq6o0FMQ3RXa2NCgco--nHCCchLXzxr6kms,83
|
|
3
|
+
kfinance/CHANGELOG.md,sha256=wNB99rvUBZsLmuCxq9ZtzvNpzeze8YmFz2HMdue3Di4,2175
|
|
4
4
|
kfinance/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
kfinance/batch_request_handling.py,sha256=G9rhpgQaCdb5C1dsfuJip8383iszibcOJ5k8gxld-tQ,5001
|
|
6
6
|
kfinance/constants.py,sha256=Zh7ruf-gFR6twCy5CUjOCgT_cGX-rgFdmR84AkcztYw,49453
|
|
7
|
-
kfinance/fetch.py,sha256=
|
|
8
|
-
kfinance/kfinance.py,sha256
|
|
7
|
+
kfinance/fetch.py,sha256=sDxO3loGNcn2aT8azXR6MlHHLyjYoWIKK1HpN2-fYu0,27682
|
|
8
|
+
kfinance/kfinance.py,sha256=MvEgcSDSiws3beJefQbOh3n8DdC6Wf33wiwf3Jfu6Mg,73194
|
|
9
9
|
kfinance/mcp.py,sha256=MbktclVfBOEwfe-eR7kPaTXopMJmn_8RMlf4Jx5CXKU,3689
|
|
10
10
|
kfinance/meta_classes.py,sha256=ulRNnWZ4P0HURs8XPzCTsJ3SYbvnT4SXyG4dIuITxAo,21766
|
|
11
11
|
kfinance/prompt.py,sha256=PtVB8c_FcSlVdyGgByAnIFGzuUuBaEjciCqnBJl1hSQ,25133
|
|
12
12
|
kfinance/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
kfinance/pydantic_models.py,sha256=avpbPqwrAyLqsCbrmFpK_B8_fj1nPlBHrnPxRcBaSkE,774
|
|
14
14
|
kfinance/server_thread.py,sha256=jUnt1YGoYDkqqz1MbCwd44zJs1T_Z2BCgvj75bdtLgA,2574
|
|
15
|
-
kfinance/version.py,sha256
|
|
15
|
+
kfinance/version.py,sha256=t0tYtjmuqfTGJQNs3pmrehzkGSiJlTwAuPRgzmcsAVU,511
|
|
16
16
|
kfinance/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
kfinance/tests/conftest.py,sha256=dhL_RSc-af3j-2_UrAGRE9mxgcbjuIRtj08DTx79pQc,1123
|
|
18
18
|
kfinance/tests/scratch.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -22,7 +22,7 @@ kfinance/tests/test_example_notebook.py,sha256=XHwDKw2avyMonTmi3snCcFWNfZhEJOkpB
|
|
|
22
22
|
kfinance/tests/test_fetch.py,sha256=mIj61dd843p3D1qtTAO60rZi6Rax0NgefOTTiBFrQcQ,17887
|
|
23
23
|
kfinance/tests/test_group_objects.py,sha256=SoMEZmkG4RYdgWOAwxLHHtzIQho92KM01YbQXPUg578,1689
|
|
24
24
|
kfinance/tests/test_objects.py,sha256=YlpxjlT1kJsDf4SgTZkhhthODwCnwNukJF_wvi11p3A,40805
|
|
25
|
-
kfinance/tests/test_tools.py,sha256=
|
|
25
|
+
kfinance/tests/test_tools.py,sha256=nq6xfnUYBm4uF_iGe2iLv6SXFesbEy4QyBk4ldXyhPk,30097
|
|
26
26
|
kfinance/tool_calling/README.md,sha256=omJq7Us6r4U45QB7hRpLjRJ5BMalCkZkh4uXBjTbJXc,2022
|
|
27
27
|
kfinance/tool_calling/__init__.py,sha256=UmtbtG6PvQHB1fInEL-K5q0kPHL__zTY9wzaPRSp1wg,2174
|
|
28
28
|
kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py,sha256=rrUVesFG3EpdVnvML42o6apJyBfWOBk0iYydJgIZaig,1615
|
|
@@ -47,8 +47,8 @@ kfinance/tool_calling/get_segments_from_identifier.py,sha256=-6I5pK_VSNxszUuQX6n
|
|
|
47
47
|
kfinance/tool_calling/get_transcript.py,sha256=2Vzab47kMw1288AubFXwhNGHtodmy_n2itITgk5szOg,767
|
|
48
48
|
kfinance/tool_calling/prompts.py,sha256=Yw1DJIMh90cjL-8q6_RMRiSjCtFDXvJAy7QiV5_uAU8,911
|
|
49
49
|
kfinance/tool_calling/resolve_identifier.py,sha256=_XEfGtDEB5tnAnseyQaugn4AuNsy6wZe5f-QOh8myko,632
|
|
50
|
-
kfinance/tool_calling/shared_models.py,sha256=
|
|
51
|
-
kensho_kfinance-2.
|
|
52
|
-
kensho_kfinance-2.
|
|
53
|
-
kensho_kfinance-2.
|
|
54
|
-
kensho_kfinance-2.
|
|
50
|
+
kfinance/tool_calling/shared_models.py,sha256=2KUY7PLFO-89Y6pYyDNbF8ub8KgWkay16683u8Wvf8Y,3731
|
|
51
|
+
kensho_kfinance-2.7.0.dist-info/METADATA,sha256=MGykZUh-nhnOLxDtjsY_rgKZX73bGLOJ5vg54yO_pY0,6197
|
|
52
|
+
kensho_kfinance-2.7.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
53
|
+
kensho_kfinance-2.7.0.dist-info/top_level.txt,sha256=kT_kNwVhfQoOAecY8W7uYah5xaHMoHoAdBIvXh6DaKM,9
|
|
54
|
+
kensho_kfinance-2.7.0.dist-info/RECORD,,
|
kfinance/CHANGELOG.md
CHANGED
kfinance/fetch.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from concurrent.futures import ThreadPoolExecutor
|
|
2
2
|
from contextlib import contextmanager
|
|
3
3
|
import logging
|
|
4
|
+
from queue import Queue
|
|
4
5
|
from time import time
|
|
5
6
|
from typing import Callable, Generator, Optional
|
|
6
7
|
from uuid import uuid4
|
|
@@ -95,6 +96,7 @@ class KFinanceApiClient:
|
|
|
95
96
|
self._batch_id: str | None = None
|
|
96
97
|
self._batch_size: str | None = None
|
|
97
98
|
self._user_permissions: set[Permission] | None = None
|
|
99
|
+
self._endpoint_tracker_queue: Queue[str] | None = None
|
|
98
100
|
|
|
99
101
|
@contextmanager
|
|
100
102
|
def batch_request_header(self, batch_size: int) -> Generator:
|
|
@@ -208,9 +210,28 @@ class KFinanceApiClient:
|
|
|
208
210
|
permission_str,
|
|
209
211
|
)
|
|
210
212
|
|
|
213
|
+
@contextmanager
|
|
214
|
+
def endpoint_tracker(self) -> Generator:
|
|
215
|
+
"""Context manager to track and return endpoint URLs in our thread-safe queue during execution.
|
|
216
|
+
|
|
217
|
+
endpoint_tracker yields a queue into which all endpoint URLs are written until the context manager gets exited.
|
|
218
|
+
It is up to the callers to dequeue the queue before the context manager gets exited and the queue gets wiped.
|
|
219
|
+
This functionality is currently used by `run_with_grounding` to collect and forward endpoint URLs.
|
|
220
|
+
"""
|
|
221
|
+
self._endpoint_tracker_queue = Queue[str]()
|
|
222
|
+
|
|
223
|
+
try:
|
|
224
|
+
yield self._endpoint_tracker_queue
|
|
225
|
+
finally:
|
|
226
|
+
self._endpoint_tracker_queue = None
|
|
227
|
+
|
|
211
228
|
def fetch(self, url: str) -> dict:
|
|
212
229
|
"""Does the request and auth"""
|
|
213
230
|
|
|
231
|
+
# _endpoint_tracker_queue will only be initialized if inside the endpoint_tracker context manager
|
|
232
|
+
if self._endpoint_tracker_queue:
|
|
233
|
+
self._endpoint_tracker_queue.put(url)
|
|
234
|
+
|
|
214
235
|
headers = {
|
|
215
236
|
"Content-Type": "application/json",
|
|
216
237
|
"Authorization": f"Bearer {self.access_token}",
|
kfinance/kfinance.py
CHANGED
|
@@ -1663,6 +1663,11 @@ class Client:
|
|
|
1663
1663
|
"""
|
|
1664
1664
|
return {t.name: t.run_without_langchain for t in self.langchain_tools}
|
|
1665
1665
|
|
|
1666
|
+
@property
|
|
1667
|
+
def grounding_tools(self) -> dict[str, Callable]:
|
|
1668
|
+
"""Return a mapping of tool calling function names to the corresponding functions for the grounding agent."""
|
|
1669
|
+
return {t.name: t.run_with_grounding for t in self.langchain_tools}
|
|
1670
|
+
|
|
1666
1671
|
@property
|
|
1667
1672
|
def anthropic_tool_descriptions(self) -> list[dict[str, Any]]:
|
|
1668
1673
|
"""Return tool descriptions for anthropic"""
|
kfinance/tests/test_tools.py
CHANGED
|
@@ -722,6 +722,34 @@ class TestGetCompetitorsFromIdentifier:
|
|
|
722
722
|
assert response == expected_competitors_response
|
|
723
723
|
|
|
724
724
|
|
|
725
|
+
class TestGetEndpointsFromToolCallsWithGrounding:
|
|
726
|
+
def test_get_info_from_identifier_with_grounding(
|
|
727
|
+
self, mock_client: Client, requests_mock: Mocker
|
|
728
|
+
):
|
|
729
|
+
"""
|
|
730
|
+
GIVEN a KfinanceTool tool
|
|
731
|
+
WHEN we run the tool with `run_with_grounding`
|
|
732
|
+
THEN we get back endpoint urls in addition to the usual tool response.
|
|
733
|
+
"""
|
|
734
|
+
|
|
735
|
+
# truncated from the original
|
|
736
|
+
resp_data = "{'name': 'S&P Global Inc.', 'status': 'Operating'}"
|
|
737
|
+
resp_endpoint = [
|
|
738
|
+
"https://kfinance.kensho.com/api/v1/id/SPGI",
|
|
739
|
+
"https://kfinance.kensho.com/api/v1/info/21719",
|
|
740
|
+
]
|
|
741
|
+
expected_resp = {"data": resp_data, "endpoint_urls": resp_endpoint}
|
|
742
|
+
|
|
743
|
+
requests_mock.get(
|
|
744
|
+
url=f"https://kfinance.kensho.com/api/v1/info/{SPGI_COMPANY_ID}",
|
|
745
|
+
json=resp_data,
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
tool = GetInfoFromIdentifier(kfinance_client=mock_client)
|
|
749
|
+
resp = tool.run_with_grounding(identifier="SPGI")
|
|
750
|
+
assert resp == expected_resp
|
|
751
|
+
|
|
752
|
+
|
|
725
753
|
class TestValidQuarter:
|
|
726
754
|
class QuarterModel(BaseModel):
|
|
727
755
|
quarter: ValidQuarter | None
|
|
@@ -40,6 +40,25 @@ class KfinanceTool(BaseTool):
|
|
|
40
40
|
args_dict = {k: v for k, v in args_dict.items() if k in kwargs}
|
|
41
41
|
return self._run(**args_dict)
|
|
42
42
|
|
|
43
|
+
def run_with_grounding(self, *args: Any, **kwargs: Any) -> Any:
|
|
44
|
+
"""Execute a Kfinance tool with grounding support.
|
|
45
|
+
|
|
46
|
+
This is a wrapper around the `run_without_langchain` method that adds grounding
|
|
47
|
+
support, for returning the endpoint urls along with the data as citation info for the LRA Data Agent.
|
|
48
|
+
"""
|
|
49
|
+
with self.kfinance_client.kfinance_api_client.endpoint_tracker() as endpoint_tracker_queue:
|
|
50
|
+
data = self.run_without_langchain(*args, **kwargs)
|
|
51
|
+
|
|
52
|
+
# After completion of tool data fetching and within the endpoint_tracker context manager scope, dequeue the endpoint_tracker_queue
|
|
53
|
+
endpoint_urls = []
|
|
54
|
+
while not endpoint_tracker_queue.empty():
|
|
55
|
+
endpoint_urls.append(endpoint_tracker_queue.get())
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
"data": data,
|
|
59
|
+
"endpoint_urls": endpoint_urls,
|
|
60
|
+
}
|
|
61
|
+
|
|
43
62
|
def _run(self, *args: Any, **kwargs: Any) -> Any:
|
|
44
63
|
"""The code to execute the tool"""
|
|
45
64
|
...
|
kfinance/version.py
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|