kensho-kfinance 2.6.5__py3-none-any.whl → 2.8.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.8.0.dist-info}/METADATA +1 -1
- kensho_kfinance-2.8.0.dist-info/RECORD +70 -0
- kfinance/CHANGELOG.md +6 -0
- kfinance/decimal_with_unit.py +78 -0
- kfinance/fetch.py +36 -16
- kfinance/kfinance.py +45 -44
- kfinance/meta_classes.py +28 -27
- kfinance/models/business_relationship_models.py +26 -0
- kfinance/models/capitalization_models.py +90 -0
- kfinance/models/competitor_models.py +13 -0
- kfinance/models/currency_models.py +345 -0
- kfinance/models/date_and_period_models.py +48 -0
- kfinance/models/id_models.py +7 -0
- kfinance/models/industry_models.py +12 -0
- kfinance/{constants.py → models/line_item_models.py} +1 -165
- kfinance/models/permission_models.py +15 -0
- kfinance/models/price_models.py +70 -0
- kfinance/models/segment_models.py +8 -0
- kfinance/models/statement_models.py +9 -0
- kfinance/tests/test_batch_requests.py +61 -31
- kfinance/tests/test_client.py +1 -1
- kfinance/tests/test_decimal_with_unit.py +60 -0
- kfinance/tests/test_example_notebook.py +1 -0
- kfinance/tests/test_fetch.py +23 -12
- kfinance/tests/test_models/__init__.py +0 -0
- kfinance/tests/test_models/test_capitalization_models.py +83 -0
- kfinance/tests/test_models/test_price_models.py +58 -0
- kfinance/tests/test_objects.py +29 -23
- kfinance/tests/test_tools.py +63 -11
- kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +1 -1
- kfinance/tool_calling/get_business_relationship_from_identifier.py +2 -1
- kfinance/tool_calling/get_capitalization_from_identifier.py +4 -5
- kfinance/tool_calling/get_competitors_from_identifier.py +2 -1
- kfinance/tool_calling/get_cusip_from_ticker.py +1 -1
- kfinance/tool_calling/get_earnings.py +1 -1
- kfinance/tool_calling/get_financial_line_item_from_identifier.py +3 -1
- kfinance/tool_calling/get_financial_statement_from_identifier.py +3 -1
- kfinance/tool_calling/get_history_metadata_from_identifier.py +2 -1
- kfinance/tool_calling/get_info_from_identifier.py +1 -1
- kfinance/tool_calling/get_isin_from_ticker.py +1 -1
- kfinance/tool_calling/get_latest.py +2 -1
- kfinance/tool_calling/get_latest_earnings.py +1 -1
- kfinance/tool_calling/get_merger_info_from_transaction_id.py +1 -1
- kfinance/tool_calling/get_mergers_from_identifier.py +1 -1
- kfinance/tool_calling/get_n_quarters_ago.py +2 -1
- kfinance/tool_calling/get_next_earnings.py +1 -1
- kfinance/tool_calling/get_prices_from_identifier.py +4 -3
- kfinance/tool_calling/get_segments_from_identifier.py +3 -1
- kfinance/tool_calling/get_transcript.py +1 -1
- kfinance/tool_calling/resolve_identifier.py +1 -1
- kfinance/tool_calling/shared_models.py +20 -1
- kfinance/version.py +2 -2
- kensho_kfinance-2.6.5.dist-info/RECORD +0 -54
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.8.0.dist-info}/WHEEL +0 -0
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.8.0.dist-info}/licenses/AUTHORS.md +0 -0
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.8.0.dist-info}/licenses/LICENSE +0 -0
- {kensho_kfinance-2.6.5.dist-info → kensho_kfinance-2.8.0.dist-info}/top_level.txt +0 -0
- /kfinance/{tests/scratch.py → models/__init__.py} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from decimal import Decimal
|
|
2
|
+
|
|
3
|
+
from kfinance.decimal_with_unit import Money, Shares
|
|
4
|
+
from kfinance.models.price_models import PriceHistory, Prices
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestPriceHistory:
|
|
8
|
+
api_resp = {
|
|
9
|
+
"currency": "USD",
|
|
10
|
+
"prices": [
|
|
11
|
+
{
|
|
12
|
+
"date": "2024-06-25",
|
|
13
|
+
"open": "445.790000",
|
|
14
|
+
"high": "449.240000",
|
|
15
|
+
"low": "442.770000",
|
|
16
|
+
"close": "448.780000",
|
|
17
|
+
"volume": "999134",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "2024-06-26",
|
|
21
|
+
"open": "446.320000",
|
|
22
|
+
"high": "449.120000",
|
|
23
|
+
"low": "443.560000",
|
|
24
|
+
"close": "448.360000",
|
|
25
|
+
"volume": "1630769",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def test_price_history_deserialization(self) -> None:
|
|
31
|
+
"""
|
|
32
|
+
GIVEN a price history API response
|
|
33
|
+
WHEN we deserialize the response into a PriceHistory object
|
|
34
|
+
THEN the deserialization succeeds and returns the expected value.
|
|
35
|
+
"""
|
|
36
|
+
expected_price_history = PriceHistory.model_construct(
|
|
37
|
+
prices=[
|
|
38
|
+
Prices(
|
|
39
|
+
date="2024-06-25",
|
|
40
|
+
open=Money(value=Decimal("445.79"), unit="USD", conventional_decimals=2),
|
|
41
|
+
high=Money(value=Decimal("449.24"), unit="USD", conventional_decimals=2),
|
|
42
|
+
low=Money(value=Decimal("442.77"), unit="USD", conventional_decimals=2),
|
|
43
|
+
close=Money(value=Decimal("448.78"), unit="USD", conventional_decimals=2),
|
|
44
|
+
volume=Shares(value=Decimal("999134"), unit="Shares", conventional_decimals=0),
|
|
45
|
+
),
|
|
46
|
+
Prices(
|
|
47
|
+
date="2024-06-26",
|
|
48
|
+
open=Money(value=Decimal("446.32"), unit="USD", conventional_decimals=2),
|
|
49
|
+
high=Money(value=Decimal("449.12"), unit="USD", conventional_decimals=2),
|
|
50
|
+
low=Money(value=Decimal("443.56"), unit="USD", conventional_decimals=2),
|
|
51
|
+
close=Money(value=Decimal("448.36"), unit="USD", conventional_decimals=2),
|
|
52
|
+
volume=Shares(value=Decimal("1630769"), unit="Shares", conventional_decimals=0),
|
|
53
|
+
),
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
price_history = PriceHistory.model_validate(self.api_resp)
|
|
58
|
+
assert price_history == expected_price_history
|
kfinance/tests/test_objects.py
CHANGED
|
@@ -10,7 +10,6 @@ import pandas as pd
|
|
|
10
10
|
from PIL.Image import open as image_open
|
|
11
11
|
import time_machine
|
|
12
12
|
|
|
13
|
-
from kfinance.constants import BusinessRelationshipType
|
|
14
13
|
from kfinance.kfinance import (
|
|
15
14
|
AdvisedCompany,
|
|
16
15
|
BusinessRelationships,
|
|
@@ -22,6 +21,8 @@ from kfinance.kfinance import (
|
|
|
22
21
|
TradingItem,
|
|
23
22
|
Transcript,
|
|
24
23
|
)
|
|
24
|
+
from kfinance.models.business_relationship_models import BusinessRelationshipType
|
|
25
|
+
from kfinance.models.capitalization_models import Capitalizations
|
|
25
26
|
from kfinance.pydantic_models import CompanyIdAndName, RelationshipResponse
|
|
26
27
|
|
|
27
28
|
|
|
@@ -329,23 +330,26 @@ class MockKFinanceApiClient:
|
|
|
329
330
|
company_id: int,
|
|
330
331
|
start_date: Optional[str] = None,
|
|
331
332
|
end_date: Optional[str] = None,
|
|
332
|
-
) ->
|
|
333
|
-
return
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
333
|
+
) -> Capitalizations:
|
|
334
|
+
return Capitalizations.model_validate(
|
|
335
|
+
{
|
|
336
|
+
"currency": "USD",
|
|
337
|
+
"market_caps": [
|
|
338
|
+
{
|
|
339
|
+
"date": "2025-01-01",
|
|
340
|
+
"market_cap": "3133802247084.000000",
|
|
341
|
+
"tev": "3152211247084.000000",
|
|
342
|
+
"shares_outstanding": 7434880776,
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"date": "2025-01-02",
|
|
346
|
+
"market_cap": "3112092395218.000000",
|
|
347
|
+
"tev": "3130501395218.000000",
|
|
348
|
+
"shares_outstanding": 7434880776,
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
}
|
|
352
|
+
)
|
|
349
353
|
|
|
350
354
|
def fetch_segments(
|
|
351
355
|
self,
|
|
@@ -843,12 +847,14 @@ class TestTicker(TestCase):
|
|
|
843
847
|
THEN the Ticker object can correctly extract market caps from the dict.
|
|
844
848
|
"""
|
|
845
849
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
+
expected_response = {
|
|
851
|
+
"market_cap": [
|
|
852
|
+
{"2025-01-01": {"unit": "USD", "value": "3133802247084.00"}},
|
|
853
|
+
{"2025-01-02": {"unit": "USD", "value": "3112092395218.00"}},
|
|
854
|
+
]
|
|
855
|
+
}
|
|
850
856
|
market_caps = self.msft_ticker_from_ticker.market_cap()
|
|
851
|
-
|
|
857
|
+
assert market_caps == expected_response
|
|
852
858
|
|
|
853
859
|
|
|
854
860
|
class TestTranscript(TestCase):
|
kfinance/tests/test_tools.py
CHANGED
|
@@ -9,14 +9,12 @@ from pytest import raises
|
|
|
9
9
|
from requests_mock import Mocker
|
|
10
10
|
import time_machine
|
|
11
11
|
|
|
12
|
-
from kfinance.constants import (
|
|
13
|
-
BusinessRelationshipType,
|
|
14
|
-
Capitalization,
|
|
15
|
-
CompetitorSource,
|
|
16
|
-
SegmentType,
|
|
17
|
-
StatementType,
|
|
18
|
-
)
|
|
19
12
|
from kfinance.kfinance import Client, NoEarningsDataError
|
|
13
|
+
from kfinance.models.business_relationship_models import BusinessRelationshipType
|
|
14
|
+
from kfinance.models.capitalization_models import Capitalization
|
|
15
|
+
from kfinance.models.competitor_models import CompetitorSource
|
|
16
|
+
from kfinance.models.segment_models import SegmentType
|
|
17
|
+
from kfinance.models.statement_models import StatementType
|
|
20
18
|
from kfinance.tests.conftest import SPGI_COMPANY_ID, SPGI_SECURITY_ID, SPGI_TRADING_ITEM_ID
|
|
21
19
|
from kfinance.tests.test_objects import MOCK_COMPANY_DB, MOCK_MERGERS_DB, ordered
|
|
22
20
|
from kfinance.tool_calling import (
|
|
@@ -164,6 +162,7 @@ class TestGetCapitalizationFromIdentifier:
|
|
|
164
162
|
requests_mock.get(
|
|
165
163
|
url=f"https://kfinance.kensho.com/api/v1/market_cap/{SPGI_COMPANY_ID}/none/none",
|
|
166
164
|
json={
|
|
165
|
+
"currency": "USD",
|
|
167
166
|
"market_caps": [
|
|
168
167
|
{
|
|
169
168
|
"date": "2024-04-10",
|
|
@@ -177,11 +176,16 @@ class TestGetCapitalizationFromIdentifier:
|
|
|
177
176
|
"tev": "147105066761.000000",
|
|
178
177
|
"shares_outstanding": 313099562,
|
|
179
178
|
},
|
|
180
|
-
]
|
|
179
|
+
],
|
|
181
180
|
},
|
|
182
181
|
)
|
|
183
182
|
|
|
184
|
-
expected_response =
|
|
183
|
+
expected_response = {
|
|
184
|
+
"market_cap": [
|
|
185
|
+
{"2024-04-10": {"unit": "USD", "value": "132766738270.00"}},
|
|
186
|
+
{"2024-04-11": {"unit": "USD", "value": "132416066761.00"}},
|
|
187
|
+
]
|
|
188
|
+
}
|
|
185
189
|
|
|
186
190
|
tool = GetCapitalizationFromIdentifier(kfinance_client=mock_client)
|
|
187
191
|
args = GetCapitalizationFromIdentifierArgs(
|
|
@@ -442,6 +446,7 @@ class TestPricesFromIdentifier:
|
|
|
442
446
|
url=f"https://kfinance.kensho.com/api/v1/pricing/{SPGI_TRADING_ITEM_ID}/none/none/day/adjusted",
|
|
443
447
|
# truncated response
|
|
444
448
|
json={
|
|
449
|
+
"currency": "USD",
|
|
445
450
|
"prices": [
|
|
446
451
|
{
|
|
447
452
|
"date": "2024-04-11",
|
|
@@ -459,10 +464,29 @@ class TestPricesFromIdentifier:
|
|
|
459
464
|
"close": "417.810000",
|
|
460
465
|
"volume": "1182229",
|
|
461
466
|
},
|
|
462
|
-
]
|
|
467
|
+
],
|
|
463
468
|
},
|
|
464
469
|
)
|
|
465
|
-
expected_response =
|
|
470
|
+
expected_response = {
|
|
471
|
+
"prices": [
|
|
472
|
+
{
|
|
473
|
+
"date": "2024-04-11",
|
|
474
|
+
"open": {"value": "424.26", "unit": "USD"},
|
|
475
|
+
"high": {"value": "425.99", "unit": "USD"},
|
|
476
|
+
"low": {"value": "422.04", "unit": "USD"},
|
|
477
|
+
"close": {"value": "422.92", "unit": "USD"},
|
|
478
|
+
"volume": {"value": "1129158", "unit": "Shares"},
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"date": "2024-04-12",
|
|
482
|
+
"open": {"value": "419.23", "unit": "USD"},
|
|
483
|
+
"high": {"value": "421.94", "unit": "USD"},
|
|
484
|
+
"low": {"value": "416.45", "unit": "USD"},
|
|
485
|
+
"close": {"value": "417.81", "unit": "USD"},
|
|
486
|
+
"volume": {"value": "1182229", "unit": "Shares"},
|
|
487
|
+
},
|
|
488
|
+
]
|
|
489
|
+
}
|
|
466
490
|
|
|
467
491
|
tool = GetPricesFromIdentifier(kfinance_client=mock_client)
|
|
468
492
|
response = tool.run(GetPricesFromIdentifierArgs(identifier="SPGI").model_dump(mode="json"))
|
|
@@ -722,6 +746,34 @@ class TestGetCompetitorsFromIdentifier:
|
|
|
722
746
|
assert response == expected_competitors_response
|
|
723
747
|
|
|
724
748
|
|
|
749
|
+
class TestGetEndpointsFromToolCallsWithGrounding:
|
|
750
|
+
def test_get_info_from_identifier_with_grounding(
|
|
751
|
+
self, mock_client: Client, requests_mock: Mocker
|
|
752
|
+
):
|
|
753
|
+
"""
|
|
754
|
+
GIVEN a KfinanceTool tool
|
|
755
|
+
WHEN we run the tool with `run_with_grounding`
|
|
756
|
+
THEN we get back endpoint urls in addition to the usual tool response.
|
|
757
|
+
"""
|
|
758
|
+
|
|
759
|
+
# truncated from the original
|
|
760
|
+
resp_data = "{'name': 'S&P Global Inc.', 'status': 'Operating'}"
|
|
761
|
+
resp_endpoint = [
|
|
762
|
+
"https://kfinance.kensho.com/api/v1/id/SPGI",
|
|
763
|
+
"https://kfinance.kensho.com/api/v1/info/21719",
|
|
764
|
+
]
|
|
765
|
+
expected_resp = {"data": resp_data, "endpoint_urls": resp_endpoint}
|
|
766
|
+
|
|
767
|
+
requests_mock.get(
|
|
768
|
+
url=f"https://kfinance.kensho.com/api/v1/info/{SPGI_COMPANY_ID}",
|
|
769
|
+
json=resp_data,
|
|
770
|
+
)
|
|
771
|
+
|
|
772
|
+
tool = GetInfoFromIdentifier(kfinance_client=mock_client)
|
|
773
|
+
resp = tool.run_with_grounding(identifier="SPGI")
|
|
774
|
+
assert resp == expected_resp
|
|
775
|
+
|
|
776
|
+
|
|
725
777
|
class TestValidQuarter:
|
|
726
778
|
class QuarterModel(BaseModel):
|
|
727
779
|
quarter: ValidQuarter | None
|
|
@@ -2,8 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.constants import Permission
|
|
6
5
|
from kfinance.kfinance import AdvisedCompany
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
7
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
8
|
|
|
9
9
|
|
|
@@ -2,8 +2,9 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
-
from kfinance.constants import BusinessRelationshipType, Permission
|
|
6
5
|
from kfinance.kfinance import BusinessRelationships
|
|
6
|
+
from kfinance.models.business_relationship_models import BusinessRelationshipType
|
|
7
|
+
from kfinance.models.permission_models import Permission
|
|
7
8
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
9
|
|
|
9
10
|
|
|
@@ -2,7 +2,8 @@ from datetime import date
|
|
|
2
2
|
|
|
3
3
|
from pydantic import Field
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.capitalization_models import Capitalization
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
6
7
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
7
8
|
|
|
8
9
|
|
|
@@ -29,8 +30,6 @@ class GetCapitalizationFromIdentifier(KfinanceTool):
|
|
|
29
30
|
capitalization: Capitalization,
|
|
30
31
|
start_date: str | None = None,
|
|
31
32
|
end_date: str | None = None,
|
|
32
|
-
) ->
|
|
33
|
+
) -> dict:
|
|
33
34
|
ticker = self.kfinance_client.ticker(identifier)
|
|
34
|
-
return getattr(ticker, capitalization.value)(
|
|
35
|
-
start_date=start_date, end_date=end_date
|
|
36
|
-
).to_markdown()
|
|
35
|
+
return getattr(ticker, capitalization.value)(start_date=start_date, end_date=end_date)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from kfinance.
|
|
1
|
+
from kfinance.models.competitor_models import CompetitorSource
|
|
2
|
+
from kfinance.models.permission_models import Permission
|
|
2
3
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
3
4
|
|
|
4
5
|
|
|
@@ -2,8 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
-
from kfinance.constants import Permission
|
|
6
5
|
from kfinance.kfinance import NoEarningsDataError
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
7
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
8
|
|
|
9
9
|
|
|
@@ -2,7 +2,9 @@ from typing import Literal, Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.date_and_period_models import PeriodType
|
|
6
|
+
from kfinance.models.line_item_models import LINE_ITEM_NAMES_AND_ALIASES
|
|
7
|
+
from kfinance.models.permission_models import Permission
|
|
6
8
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
|
|
7
9
|
|
|
8
10
|
|
|
@@ -2,7 +2,9 @@ from typing import Literal, Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.date_and_period_models import PeriodType
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
|
+
from kfinance.models.statement_models import StatementType
|
|
6
8
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
|
|
7
9
|
|
|
8
10
|
|
|
@@ -2,7 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.permission_models import Permission
|
|
6
|
+
from kfinance.models.price_models import HistoryMetadata
|
|
6
7
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
7
8
|
|
|
8
9
|
|
|
@@ -2,7 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.date_and_period_models import LatestPeriods
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
6
7
|
from kfinance.tool_calling.shared_models import KfinanceTool
|
|
7
8
|
|
|
8
9
|
|
|
@@ -2,8 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
-
from kfinance.constants import Permission
|
|
6
5
|
from kfinance.kfinance import NoEarningsDataError
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
7
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
8
|
|
|
9
9
|
|
|
@@ -2,8 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.constants import Permission
|
|
6
5
|
from kfinance.kfinance import MergerOrAcquisition
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
7
|
from kfinance.tool_calling.shared_models import KfinanceTool
|
|
8
8
|
|
|
9
9
|
|
|
@@ -2,7 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.date_and_period_models import YearAndQuarter
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
6
7
|
from kfinance.tool_calling.shared_models import KfinanceTool
|
|
7
8
|
|
|
8
9
|
|
|
@@ -2,8 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
-
from kfinance.constants import Permission
|
|
6
5
|
from kfinance.kfinance import NoEarningsDataError
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
7
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
8
|
|
|
9
9
|
|
|
@@ -3,7 +3,8 @@ from typing import Type
|
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel, Field
|
|
5
5
|
|
|
6
|
-
from kfinance.
|
|
6
|
+
from kfinance.models.date_and_period_models import Periodicity
|
|
7
|
+
from kfinance.models.permission_models import Permission
|
|
7
8
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
9
|
|
|
9
10
|
|
|
@@ -35,11 +36,11 @@ class GetPricesFromIdentifier(KfinanceTool):
|
|
|
35
36
|
end_date: date | None = None,
|
|
36
37
|
periodicity: Periodicity = Periodicity.day,
|
|
37
38
|
adjusted: bool = True,
|
|
38
|
-
) ->
|
|
39
|
+
) -> dict:
|
|
39
40
|
ticker = self.kfinance_client.ticker(identifier)
|
|
40
41
|
return ticker.history(
|
|
41
42
|
start_date=start_date.isoformat() if start_date else None,
|
|
42
43
|
end_date=end_date.isoformat() if end_date else None,
|
|
43
44
|
periodicity=periodicity,
|
|
44
45
|
adjusted=adjusted,
|
|
45
|
-
).
|
|
46
|
+
).model_dump(mode="json")
|
|
@@ -2,7 +2,9 @@ from typing import Literal, Type
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from kfinance.
|
|
5
|
+
from kfinance.models.date_and_period_models import PeriodType
|
|
6
|
+
from kfinance.models.permission_models import Permission
|
|
7
|
+
from kfinance.models.segment_models import SegmentType
|
|
6
8
|
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
|
|
7
9
|
|
|
8
10
|
|
|
@@ -3,8 +3,8 @@ from typing import Annotated, Any, Literal, Type
|
|
|
3
3
|
from langchain_core.tools import BaseTool
|
|
4
4
|
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
|
|
5
5
|
|
|
6
|
-
from kfinance.constants import Permission
|
|
7
6
|
from kfinance.kfinance import Client
|
|
7
|
+
from kfinance.models.permission_models import Permission
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class KfinanceTool(BaseTool):
|
|
@@ -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
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
kensho_kfinance-2.6.5.dist-info/licenses/AUTHORS.md,sha256=0h9ClbI0pu1oKj1M28ROUsaxrbZg-6ukQGl6X4y9noI,68
|
|
2
|
-
kensho_kfinance-2.6.5.dist-info/licenses/LICENSE,sha256=bsY4blvSgq6o0FMQ3RXa2NCgco--nHCCchLXzxr6kms,83
|
|
3
|
-
kfinance/CHANGELOG.md,sha256=YiHif7EkkMz4H_xOuDpLlFZ1-8nJE3LOR6yHs1mO_6w,2065
|
|
4
|
-
kfinance/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
kfinance/batch_request_handling.py,sha256=G9rhpgQaCdb5C1dsfuJip8383iszibcOJ5k8gxld-tQ,5001
|
|
6
|
-
kfinance/constants.py,sha256=Zh7ruf-gFR6twCy5CUjOCgT_cGX-rgFdmR84AkcztYw,49453
|
|
7
|
-
kfinance/fetch.py,sha256=QyQjL2t9Z_tT1DD_Xzal59URH7QtnrpLQywcHSFtoWA,26691
|
|
8
|
-
kfinance/kfinance.py,sha256=-KilPs5VK5DDddfcFtt5NB_S8ITPfixlRUyovgE3LZA,72931
|
|
9
|
-
kfinance/mcp.py,sha256=MbktclVfBOEwfe-eR7kPaTXopMJmn_8RMlf4Jx5CXKU,3689
|
|
10
|
-
kfinance/meta_classes.py,sha256=ulRNnWZ4P0HURs8XPzCTsJ3SYbvnT4SXyG4dIuITxAo,21766
|
|
11
|
-
kfinance/prompt.py,sha256=PtVB8c_FcSlVdyGgByAnIFGzuUuBaEjciCqnBJl1hSQ,25133
|
|
12
|
-
kfinance/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
kfinance/pydantic_models.py,sha256=avpbPqwrAyLqsCbrmFpK_B8_fj1nPlBHrnPxRcBaSkE,774
|
|
14
|
-
kfinance/server_thread.py,sha256=jUnt1YGoYDkqqz1MbCwd44zJs1T_Z2BCgvj75bdtLgA,2574
|
|
15
|
-
kfinance/version.py,sha256=-IQDAMhAOM7pwUeC1G5pNoAyrR4v-SlcNn3yoDx_kZw,511
|
|
16
|
-
kfinance/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
kfinance/tests/conftest.py,sha256=dhL_RSc-af3j-2_UrAGRE9mxgcbjuIRtj08DTx79pQc,1123
|
|
18
|
-
kfinance/tests/scratch.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
-
kfinance/tests/test_batch_requests.py,sha256=2A0XnDDDSPkq0-BuiRryZx8b9_jBDtjYd2kWxFVyRew,10140
|
|
20
|
-
kfinance/tests/test_client.py,sha256=_OJ8fZ14aa7Oj2znheuRIRKz7FyQLqwkhWexEZetxmg,3855
|
|
21
|
-
kfinance/tests/test_example_notebook.py,sha256=XHwDKw2avyMonTmi3snCcFWNfZhEJOkpBGOZNrMLrhk,6470
|
|
22
|
-
kfinance/tests/test_fetch.py,sha256=mIj61dd843p3D1qtTAO60rZi6Rax0NgefOTTiBFrQcQ,17887
|
|
23
|
-
kfinance/tests/test_group_objects.py,sha256=SoMEZmkG4RYdgWOAwxLHHtzIQho92KM01YbQXPUg578,1689
|
|
24
|
-
kfinance/tests/test_objects.py,sha256=YlpxjlT1kJsDf4SgTZkhhthODwCnwNukJF_wvi11p3A,40805
|
|
25
|
-
kfinance/tests/test_tools.py,sha256=OfyoS4LInkh8c6hlGj-qtTwaL0WqV-8H7od3uNYXnec,29086
|
|
26
|
-
kfinance/tool_calling/README.md,sha256=omJq7Us6r4U45QB7hRpLjRJ5BMalCkZkh4uXBjTbJXc,2022
|
|
27
|
-
kfinance/tool_calling/__init__.py,sha256=UmtbtG6PvQHB1fInEL-K5q0kPHL__zTY9wzaPRSp1wg,2174
|
|
28
|
-
kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py,sha256=rrUVesFG3EpdVnvML42o6apJyBfWOBk0iYydJgIZaig,1615
|
|
29
|
-
kfinance/tool_calling/get_business_relationship_from_identifier.py,sha256=vILN4k2NGCIrpgWiT_p7CLwDv_uQf9qXwojmQwDRsJo,1480
|
|
30
|
-
kfinance/tool_calling/get_capitalization_from_identifier.py,sha256=7n52UH0oug6KspPxCQsRinb6WPC4M5UNK1CFhQxKAaE,1529
|
|
31
|
-
kfinance/tool_calling/get_competitors_from_identifier.py,sha256=RZ1ngeeZee12GOKUvw1rpzij9A55Zfs3MTt6O-DC98M,1096
|
|
32
|
-
kfinance/tool_calling/get_cusip_from_ticker.py,sha256=P4J2JS0_jwmfBWD9k-URlJ0gPFsgTkglivN-d3fA9Ek,652
|
|
33
|
-
kfinance/tool_calling/get_earnings.py,sha256=53mpdno7uaVMQVQXC_IXYEGvBh2kM7e41SFxI9LG--A,1230
|
|
34
|
-
kfinance/tool_calling/get_financial_line_item_from_identifier.py,sha256=iQywFZzXQdvL3oSWPHZJ6v1kifR27tsHLcXa6089Wls,2161
|
|
35
|
-
kfinance/tool_calling/get_financial_statement_from_identifier.py,sha256=4nJvQBaZZpD9-cKBONEimicUsQxIftFfdVj7rRqdUck,1914
|
|
36
|
-
kfinance/tool_calling/get_history_metadata_from_identifier.py,sha256=N-ZXYMT0YGIcTmCEAKgs5IK134WKFeuVzrGyPYIliXM,734
|
|
37
|
-
kfinance/tool_calling/get_info_from_identifier.py,sha256=XRan7nKa0FQuBF0i8UmoN2E0FOMEx34N8H-El4J51E0,772
|
|
38
|
-
kfinance/tool_calling/get_isin_from_ticker.py,sha256=iy4p8dhOpkooPZP8BPQRijsZbDbuAf9WyV5t8zBGMi8,646
|
|
39
|
-
kfinance/tool_calling/get_latest.py,sha256=CHtR8MvUdOxI63kWVWFONUaqlHPhSrE9qv96RRCJsiw,792
|
|
40
|
-
kfinance/tool_calling/get_latest_earnings.py,sha256=lUahH0G-QbxxeN4ClF-ETrMACFesw5UXOl9pnssDgzM,1182
|
|
41
|
-
kfinance/tool_calling/get_merger_info_from_transaction_id.py,sha256=uTtUFMtKrN53BxZ53s_HlTyyc4ToO1qIPFUts6IQFu8,3150
|
|
42
|
-
kfinance/tool_calling/get_mergers_from_identifier.py,sha256=Av86oG4Rf4eUYG3aHIzIMwJEkrxKR1CqRYLPnCQN5po,1710
|
|
43
|
-
kfinance/tool_calling/get_n_quarters_ago.py,sha256=R-_Wn-VUYABb7CPD2OQ_xauMAOZoYXW0FPw6ccvw6Ho,719
|
|
44
|
-
kfinance/tool_calling/get_next_earnings.py,sha256=O7bIXqJmvxgBZZ9jjcvN2WGy2KIsBe6YegnymiYJy-E,1162
|
|
45
|
-
kfinance/tool_calling/get_prices_from_identifier.py,sha256=4yTEPWTMqfUfU6JdsD_TQJLEFTNji0wic-8oXtdSqVY,1890
|
|
46
|
-
kfinance/tool_calling/get_segments_from_identifier.py,sha256=-6I5pK_VSNxszUuQX6ne9zr7HFwaeWCFMddmJ3PYA_g,1873
|
|
47
|
-
kfinance/tool_calling/get_transcript.py,sha256=2Vzab47kMw1288AubFXwhNGHtodmy_n2itITgk5szOg,767
|
|
48
|
-
kfinance/tool_calling/prompts.py,sha256=Yw1DJIMh90cjL-8q6_RMRiSjCtFDXvJAy7QiV5_uAU8,911
|
|
49
|
-
kfinance/tool_calling/resolve_identifier.py,sha256=_XEfGtDEB5tnAnseyQaugn4AuNsy6wZe5f-QOh8myko,632
|
|
50
|
-
kfinance/tool_calling/shared_models.py,sha256=COwOWhzgBMJMv1uXEhlsZJ0iwgA6yX2knFG8t9wY0uU,2819
|
|
51
|
-
kensho_kfinance-2.6.5.dist-info/METADATA,sha256=Ajs4li5Ux4TEl-zmEd2QoQB-W07xiCTgdsghc6mHORQ,6197
|
|
52
|
-
kensho_kfinance-2.6.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
53
|
-
kensho_kfinance-2.6.5.dist-info/top_level.txt,sha256=kT_kNwVhfQoOAecY8W7uYah5xaHMoHoAdBIvXh6DaKM,9
|
|
54
|
-
kensho_kfinance-2.6.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|