kensho-kfinance 3.2.4__py3-none-any.whl → 3.2.6__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.

Files changed (43) hide show
  1. {kensho_kfinance-3.2.4.dist-info → kensho_kfinance-3.2.6.dist-info}/METADATA +1 -1
  2. {kensho_kfinance-3.2.4.dist-info → kensho_kfinance-3.2.6.dist-info}/RECORD +43 -43
  3. kfinance/CHANGELOG.md +6 -0
  4. kfinance/client/fetch.py +7 -5
  5. kfinance/client/kfinance.py +38 -39
  6. kfinance/client/models/date_and_period_models.py +8 -7
  7. kfinance/client/tests/test_fetch.py +3 -1
  8. kfinance/client/tests/test_objects.py +38 -95
  9. kfinance/domains/business_relationships/business_relationship_tools.py +4 -4
  10. kfinance/domains/business_relationships/tests/test_business_relationship_tools.py +18 -16
  11. kfinance/domains/capitalizations/capitalization_models.py +3 -3
  12. kfinance/domains/capitalizations/capitalization_tools.py +7 -5
  13. kfinance/domains/capitalizations/tests/test_capitalization_tools.py +46 -36
  14. kfinance/domains/companies/company_tools.py +8 -12
  15. kfinance/domains/companies/tests/test_company_tools.py +21 -9
  16. kfinance/domains/competitors/competitor_tools.py +2 -3
  17. kfinance/domains/competitors/tests/test_competitor_tools.py +22 -19
  18. kfinance/domains/cusip_and_isin/cusip_and_isin_tools.py +4 -6
  19. kfinance/domains/cusip_and_isin/tests/test_cusip_and_isin_tools.py +13 -8
  20. kfinance/domains/earnings/earning_tools.py +12 -9
  21. kfinance/domains/earnings/tests/test_earnings_tools.py +52 -43
  22. kfinance/domains/line_items/line_item_models.py +121 -0
  23. kfinance/domains/line_items/line_item_tools.py +2 -3
  24. kfinance/domains/line_items/tests/test_line_item_tools.py +20 -23
  25. kfinance/domains/mergers_and_acquisitions/merger_and_acquisition_models.py +46 -2
  26. kfinance/domains/mergers_and_acquisitions/merger_and_acquisition_tools.py +13 -68
  27. kfinance/domains/mergers_and_acquisitions/tests/test_merger_and_acquisition_tools.py +61 -59
  28. kfinance/domains/prices/price_tools.py +4 -7
  29. kfinance/domains/prices/tests/test_price_tools.py +47 -39
  30. kfinance/domains/segments/segment_tools.py +2 -3
  31. kfinance/domains/segments/tests/test_segment_tools.py +16 -11
  32. kfinance/domains/statements/statement_tools.py +2 -3
  33. kfinance/domains/statements/tests/test_statement_tools.py +40 -35
  34. kfinance/integrations/tool_calling/static_tools/get_n_quarters_ago.py +5 -0
  35. kfinance/integrations/tool_calling/static_tools/tests/test_get_lastest.py +13 -10
  36. kfinance/integrations/tool_calling/static_tools/tests/test_get_n_quarters_ago.py +2 -1
  37. kfinance/integrations/tool_calling/tests/test_tool_calling_models.py +8 -2
  38. kfinance/integrations/tool_calling/tool_calling_models.py +11 -5
  39. kfinance/version.py +2 -2
  40. {kensho_kfinance-3.2.4.dist-info → kensho_kfinance-3.2.6.dist-info}/WHEEL +0 -0
  41. {kensho_kfinance-3.2.4.dist-info → kensho_kfinance-3.2.6.dist-info}/licenses/AUTHORS.md +0 -0
  42. {kensho_kfinance-3.2.4.dist-info → kensho_kfinance-3.2.6.dist-info}/licenses/LICENSE +0 -0
  43. {kensho_kfinance-3.2.4.dist-info → kensho_kfinance-3.2.6.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,4 @@
1
+ import abc
1
2
  from typing import Annotated, Any, Callable, Dict, Literal, Type
2
3
 
3
4
  from langchain_core.tools import BaseTool
@@ -22,7 +23,7 @@ class KfinanceTool(BaseTool):
22
23
 
23
24
  model_config = ConfigDict(extra="forbid")
24
25
 
25
- def run_without_langchain(self, *args: Any, **kwargs: Any) -> Any:
26
+ def run_without_langchain(self, *args: Any, **kwargs: Any) -> dict:
26
27
  """Execute a Kfinance tool without langchain.
27
28
 
28
29
  Langchain converts json input params into the pydantic args_schema, which means that
@@ -38,7 +39,8 @@ class KfinanceTool(BaseTool):
38
39
  # This behavior matches the langchain handling. See
39
40
  # https://github.com/langchain-ai/langchain/blob/ca39680d2ab0d786bc035930778a5787e7bb5e01/libs/core/langchain_core/tools/base.py#L595-L597
40
41
  args_dict = {k: v for k, v in args_dict.items() if k in kwargs}
41
- return self._run(**args_dict)
42
+ result_model = self._run(**args_dict)
43
+ return result_model.model_dump(mode="json", exclude_none=True)
42
44
 
43
45
  def run_with_grounding(self, *args: Any, **kwargs: Any) -> Any:
44
46
  """Execute a Kfinance tool with grounding support.
@@ -47,7 +49,10 @@ class KfinanceTool(BaseTool):
47
49
  support, for returning the endpoint urls along with the data as citation info for the LRA Data Agent.
48
50
  """
49
51
  with self.kfinance_client.kfinance_api_client.endpoint_tracker() as endpoint_tracker_queue:
50
- data = self.run_without_langchain(*args, **kwargs)
52
+ args_model = self.args_schema.model_validate(kwargs)
53
+ args_dict = args_model.model_dump()
54
+ args_dict = {k: v for k, v in args_dict.items() if k in kwargs}
55
+ result_model = self._run(**args_dict)
51
56
 
52
57
  # After completion of tool data fetching and within the endpoint_tracker context manager scope, dequeue the endpoint_tracker_queue
53
58
  endpoint_urls = []
@@ -55,11 +60,12 @@ class KfinanceTool(BaseTool):
55
60
  endpoint_urls.append(endpoint_tracker_queue.get())
56
61
 
57
62
  return {
58
- "data": data,
63
+ "data": result_model,
59
64
  "endpoint_urls": endpoint_urls,
60
65
  }
61
66
 
62
- def _run(self, *args: Any, **kwargs: Any) -> Any:
67
+ @abc.abstractmethod
68
+ def _run(self, *args: Any, **kwargs: Any) -> BaseModel:
63
69
  """The code to execute the tool.
64
70
 
65
71
  Where feasible and useful, tools should use batch processing to parallelize
kfinance/version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '3.2.4'
32
- __version_tuple__ = version_tuple = (3, 2, 4)
31
+ __version__ = version = '3.2.6'
32
+ __version_tuple__ = version_tuple = (3, 2, 6)
33
33
 
34
34
  __commit_id__ = commit_id = None