kensho-kfinance 2.2.4__tar.gz → 2.3.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 (83) hide show
  1. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/.gitignore +2 -1
  2. {kensho_kfinance-2.2.4/kensho_kfinance.egg-info → kensho_kfinance-2.3.0}/PKG-INFO +14 -4
  3. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/README.md +10 -1
  4. kensho_kfinance-2.2.4/usage_examples.ipynb → kensho_kfinance-2.3.0/example_notebooks/basic_usage.ipynb +1 -1
  5. kensho_kfinance-2.3.0/example_notebooks/tool_calling/langchain/anthropic_langchain_tool_calling.ipynb +200 -0
  6. kensho_kfinance-2.3.0/example_notebooks/tool_calling/langchain/google_gemini_langchain_tool_calling.ipynb +193 -0
  7. kensho_kfinance-2.3.0/example_notebooks/tool_calling/langchain/openai_langchain_tool_calling.ipynb +193 -0
  8. kensho_kfinance-2.3.0/example_notebooks/tool_calling/non-langchain/anthropic_tool_calling.ipynb +286 -0
  9. kensho_kfinance-2.3.0/example_notebooks/tool_calling/non-langchain/google_gemini_tool_calling.ipynb +228 -0
  10. kensho_kfinance-2.3.0/example_notebooks/tool_calling/non-langchain/openai_langchain_tool_calling.ipynb +278 -0
  11. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/justfile +5 -1
  12. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0/kensho_kfinance.egg-info}/PKG-INFO +14 -4
  13. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kensho_kfinance.egg-info/SOURCES.txt +13 -1
  14. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kensho_kfinance.egg-info/requires.txt +3 -2
  15. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/CHANGELOG.md +9 -0
  16. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/fetch.py +26 -10
  17. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/kfinance.py +227 -11
  18. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/meta_classes.py +26 -8
  19. kensho_kfinance-2.3.0/kfinance/pydantic_models.py +33 -0
  20. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_example_notebook.py +4 -2
  21. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_fetch.py +74 -1
  22. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_objects.py +165 -2
  23. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_tools.py +217 -1
  24. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/__init__.py +8 -0
  25. kensho_kfinance-2.3.0/kfinance/tool_calling/get_earnings.py +30 -0
  26. kensho_kfinance-2.3.0/kfinance/tool_calling/get_latest_earnings.py +27 -0
  27. kensho_kfinance-2.3.0/kfinance/tool_calling/get_next_earnings.py +27 -0
  28. kensho_kfinance-2.3.0/kfinance/tool_calling/get_transcript.py +23 -0
  29. kensho_kfinance-2.3.0/kfinance/tool_calling/prompts.py +16 -0
  30. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/version.py +2 -2
  31. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/pyproject.toml +3 -2
  32. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/scripts/lint.sh +1 -1
  33. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/.coveragerc +0 -0
  34. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/.github/workflows/ci-lint.yml +0 -0
  35. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/.github/workflows/ci-test.yml +0 -0
  36. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/.github/workflows/python-publish.yml +0 -0
  37. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/.readthedocs.yaml +0 -0
  38. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/AUTHORS.md +0 -0
  39. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/CODE_OF_CONDUCT.md +0 -0
  40. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/CONTRIBUTING.md +0 -0
  41. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/LICENSE +0 -0
  42. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/build_tool_calling_documentation.py +0 -0
  43. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/conf.py +0 -0
  44. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/index.rst +0 -0
  45. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/kfinance.rst +0 -0
  46. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/requirements.txt +0 -0
  47. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/templates/apidoc/package.rst_t +0 -0
  48. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/templates/apidoc/toc.rst_t +0 -0
  49. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/docs/tool_calling.rst +0 -0
  50. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/images/colab_logo_32px.png +0 -0
  51. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
  52. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kensho_kfinance.egg-info/top_level.txt +0 -0
  53. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/__init__.py +0 -0
  54. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/batch_request_handling.py +0 -0
  55. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/constants.py +0 -0
  56. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/prompt.py +0 -0
  57. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/py.typed +0 -0
  58. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/server_thread.py +0 -0
  59. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/__init__.py +0 -0
  60. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/conftest.py +0 -0
  61. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_batch_requests.py +0 -0
  62. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_client.py +0 -0
  63. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tests/test_group_objects.py +0 -0
  64. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/README.md +0 -0
  65. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_business_relationship_from_identifier.py +0 -0
  66. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_capitalization_from_identifier.py +0 -0
  67. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_cusip_from_ticker.py +0 -0
  68. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_earnings_call_datetimes_from_identifier.py +0 -0
  69. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_financial_line_item_from_identifier.py +0 -0
  70. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_financial_statement_from_identifier.py +0 -0
  71. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_history_metadata_from_identifier.py +0 -0
  72. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_info_from_identifier.py +0 -0
  73. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_isin_from_ticker.py +0 -0
  74. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_latest.py +0 -0
  75. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_n_quarters_ago.py +0 -0
  76. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_prices_from_identifier.py +0 -0
  77. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/get_segments_from_identifier.py +0 -0
  78. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/resolve_identifier.py +0 -0
  79. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/kfinance/tool_calling/shared_models.py +0 -0
  80. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/scripts/copyright_line_check.sh +0 -0
  81. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/scripts/test.sh +0 -0
  82. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/setup.cfg +0 -0
  83. {kensho_kfinance-2.2.4 → kensho_kfinance-2.3.0}/setup.py +0 -0
