kensho-kfinance 2.6.5__tar.gz → 2.7.0__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.

Potentially problematic release.


This version of kensho-kfinance might be problematic. Click here for more details.

Files changed (88) hide show
  1. {kensho_kfinance-2.6.5/kensho_kfinance.egg-info → kensho_kfinance-2.7.0}/PKG-INFO +1 -1
  2. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0/kensho_kfinance.egg-info}/PKG-INFO +1 -1
  3. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/CHANGELOG.md +3 -0
  4. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/fetch.py +21 -0
  5. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/kfinance.py +5 -0
  6. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_tools.py +28 -0
  7. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/shared_models.py +19 -0
  8. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/version.py +2 -2
  9. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/.coveragerc +0 -0
  10. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/.github/workflows/ci-lint.yml +0 -0
  11. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/.github/workflows/ci-test.yml +0 -0
  12. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/.github/workflows/python-publish.yml +0 -0
  13. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/.gitignore +0 -0
  14. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/.readthedocs.yaml +0 -0
  15. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/AUTHORS.md +0 -0
  16. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/CODE_OF_CONDUCT.md +0 -0
  17. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/CONTRIBUTING.md +0 -0
  18. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/LICENSE +0 -0
  19. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/README.md +0 -0
  20. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/build_tool_calling_documentation.py +0 -0
  21. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/conf.py +0 -0
  22. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/index.rst +0 -0
  23. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/kfinance.rst +0 -0
  24. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/requirements.txt +0 -0
  25. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/templates/apidoc/package.rst_t +0 -0
  26. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/templates/apidoc/toc.rst_t +0 -0
  27. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/docs/tool_calling.rst +0 -0
  28. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/basic_usage.ipynb +0 -0
  29. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/tool_calling/langchain/anthropic_langchain_tool_calling.ipynb +0 -0
  30. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/tool_calling/langchain/google_gemini_langchain_tool_calling.ipynb +0 -0
  31. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/tool_calling/langchain/openai_langchain_tool_calling.ipynb +0 -0
  32. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/tool_calling/non-langchain/anthropic_tool_calling.ipynb +0 -0
  33. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/tool_calling/non-langchain/google_gemini_tool_calling.ipynb +0 -0
  34. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/example_notebooks/tool_calling/non-langchain/openai_langchain_tool_calling.ipynb +0 -0
  35. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/images/colab_logo_32px.png +0 -0
  36. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/justfile +0 -0
  37. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kensho_kfinance.egg-info/SOURCES.txt +0 -0
  38. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
  39. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kensho_kfinance.egg-info/requires.txt +0 -0
  40. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kensho_kfinance.egg-info/top_level.txt +0 -0
  41. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/__init__.py +0 -0
  42. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/batch_request_handling.py +0 -0
  43. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/constants.py +0 -0
  44. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/mcp.py +0 -0
  45. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/meta_classes.py +0 -0
  46. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/prompt.py +0 -0
  47. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/py.typed +0 -0
  48. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/pydantic_models.py +0 -0
  49. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/server_thread.py +0 -0
  50. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/__init__.py +0 -0
  51. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/conftest.py +0 -0
  52. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/scratch.py +0 -0
  53. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_batch_requests.py +0 -0
  54. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_client.py +0 -0
  55. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_example_notebook.py +0 -0
  56. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_fetch.py +0 -0
  57. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_group_objects.py +0 -0
  58. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tests/test_objects.py +0 -0
  59. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/README.md +0 -0
  60. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/__init__.py +0 -0
  61. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +0 -0
  62. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_business_relationship_from_identifier.py +0 -0
  63. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_capitalization_from_identifier.py +0 -0
  64. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_competitors_from_identifier.py +0 -0
  65. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_cusip_from_ticker.py +0 -0
  66. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_earnings.py +0 -0
  67. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_financial_line_item_from_identifier.py +0 -0
  68. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_financial_statement_from_identifier.py +0 -0
  69. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_history_metadata_from_identifier.py +0 -0
  70. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_info_from_identifier.py +0 -0
  71. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_isin_from_ticker.py +0 -0
  72. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_latest.py +0 -0
  73. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_latest_earnings.py +0 -0
  74. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_merger_info_from_transaction_id.py +0 -0
  75. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_mergers_from_identifier.py +0 -0
  76. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_n_quarters_ago.py +0 -0
  77. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_next_earnings.py +0 -0
  78. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_prices_from_identifier.py +0 -0
  79. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_segments_from_identifier.py +0 -0
  80. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/get_transcript.py +0 -0
  81. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/prompts.py +0 -0
  82. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/kfinance/tool_calling/resolve_identifier.py +0 -0
  83. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/pyproject.toml +0 -0
  84. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/scripts/copyright_line_check.sh +0 -0
  85. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/scripts/lint.sh +0 -0
  86. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/scripts/test.sh +0 -0
  87. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/setup.cfg +0 -0
  88. {kensho_kfinance-2.6.5 → kensho_kfinance-2.7.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 2.6.5
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 2.6.5
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,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.7.0
4
+ - Expose a new list of LLM tools `grounding_tools` that return a list of all endpoint urls called
5
+
3
6
  ## v2.6.5
4
7
  - Add competitor company_name
5
8
 
@@ -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}",
@@ -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"""
@@ -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
  ...
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '2.6.5'
21
- __version_tuple__ = version_tuple = (2, 6, 5)
20
+ __version__ = version = '2.7.0'
21
+ __version_tuple__ = version_tuple = (2, 7, 0)
File without changes