kensho-kfinance 2.4.2__tar.gz → 2.4.3__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.
- {kensho_kfinance-2.4.2/kensho_kfinance.egg-info → kensho_kfinance-2.4.3}/PKG-INFO +1 -1
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3/kensho_kfinance.egg-info}/PKG-INFO +1 -1
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kensho_kfinance.egg-info/SOURCES.txt +1 -1
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/CHANGELOG.md +3 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/constants.py +0 -2
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/mcp.py +23 -35
- kensho_kfinance-2.4.3/kfinance/tests/scratch.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_tools.py +35 -1
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_financial_line_item_from_identifier.py +3 -3
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_financial_statement_from_identifier.py +3 -3
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_segments_from_identifier.py +3 -3
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/shared_models.py +17 -2
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/version.py +2 -2
- kensho_kfinance-2.4.2/kfinance/tests/test_mcp.py +0 -16
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/.coveragerc +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/.github/workflows/ci-lint.yml +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/.github/workflows/ci-test.yml +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/.github/workflows/python-publish.yml +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/.gitignore +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/.readthedocs.yaml +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/AUTHORS.md +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/CODE_OF_CONDUCT.md +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/CONTRIBUTING.md +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/LICENSE +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/README.md +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/build_tool_calling_documentation.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/conf.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/index.rst +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/kfinance.rst +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/requirements.txt +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/templates/apidoc/package.rst_t +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/templates/apidoc/toc.rst_t +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/docs/tool_calling.rst +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/basic_usage.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/tool_calling/langchain/anthropic_langchain_tool_calling.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/tool_calling/langchain/google_gemini_langchain_tool_calling.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/tool_calling/langchain/openai_langchain_tool_calling.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/tool_calling/non-langchain/anthropic_tool_calling.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/tool_calling/non-langchain/google_gemini_tool_calling.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/example_notebooks/tool_calling/non-langchain/openai_langchain_tool_calling.ipynb +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/images/colab_logo_32px.png +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/justfile +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kensho_kfinance.egg-info/requires.txt +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kensho_kfinance.egg-info/top_level.txt +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/__init__.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/batch_request_handling.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/fetch.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/kfinance.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/meta_classes.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/prompt.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/py.typed +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/pydantic_models.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/server_thread.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/__init__.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/conftest.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_batch_requests.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_client.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_example_notebook.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_fetch.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_group_objects.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tests/test_objects.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/README.md +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/__init__.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_business_relationship_from_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_capitalization_from_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_cusip_from_ticker.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_earnings.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_earnings_call_datetimes_from_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_history_metadata_from_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_info_from_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_isin_from_ticker.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_latest.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_latest_earnings.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_n_quarters_ago.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_next_earnings.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_prices_from_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_transcript.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/prompts.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/resolve_identifier.py +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/pyproject.toml +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/scripts/copyright_line_check.sh +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/scripts/lint.sh +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/scripts/test.sh +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/setup.cfg +0 -0
- {kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kensho-kfinance
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.3
|
|
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.4.
|
|
3
|
+
Version: 2.4.3
|
|
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
|
|
@@ -48,12 +48,12 @@ kfinance/server_thread.py
|
|
|
48
48
|
kfinance/version.py
|
|
49
49
|
kfinance/tests/__init__.py
|
|
50
50
|
kfinance/tests/conftest.py
|
|
51
|
+
kfinance/tests/scratch.py
|
|
51
52
|
kfinance/tests/test_batch_requests.py
|
|
52
53
|
kfinance/tests/test_client.py
|
|
53
54
|
kfinance/tests/test_example_notebook.py
|
|
54
55
|
kfinance/tests/test_fetch.py
|
|
55
56
|
kfinance/tests/test_group_objects.py
|
|
56
|
-
kfinance/tests/test_mcp.py
|
|
57
57
|
kfinance/tests/test_objects.py
|
|
58
58
|
kfinance/tests/test_tools.py
|
|
59
59
|
kfinance/tool_calling/README.md
|
|
@@ -56,10 +56,8 @@ class StatementType(StrEnum):
|
|
|
56
56
|
"""The type of financial statement"""
|
|
57
57
|
|
|
58
58
|
balance_sheet = "balance_sheet"
|
|
59
|
-
bs = "balance_sheet"
|
|
60
59
|
income_statement = "income_statement"
|
|
61
60
|
cashflow = "cashflow"
|
|
62
|
-
cf = "cashflow"
|
|
63
61
|
|
|
64
62
|
|
|
65
63
|
class SegmentType(StrEnum):
|
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
from textwrap import dedent
|
|
2
1
|
from typing import Literal, Optional
|
|
3
2
|
|
|
4
3
|
import click
|
|
5
4
|
from fastmcp import FastMCP
|
|
5
|
+
from fastmcp.tools import FunctionTool
|
|
6
6
|
from fastmcp.utilities.logging import get_logger
|
|
7
|
+
from langchain_core.utils.function_calling import convert_to_openai_tool
|
|
7
8
|
|
|
8
9
|
from kfinance.kfinance import Client
|
|
9
|
-
from kfinance.tool_calling
|
|
10
|
+
from kfinance.tool_calling import KfinanceTool
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
logger = get_logger(__name__)
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
def
|
|
16
|
-
"""Build
|
|
16
|
+
def build_mcp_tool_from_kfinance_tool(kfinance_tool: KfinanceTool) -> FunctionTool:
|
|
17
|
+
"""Build an MCP FunctionTool from a langchain KfinanceTool."""
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for arg_name, arg_field in tool.args_schema.model_fields.items():
|
|
35
|
-
default_value_description = (
|
|
36
|
-
f"Default: {arg_field.default}. " if not arg_field.is_required() else ""
|
|
37
|
-
)
|
|
38
|
-
param_description = f"\n {arg_name}: {default_value_description}{arg_field.description}"
|
|
39
|
-
description += param_description
|
|
40
|
-
|
|
41
|
-
return description
|
|
19
|
+
return FunctionTool(
|
|
20
|
+
name=kfinance_tool.name,
|
|
21
|
+
description=kfinance_tool.description,
|
|
22
|
+
# MCP expects a JSON schema for tool params, which we
|
|
23
|
+
# can generate similar to how langchain generates openai json schemas.
|
|
24
|
+
parameters=convert_to_openai_tool(kfinance_tool)["function"]["parameters"],
|
|
25
|
+
# The langchain runner internally validates input arguments via the args_schema.
|
|
26
|
+
# When running with mcp, we need to reproduce that validation ourselves in
|
|
27
|
+
# run_without_langchain (which then calls _run).
|
|
28
|
+
# If we pass in the underlying _run method directly, mcp generates a schema from
|
|
29
|
+
# the _run type hints but bypasses our internal validation. This causes errors,
|
|
30
|
+
# for example with integer literals, which our args models allow but the
|
|
31
|
+
# mcp-internal validation disallows.
|
|
32
|
+
fn=kfinance_tool.run_without_langchain,
|
|
33
|
+
)
|
|
42
34
|
|
|
43
35
|
|
|
44
36
|
@click.command()
|
|
@@ -85,13 +77,9 @@ def run_mcp(
|
|
|
85
77
|
kfinance_client = Client()
|
|
86
78
|
|
|
87
79
|
kfinance_mcp: FastMCP = FastMCP("Kfinance")
|
|
88
|
-
for
|
|
89
|
-
logger.info("Adding %s to server",
|
|
90
|
-
kfinance_mcp.
|
|
91
|
-
name_or_fn=getattr(tool, "_run"),
|
|
92
|
-
name=tool.name,
|
|
93
|
-
description=build_doc_string(tool),
|
|
94
|
-
)
|
|
80
|
+
for langchain_tool in kfinance_client.langchain_tools:
|
|
81
|
+
logger.info("Adding %s to server", langchain_tool.name)
|
|
82
|
+
kfinance_mcp.add_tool(build_mcp_tool_from_kfinance_tool(langchain_tool))
|
|
95
83
|
|
|
96
84
|
logger.info("Server starting")
|
|
97
85
|
kfinance_mcp.run(transport=transport)
|
|
File without changes
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
from contextlib import nullcontext as does_not_raise
|
|
1
3
|
from datetime import date, datetime
|
|
2
4
|
|
|
3
5
|
from langchain_core.utils.function_calling import convert_to_openai_tool
|
|
6
|
+
from pydantic import BaseModel, ValidationError
|
|
7
|
+
import pytest
|
|
4
8
|
from pytest import raises
|
|
5
9
|
from requests_mock import Mocker
|
|
6
10
|
import time_machine
|
|
@@ -48,7 +52,7 @@ from kfinance.tool_calling.get_segments_from_identifier import (
|
|
|
48
52
|
GetSegmentsFromIdentifierArgs,
|
|
49
53
|
)
|
|
50
54
|
from kfinance.tool_calling.get_transcript import GetTranscriptArgs
|
|
51
|
-
from kfinance.tool_calling.shared_models import ToolArgsWithIdentifier
|
|
55
|
+
from kfinance.tool_calling.shared_models import ToolArgsWithIdentifier, ValidQuarter
|
|
52
56
|
|
|
53
57
|
|
|
54
58
|
class TestGetBusinessRelationshipFromIdentifier:
|
|
@@ -638,3 +642,33 @@ class TestGetTranscript:
|
|
|
638
642
|
tool = GetTranscript(kfinance_client=mock_client)
|
|
639
643
|
response = tool.run(GetTranscriptArgs(key_dev_id=12345).model_dump(mode="json"))
|
|
640
644
|
assert response == expected_response
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
class TestValidQuarter:
|
|
648
|
+
class QuarterModel(BaseModel):
|
|
649
|
+
quarter: ValidQuarter | None
|
|
650
|
+
|
|
651
|
+
@pytest.mark.parametrize(
|
|
652
|
+
"input_quarter, expectation, expected_quarter",
|
|
653
|
+
[
|
|
654
|
+
pytest.param(1, does_not_raise(), 1, id="int input works"),
|
|
655
|
+
pytest.param("1", does_not_raise(), 1, id="str input works"),
|
|
656
|
+
pytest.param(None, does_not_raise(), None, id="None input works"),
|
|
657
|
+
pytest.param(5, pytest.raises(ValidationError), None, id="invalid int raises"),
|
|
658
|
+
pytest.param("5", pytest.raises(ValidationError), None, id="invalid str raises"),
|
|
659
|
+
],
|
|
660
|
+
)
|
|
661
|
+
def test_valid_quarter(
|
|
662
|
+
self,
|
|
663
|
+
input_quarter: int | str | None,
|
|
664
|
+
expectation: contextlib.AbstractContextManager,
|
|
665
|
+
expected_quarter: int | None,
|
|
666
|
+
) -> None:
|
|
667
|
+
"""
|
|
668
|
+
GIVEN a model that uses `ValidQuarter`
|
|
669
|
+
WHEN we deserialize with int, str, or None
|
|
670
|
+
THEN valid str get coerced to int. Invalid values raise.
|
|
671
|
+
"""
|
|
672
|
+
with expectation:
|
|
673
|
+
res = self.QuarterModel.model_validate(dict(quarter=input_quarter))
|
|
674
|
+
assert res.quarter == expected_quarter
|
|
@@ -3,7 +3,7 @@ from typing import Literal, Type
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
5
|
from kfinance.constants import LINE_ITEM_NAMES_AND_ALIASES, PeriodType, Permission
|
|
6
|
-
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
6
|
+
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class GetFinancialLineItemFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
@@ -16,8 +16,8 @@ class GetFinancialLineItemFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
|
16
16
|
period_type: PeriodType | None = Field(default=None, description="The period type")
|
|
17
17
|
start_year: int | None = Field(default=None, description="The starting year for the data range")
|
|
18
18
|
end_year: int | None = Field(default=None, description="The ending year for the data range")
|
|
19
|
-
start_quarter:
|
|
20
|
-
end_quarter:
|
|
19
|
+
start_quarter: ValidQuarter | None = Field(default=None, description="Starting quarter")
|
|
20
|
+
end_quarter: ValidQuarter | None = Field(default=None, description="Ending quarter")
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class GetFinancialLineItemFromIdentifier(KfinanceTool):
|
|
@@ -3,7 +3,7 @@ from typing import Literal, Type
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
5
|
from kfinance.constants import PeriodType, Permission, StatementType
|
|
6
|
-
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
6
|
+
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class GetFinancialStatementFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
@@ -12,8 +12,8 @@ class GetFinancialStatementFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
|
12
12
|
period_type: PeriodType | None = Field(default=None, description="The period type")
|
|
13
13
|
start_year: int | None = Field(default=None, description="The starting year for the data range")
|
|
14
14
|
end_year: int | None = Field(default=None, description="The ending year for the data range")
|
|
15
|
-
start_quarter:
|
|
16
|
-
end_quarter:
|
|
15
|
+
start_quarter: ValidQuarter | None = Field(default=None, description="Starting quarter")
|
|
16
|
+
end_quarter: ValidQuarter | None = Field(default=None, description="Ending quarter")
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class GetFinancialStatementFromIdentifier(KfinanceTool):
|
|
@@ -3,7 +3,7 @@ from typing import Literal, Type
|
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
5
|
from kfinance.constants import PeriodType, Permission, SegmentType
|
|
6
|
-
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
6
|
+
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class GetSegmentsFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
@@ -12,8 +12,8 @@ class GetSegmentsFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
|
12
12
|
period_type: PeriodType | None = Field(default=None, description="The period type")
|
|
13
13
|
start_year: int | None = Field(default=None, description="The starting year for the data range")
|
|
14
14
|
end_year: int | None = Field(default=None, description="The ending year for the data range")
|
|
15
|
-
start_quarter:
|
|
16
|
-
end_quarter:
|
|
15
|
+
start_quarter: ValidQuarter | None = Field(default=None, description="Starting quarter")
|
|
16
|
+
end_quarter: ValidQuarter | None = Field(default=None, description="Ending quarter")
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class GetSegmentsFromIdentifier(KfinanceTool):
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
from typing import Any, Type
|
|
1
|
+
from typing import Annotated, Any, Literal, Type
|
|
2
2
|
|
|
3
3
|
from langchain_core.tools import BaseTool
|
|
4
|
-
from pydantic import BaseModel, ConfigDict, Field
|
|
4
|
+
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
|
|
5
5
|
|
|
6
6
|
from kfinance.constants import Permission
|
|
7
7
|
from kfinance.kfinance import Client
|
|
@@ -53,3 +53,18 @@ class ToolArgsWithIdentifier(BaseModel):
|
|
|
53
53
|
identifier: str = Field(
|
|
54
54
|
description="The identifier, which can be a ticker symbol, ISIN, or CUSIP"
|
|
55
55
|
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def convert_str_to_int(v: Any) -> Any:
|
|
59
|
+
"""Convert strings to integers if possible."""
|
|
60
|
+
if isinstance(v, str) and v.isdigit():
|
|
61
|
+
return int(v)
|
|
62
|
+
return v
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Valid Quarter is a literal type, which converts strings to int before
|
|
66
|
+
# validating them.
|
|
67
|
+
# Claude seems to often pass strings to int literals, which raise a
|
|
68
|
+
# ValidationError during deserialization unless they have been converted
|
|
69
|
+
# to int.
|
|
70
|
+
ValidQuarter = Annotated[Literal[1, 2, 3, 4], BeforeValidator(convert_str_to_int)]
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from typing import Type
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
from kfinance.kfinance import Client
|
|
6
|
-
from kfinance.mcp import build_doc_string
|
|
7
|
-
from kfinance.tool_calling import ALL_TOOLS
|
|
8
|
-
from kfinance.tool_calling.shared_models import KfinanceTool
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TestDocStringBuilding:
|
|
12
|
-
@pytest.mark.parametrize("tool_class", ALL_TOOLS)
|
|
13
|
-
def test_build_doc_string(self, mock_client: Client, tool_class: Type[KfinanceTool]):
|
|
14
|
-
"""This test build the docstring for each tool. A success is considered if no exception is raised"""
|
|
15
|
-
tool = tool_class(kfinance_client=mock_client)
|
|
16
|
-
build_doc_string(tool)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kensho_kfinance.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_cusip_from_ticker.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_info_from_identifier.py
RENAMED
|
File without changes
|
{kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_isin_from_ticker.py
RENAMED
|
File without changes
|
|
File without changes
|
{kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_latest_earnings.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kensho_kfinance-2.4.2 → kensho_kfinance-2.4.3}/kfinance/tool_calling/get_prices_from_identifier.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|