@@ -104,4 +104,5 @@ kfinance/version.py
104
104
  kfinance/wrappers/
105
105
 
106
106
  docs/output/
107
- docs/generated/
107
+ docs/generated/
108
+ wrappers/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 2.2.4
3
+ Version: 2.3.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
@@ -14,7 +14,7 @@ License-File: LICENSE
14
14
  License-File: AUTHORS.md
15
15
  Requires-Dist: cachetools<6,>=5.5
16
16
  Requires-Dist: langchain-core>=0.3.15
17
- Requires-Dist: langchain-google-genai<3,>=2.1.0
17
+ Requires-Dist: langchain-google-genai<3,>=2.1.5
18
18
  Requires-Dist: numpy>=1.22.4
19
19
  Requires-Dist: pandas>=2.0.0
20
20
  Requires-Dist: pillow>=10
@@ -29,7 +29,8 @@ Requires-Dist: urllib3>=1.21.1
29
29
  Provides-Extra: dev
30
30
  Requires-Dist: coverage<8,>=7.6.10; extra == "dev"
31
31
  Requires-Dist: ipykernel<7,>=6.29; extra == "dev"
32
- Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
32
+ Requires-Dist: langchain-anthropic<1,>=0.3.10; extra == "dev"
33
+ Requires-Dist: mypy<2,>=1.16.0; extra == "dev"
33
34
  Requires-Dist: nbconvert<8,>=7.16; extra == "dev"
34
35
  Requires-Dist: nbformat<6,>5.10; extra == "dev"
35
36
  Requires-Dist: nbqa<2,>1.9; extra == "dev"
@@ -61,7 +62,16 @@ To receive access, please email [S&P Global Market Intelligence](market.intellig
61
62
 
62
63
  Once access is obtained, get started using the [Authentication Guide](https://docs.kensho.com/llmreadyapi/kf-authentication) and [Usage Guide](https://docs.kensho.com/llmreadyapi/usage).
63
64
 
64
- We also provide an [interactive notebook](usage_examples.ipynb) that demonstrates some usage examples.
65
+ To get started, we provide some notebooks:
66
+
67
+ - The [LLM-ready API Basic Usage](example_notebooks%2Fbasic_usage.ipynb) notebook demonstrates how
68
+ fetch data with the kFinance client.
69
+ - The [tool_calling notebooks](example_notebooks%2Ftool_calling) show how the kFinance library can
70
+ be used for tool calling. We provide notebooks for OpenAI (GPT), Anthropic (Claude), and Google
71
+ (Gemini). Each of these integrations comes in a langchain version, which uses langchain as a
72
+ wrapper to simplify the integration, and as a lower level non-langchain version.
73
+
74
+ We also provide an [interactive notebook](example_notebooks/basic_usage.ipynb) that demonstrates some usage examples.
65
75
 
66
76
  # Versioning
67
77
  The kFinance uses semantic versioning (major, minor, patch).
@@ -18,7 +18,16 @@ To receive access, please email [S&P Global Market Intelligence](market.intellig
18
18
 
19
19
  Once access is obtained, get started using the [Authentication Guide](https://docs.kensho.com/llmreadyapi/kf-authentication) and [Usage Guide](https://docs.kensho.com/llmreadyapi/usage).
20
20
 
21
- We also provide an [interactive notebook](usage_examples.ipynb) that demonstrates some usage examples.
21
+ To get started, we provide some notebooks:
22
+
23
+ - The [LLM-ready API Basic Usage](example_notebooks%2Fbasic_usage.ipynb) notebook demonstrates how
24
+ fetch data with the kFinance client.
25
+ - The [tool_calling notebooks](example_notebooks%2Ftool_calling) show how the kFinance library can
26
+ be used for tool calling. We provide notebooks for OpenAI (GPT), Anthropic (Claude), and Google
27
+ (Gemini). Each of these integrations comes in a langchain version, which uses langchain as a
28
+ wrapper to simplify the integration, and as a lower level non-langchain version.
29
+
30
+ We also provide an [interactive notebook](example_notebooks/basic_usage.ipynb) that demonstrates some usage examples.
22
31
 
23
32
  # Versioning
24
33
  The kFinance uses semantic versioning (major, minor, patch).
@@ -20,7 +20,7 @@
20
20
  "\n",
21
21
  "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
22
22
  " <td>\n",
23
- " <a target=\"_blank\" href=\"https://colab.research.google.com/github/kensho-technologies/llm-ready-api-examples/blob/main/basic_usage.ipynb\"><img src=\"./images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
23
+ " <a target=\"_blank\" href=\"https://colab.research.google.com/github/kensho-technologies/kfinance/blob/main/example_notebooks/basic_usage.ipynb\"><img src=\"../images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
24
24
  " </td>\n",
25
25
  "</table>"
26
26
  ]
@@ -0,0 +1,200 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "##### Copyright 2025 Kensho Technologies, LLC"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "markdown",
13
+ "source": [
14
+ "# LangChain Tool Calling with Anthropic Claude\n",
15
+ "**_Claude to retrieve data from the LLM-ready API using the kFinance python library!_**\n",
16
+ "\n",
17
+ "What you'll need to run this notebook:\n",
18
+ "\n",
19
+ "1. kFinance credentials\n",
20
+ "2. An Anthropic API key\n",
21
+ "\n",
22
+ "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
23
+ " <td>\n",
24
+ " <a target=\"_blank\" href=\"https://colab.research.google.com/github/kensho-technologies/kfinance/blob/main/example_notebooks/tool_calling/langchain/anthropic_langchain_tool_calling.ipynb\"><img src=\"../../../images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
25
+ " </td>\n",
26
+ "</table>"
27
+ ],
28
+ "metadata": {
29
+ "collapsed": false
30
+ }
31
+ },
32
+ {
33
+ "attachments": {},
34
+ "cell_type": "markdown",
35
+ "metadata": {
36
+ "id": "ruP6MHfzR2Y4"
37
+ },
38
+ "source": [
39
+ "## Install dependencies"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": null,
45
+ "metadata": {
46
+ "colab": {
47
+ "base_uri": "https://localhost:8080/"
48
+ },
49
+ "collapsed": true,
50
+ "id": "YAwU0_7TRhV7",
51
+ "jupyter": {
52
+ "outputs_hidden": true
53
+ },
54
+ "outputId": "e6ebf89c-7680-4852-e52b-c99610107cdf"
55
+ },
56
+ "outputs": [],
57
+ "source": [
58
+ "# install the latest version of kFinance package\n",
59
+ "%pip install kensho-kfinance\n",
60
+ "# install langchain and anthropic\n",
61
+ "%pip install anthropic\n",
62
+ "%pip install langchain\n",
63
+ "%pip install langchain-anthropic"
64
+ ]
65
+ },
66
+ {
67
+ "attachments": {},
68
+ "cell_type": "markdown",
69
+ "metadata": {
70
+ "id": "e_G2p3tTSHeo"
71
+ },
72
+ "source": [
73
+ "# Instantiate kFinance Client"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": null,
79
+ "metadata": {
80
+ "id": "7QPnfPuX87rg"
81
+ },
82
+ "outputs": [],
83
+ "source": [
84
+ "# import the kfinance client\n",
85
+ "import sys\n",
86
+ "from kfinance.kfinance import Client\n",
87
+ "\n",
88
+ "# check if the current environment is a Google Colab\n",
89
+ "try:\n",
90
+ " import google.colab\n",
91
+ "\n",
92
+ " IN_GOOGLE_COLAB = True\n",
93
+ "except:\n",
94
+ " IN_GOOGLE_COLAB = False\n",
95
+ "\n",
96
+ "# initialize the kfinance client with one of the following:\n",
97
+ "# 1. your kensho refresh token\n",
98
+ "# 2. your kensho client id and kensho private key\n",
99
+ "# 3. automated login (not accessible on Google Collab)\n",
100
+ "if IN_GOOGLE_COLAB:\n",
101
+ " kensho_refresh_token = \"\"\n",
102
+ " assert kensho_refresh_token != \"\", \"kensho refresh token is empty! Make sure to enter your kensho refresh token above\"\n",
103
+ " kfinance_client = Client(refresh_token=kensho_refresh_token)\n",
104
+ "\n",
105
+ " # kensho_client_id = \"\"\n",
106
+ " # kensho_private_key = \"\"\n",
107
+ " # assert kensho_client_id != \"\", \"kensho client id is empty! Make sure to enter your kensho client id above\"\n",
108
+ " # assert kensho_private_key != \"\", \"kensho private key is empty! Make sure to enter your kensho private key above\"\n",
109
+ " # kfinance_client = Client(client_id=kensho_client_id, private_key=kensho_private_key)\n",
110
+ "else:\n",
111
+ " kfinance_client = Client()"
112
+ ]
113
+ },
114
+ {
115
+ "attachments": {},
116
+ "cell_type": "markdown",
117
+ "metadata": {
118
+ "id": "LvQy_66Jioys"
119
+ },
120
+ "source": [
121
+ "# LangChain Tool Calling with Anthropic"
122
+ ]
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "execution_count": null,
127
+ "metadata": {
128
+ "id": "WkoRuipOEQz6"
129
+ },
130
+ "outputs": [],
131
+ "source": [
132
+ "from pydantic import SecretStr\n",
133
+ "from kfinance.tool_calling.prompts import BASE_PROMPT\n",
134
+ "from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
135
+ "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
136
+ "from langchain_anthropic import ChatAnthropic\n",
137
+ "\n",
138
+ "\n",
139
+ "class LangChainAnthropicChat:\n",
140
+ " def __init__(self, kfinance_client: Client) -> None:\n",
141
+ " \"\"\"Initialize a LangChainAnthropicChat\"\"\"\n",
142
+ "\n",
143
+ " # Initialize Anthropic with your Anthropic key\n",
144
+ " anthropic_api_key = SecretStr(\"\") # replace with your own key\n",
145
+ " assert anthropic_api_key, \"Anthropic API key is empty! Make sure to enter your Anthropic API key above\"\n",
146
+ " llm = ChatAnthropic(model=\"claude-3-7-sonnet-20250219\",\n",
147
+ " api_key=anthropic_api_key) # type: ignore[call-arg]\n",
148
+ "\n",
149
+ " # Get the prompt to use - can be replaced with any prompt that includes variables \"agent_scratchpad\" and \"input\"!\n",
150
+ " # Prompt\n",
151
+ " prompt = ChatPromptTemplate.from_messages(\n",
152
+ " [\n",
153
+ " (\"system\", BASE_PROMPT),\n",
154
+ " MessagesPlaceholder(\"chat_history\", optional=True),\n",
155
+ " (\"human\", \"{input}\"),\n",
156
+ " MessagesPlaceholder(\"agent_scratchpad\"),\n",
157
+ " ]\n",
158
+ " )\n",
159
+ " # Construct the tool calling agent\n",
160
+ " agent = create_tool_calling_agent(llm=llm, tools=kfinance_client.langchain_tools,\n",
161
+ " prompt=prompt)\n",
162
+ " # Create an agent executor by passing in the agent and tools\n",
163
+ " self.agent_executor = AgentExecutor(agent=agent, tools=kfinance_client.langchain_tools,\n",
164
+ " verbose=True)\n",
165
+ "\n",
166
+ " def start_chatting(self) -> None:\n",
167
+ " \"\"\"Open chat shell\"\"\"\n",
168
+ " while True:\n",
169
+ " user_input = input(\"Enter your message and press the [return] key\\n\")\n",
170
+ " self.agent_executor.invoke({\"input\": user_input})\n",
171
+ " sys.stdout.write(\"\\n\")"
172
+ ]
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "execution_count": null,
177
+ "metadata": {},
178
+ "outputs": [],
179
+ "source": [
180
+ "# instantiate LangChainAnthropicChat with the kfinance client\n",
181
+ "anthropic_chat = LangChainAnthropicChat(kfinance_client)\n",
182
+ "# start chatting with LangChainAnthropicChat\n",
183
+ "anthropic_chat.start_chatting()"
184
+ ]
185
+ }
186
+ ],
187
+ "metadata": {
188
+ "language_info": {
189
+ "name": "python"
190
+ },
191
+ "orig_nbformat": 4,
192
+ "kernelspec": {
193
+ "name": "python3",
194
+ "language": "python",
195
+ "display_name": "Python 3 (ipykernel)"
196
+ }
197
+ },
198
+ "nbformat": 4,
199
+ "nbformat_minor": 2
200
+ }
@@ -0,0 +1,193 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "##### Copyright 2025 Kensho Technologies, LLC"
9
+ ]
10
+ },
11
+ {
12
+ "attachments": {},
13
+ "cell_type": "markdown",
14
+ "metadata": {
15
+ "id": "-zOQ3ZfKSrT2"
16
+ },
17
+ "source": [
18
+ "# LangChain Tool Calling with Google Gemini\n",
19
+ "**_Gemini to retrieve data from the LLM-ready API using the kFinance python library!_**\n",
20
+ "\n",
21
+ "What you'll need to run this notebook:\n",
22
+ "\n",
23
+ "1. kFinance credentials\n",
24
+ "2. An Gemini API key\n",
25
+ "\n",
26
+ "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
27
+ " <td>\n",
28
+ " <a target=\"_blank\" href=\"https://colab.research.google.com/github/kensho-technologies/kfinance/blob/main/example_notebooks/tool_calling/langchain/google_gemini_langchain_tool_calling.ipynb\"><img src=\"../../../images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
29
+ " </td>\n",
30
+ "</table>"
31
+ ]
32
+ },
33
+ {
34
+ "attachments": {},
35
+ "cell_type": "markdown",
36
+ "metadata": {
37
+ "id": "ruP6MHfzR2Y4"
38
+ },
39
+ "source": [
40
+ "## Install dependencies"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": null,
46
+ "metadata": {
47
+ "colab": {
48
+ "base_uri": "https://localhost:8080/"
49
+ },
50
+ "collapsed": true,
51
+ "id": "YAwU0_7TRhV7",
52
+ "jupyter": {
53
+ "outputs_hidden": true
54
+ },
55
+ "outputId": "e6ebf89c-7680-4852-e52b-c99610107cdf"
56
+ },
57
+ "outputs": [],
58
+ "source": [
59
+ "# install the latest version of kFinance package\n",
60
+ "%pip install kensho-kfinance\n",
61
+ "# install langchain and gemini\n",
62
+ "%pip install langchain\n",
63
+ "%pip install google-generativeai\n",
64
+ "%pip install langchain-google-genai"
65
+ ]
66
+ },
67
+ {
68
+ "attachments": {},
69
+ "cell_type": "markdown",
70
+ "metadata": {
71
+ "id": "e_G2p3tTSHeo"
72
+ },
73
+ "source": [
74
+ "# Instantiate kFinance Client"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": null,
80
+ "metadata": {
81
+ "id": "7QPnfPuX87rg"
82
+ },
83
+ "outputs": [],
84
+ "source": [
85
+ "# import the kfinance client\n",
86
+ "import sys\n",
87
+ "from kfinance.kfinance import Client\n",
88
+ "# check if the current environment is a Google Colab\n",
89
+ "try:\n",
90
+ " import google.colab\n",
91
+ " IN_GOOGLE_COLAB = True\n",
92
+ "except:\n",
93
+ " IN_GOOGLE_COLAB = False\n",
94
+ "\n",
95
+ "# initialize the kfinance client with one of the following:\n",
96
+ "# 1. your kensho refresh token\n",
97
+ "# 2. your kensho client id and kensho private key\n",
98
+ "# 3. automated login (not accessible on Google Collab)\n",
99
+ "if IN_GOOGLE_COLAB:\n",
100
+ " kensho_refresh_token = \"\"\n",
101
+ " assert kensho_refresh_token != \"\", \"kensho refresh token is empty! Make sure to enter your kensho refresh token above\"\n",
102
+ " kfinance_client = Client(refresh_token=kensho_refresh_token)\n",
103
+ "\n",
104
+ " # kensho_client_id = \"\"\n",
105
+ " # kensho_private_key = \"\"\n",
106
+ " # assert kensho_client_id != \"\", \"kensho client id is empty! Make sure to enter your kensho client id above\"\n",
107
+ " # assert kensho_private_key != \"\", \"kensho private key is empty! Make sure to enter your kensho private key above\"\n",
108
+ " # kfinance_client = Client(client_id=kensho_client_id, private_key=kensho_private_key)\n",
109
+ "else:\n",
110
+ " kfinance_client = Client()\n"
111
+ ]
112
+ },
113
+ {
114
+ "attachments": {},
115
+ "cell_type": "markdown",
116
+ "metadata": {
117
+ "id": "LvQy_66Jioys"
118
+ },
119
+ "source": [
120
+ "# LangChain Function Calling with Gemini"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": null,
126
+ "metadata": {
127
+ "id": "WkoRuipOEQz6"
128
+ },
129
+ "outputs": [],
130
+ "source": [
131
+ "from kfinance.tool_calling.prompts import BASE_PROMPT\n",
132
+ "# import langchain\n",
133
+ "from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
134
+ "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
135
+ "from langchain_google_genai import ChatGoogleGenerativeAI\n",
136
+ "\n",
137
+ "class LangChainGeminiChat:\n",
138
+ " def __init__(self, kfinance_client: Client) -> None:\n",
139
+ " # Initialize Gemini with your Gemini API key\n",
140
+ " gemini_api_key = \"\" # replace with your own key\n",
141
+ " assert gemini_api_key != \"\", \"Gemini API key is empty! Make sure to enter your Gemini API key above\"\n",
142
+ " llm = ChatGoogleGenerativeAI(model=\"gemini-2.0-flash\", google_api_key=gemini_api_key)\n",
143
+ " \n",
144
+ " # Prompt\n",
145
+ " prompt = ChatPromptTemplate.from_messages(\n",
146
+ " [\n",
147
+ " (\"system\", BASE_PROMPT),\n",
148
+ " MessagesPlaceholder(\"chat_history\", optional=True),\n",
149
+ " (\"human\", \"{input}\"),\n",
150
+ " MessagesPlaceholder(\"agent_scratchpad\"),\n",
151
+ " ]\n",
152
+ " )\n",
153
+ " # Construct the tool calling agent\n",
154
+ " agent = create_tool_calling_agent(llm=llm, tools=kfinance_client.langchain_tools, prompt=prompt)\n",
155
+ " # Create an agent executor by passing in the agent and tools\n",
156
+ " self.agent_executor = AgentExecutor(agent=agent, tools=kfinance_client.langchain_tools, verbose=True)\n",
157
+ "\n",
158
+ "\n",
159
+ " def start_chatting(self) -> None:\n",
160
+ " \"\"\"Open chat shell\"\"\"\n",
161
+ " while True:\n",
162
+ " user_input = input(\"Enter your message and press the [return] key\\n\")\n",
163
+ " self.agent_executor.invoke({\"input\": user_input})\n",
164
+ " sys.stdout.write(\"\\n\")\n"
165
+ ]
166
+ },
167
+ {
168
+ "cell_type": "code",
169
+ "execution_count": null,
170
+ "metadata": {},
171
+ "outputs": [],
172
+ "source": [
173
+ "# instantiate LangChainGeminiChat with the kfinance client\n",
174
+ "gemini_chat = LangChainGeminiChat(kfinance_client)\n",
175
+ "# start chatting with LangChainGeminiChat\n",
176
+ "gemini_chat.start_chatting()"
177
+ ]
178
+ }
179
+ ],
180
+ "metadata": {
181
+ "language_info": {
182
+ "name": "python"
183
+ },
184
+ "orig_nbformat": 4,
185
+ "kernelspec": {
186
+ "name": "python3",
187
+ "language": "python",
188
+ "display_name": "Python 3 (ipykernel)"
189
+ }
190
+ },
191
+ "nbformat": 4,
192
+ "nbformat_minor": 2
193
+ }
@@ -0,0 +1,193 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "##### Copyright 2025 Kensho Technologies, LLC"
9
+ ]
10
+ },
11
+ {
12
+ "attachments": {},
13
+ "cell_type": "markdown",
14
+ "metadata": {
15
+ "id": "-zOQ3ZfKSrT2"
16
+ },
17
+ "source": [
18
+ "# LangChain Tool Calling with GPT-4o\n",
19
+ "**_GPT to retrieve data from the LLM-ready API using the kFinance python library!_**\n",
20
+ "\n",
21
+ "What you'll need to run this notebook:\n",
22
+ "\n",
23
+ "1. kFinance credentials\n",
24
+ "2. An OpenAI API key\n",
25
+ "\n",
26
+ "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
27
+ " <td>\n",
28
+ " <a target=\"_blank\" href=\"https://colab.research.google.com/github/kensho-technologies/kfinance/blob/main/example_notebooks/tool_calling/langchain/openai_langchain_tool_calling.ipynb\"><img src=\"../../../images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
29
+ " </td>\n",
30
+ "</table>"
31
+ ]
32
+ },
33
+ {
34
+ "attachments": {},
35
+ "cell_type": "markdown",
36
+ "metadata": {
37
+ "id": "ruP6MHfzR2Y4"
38
+ },
39
+ "source": [
40
+ "## Install dependencies"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": null,
46
+ "metadata": {
47
+ "colab": {
48
+ "base_uri": "https://localhost:8080/"
49
+ },
50
+ "collapsed": true,
51
+ "id": "YAwU0_7TRhV7",
52
+ "jupyter": {
53
+ "outputs_hidden": true
54
+ },
55
+ "outputId": "e6ebf89c-7680-4852-e52b-c99610107cdf"
56
+ },
57
+ "outputs": [],
58
+ "source": [
59
+ "# install the latest version of kFinance package\n",
60
+ "%pip install kensho-kfinance\n",
61
+ "# install langchain and openai\n",
62
+ "%pip install openai\n",
63
+ "%pip install langchain\n",
64
+ "%pip install langchain-openai"
65
+ ]
66
+ },
67
+ {
68
+ "attachments": {},
69
+ "cell_type": "markdown",
70
+ "metadata": {
71
+ "id": "e_G2p3tTSHeo"
72
+ },
73
+ "source": [
74
+ "# Instantiate kFinance Client"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": null,
80
+ "metadata": {
81
+ "id": "7QPnfPuX87rg"
82
+ },
83
+ "outputs": [],
84
+ "source": [
85
+ "# import the kfinance client\n",
86
+ "import sys\n",
87
+ "from kfinance.kfinance import Client\n",
88
+ "# check if the current environment is a Google Colab\n",
89
+ "try:\n",
90
+ " import google.colab\n",
91
+ " IN_GOOGLE_COLAB = True\n",
92
+ "except:\n",
93
+ " IN_GOOGLE_COLAB = False\n",
94
+ "\n",
95
+ "# initialize the kfinance client with one of the following:\n",
96
+ "# 1. your kensho refresh token\n",
97
+ "# 2. your kensho client id and kensho private key\n",
98
+ "# 3. automated login (not accessible on Google Collab)\n",
99
+ "if IN_GOOGLE_COLAB:\n",
100
+ " kensho_refresh_token = \"\"\n",
101
+ " assert kensho_refresh_token != \"\", \"kensho refresh token is empty! Make sure to enter your kensho refresh token above\"\n",
102
+ " kfinance_client = Client(refresh_token=kensho_refresh_token)\n",
103
+ "\n",
104
+ " # kensho_client_id = \"\"\n",
105
+ " # kensho_private_key = \"\"\n",
106
+ " # assert kensho_client_id != \"\", \"kensho client id is empty! Make sure to enter your kensho client id above\"\n",
107
+ " # assert kensho_private_key != \"\", \"kensho private key is empty! Make sure to enter your kensho private key above\"\n",
108
+ " # kfinance_client = Client(client_id=kensho_client_id, private_key=kensho_private_key)\n",
109
+ "else:\n",
110
+ " kfinance_client = Client()"
111
+ ]
112
+ },
113
+ {
114
+ "attachments": {},
115
+ "cell_type": "markdown",
116
+ "metadata": {
117
+ "id": "LvQy_66Jioys"
118
+ },
119
+ "source": [
120
+ "# LangChain Tool Calling with OpenAI"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": null,
126
+ "outputs": [],
127
+ "source": [
128
+ "from kfinance.tool_calling.prompts import BASE_PROMPT\n",
129
+ "from pydantic import SecretStr\n",
130
+ "from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
131
+ "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
132
+ "from langchain_openai import ChatOpenAI\n",
133
+ "\n",
134
+ "class LangChainOpenAIChat:\n",
135
+ " def __init__(self, kfinance_client: Client) -> None:\n",
136
+ " # Initialize OpenAI with your OpenAI API key\n",
137
+ " openai_api_key = SecretStr(\"\") # replace with your own key\n",
138
+ " assert openai_api_key != \"\", \"OpenAI API key is empty! Make sure to enter your OpenAI API key above\"\n",
139
+ " llm = ChatOpenAI(model=\"gpt-4o\", api_key=openai_api_key)\n",
140
+ " \n",
141
+ " # Prompt\n",
142
+ " prompt = ChatPromptTemplate.from_messages(\n",
143
+ " [\n",
144
+ " (\"system\", BASE_PROMPT),\n",
145
+ " MessagesPlaceholder(\"chat_history\", optional=True),\n",
146
+ " (\"human\", \"{input}\"),\n",
147
+ " MessagesPlaceholder(\"agent_scratchpad\"),\n",
148
+ " ]\n",
149
+ " )\n",
150
+ " # Construct the tool calling agent\n",
151
+ " agent = create_tool_calling_agent(llm=llm, tools=kfinance_client.langchain_tools, prompt=prompt)\n",
152
+ " # Create an agent executor by passing in the agent and tools\n",
153
+ " self.agent_executor = AgentExecutor(agent=agent, tools=kfinance_client.langchain_tools, verbose=True)\n",
154
+ "\n",
155
+ "\n",
156
+ " def start_chatting(self) -> None:\n",
157
+ " \"\"\"Open chat shell\"\"\"\n",
158
+ " while True:\n",
159
+ " user_input = input(\"Enter your message and press the [return] key\\n\")\n",
160
+ " self.agent_executor.invoke({\"input\": user_input})\n",
161
+ " sys.stdout.write(\"\\n\")\n"
162
+ ],
163
+ "metadata": {
164
+ "collapsed": false
165
+ }
166
+ },
167
+ {
168
+ "cell_type": "code",
169
+ "execution_count": null,
170
+ "metadata": {},
171
+ "outputs": [],
172
+ "source": [
173
+ "# instantiate LangChainOpenAIChat with the kfinance client\n",
174
+ "openai_chat = LangChainOpenAIChat(kfinance_client)\n",
175
+ "# start chatting with LangChainOpenAIChat\n",
176
+ "openai_chat.start_chatting()"
177
+ ]
178
+ }
179
+ ],
180
+ "metadata": {
181
+ "language_info": {
182
+ "name": "python"
183
+ },
184
+ "orig_nbformat": 4,
185
+ "kernelspec": {
186
+ "name": "python3",
187
+ "language": "python",
188
+ "display_name": "Python 3 (ipykernel)"
189
+ }
190
+ },
191
+ "nbformat": 4,
192
+ "nbformat_minor": 2
193
+ }