Skip to content

Commit 5833863

Browse files
committed
UPdate
1 parent 1028806 commit 5833863

1 file changed

Lines changed: 90 additions & 90 deletions

File tree

examples/tools/api_as_tool.ipynb

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 0,
4-
"metadata": {
5-
"colab": {
6-
"provenance": []
7-
},
8-
"kernelspec": {
9-
"name": "python3",
10-
"display_name": "Python 3"
11-
},
12-
"language_info": {
13-
"name": "python"
14-
}
15-
},
162
"cells": [
173
{
184
"cell_type": "code",
@@ -27,6 +13,11 @@
2713
},
2814
{
2915
"cell_type": "code",
16+
"execution_count": 114,
17+
"metadata": {
18+
"id": "HHduMDd9gtFs"
19+
},
20+
"outputs": [],
3021
"source": [
3122
"import httpx\n",
3223
"import logging\n",
@@ -134,45 +125,57 @@
134125
" fields[key] = (field_type, default_value)\n",
135126
"\n",
136127
" return create_model(model_name, **fields)"
137-
],
138-
"metadata": {
139-
"id": "HHduMDd9gtFs"
140-
},
141-
"execution_count": 114,
142-
"outputs": []
128+
]
143129
},
144130
{
145131
"cell_type": "code",
146-
"source": [
147-
"api_client = APIClient(base_url=\"https://chat.enso.sh/api\")\n",
148-
"\n",
149-
"await api_client.get(endpoint=\"/info/health\")"
150-
],
132+
"execution_count": 116,
151133
"metadata": {
152134
"colab": {
153135
"base_uri": "https://localhost:8080/"
154136
},
155137
"id": "uZIpXGaOg6ZZ",
156138
"outputId": "702117fc-8601-4177-a7aa-082427676f65"
157139
},
158-
"execution_count": 116,
159140
"outputs": [
160141
{
161-
"output_type": "execute_result",
162142
"data": {
163143
"text/plain": [
164144
"{'status': 'healthy',\n",
165145
" 'message': 'Service is running',\n",
166146
" 'version': '0.0.2-rc109'}"
167147
]
168148
},
149+
"execution_count": null,
169150
"metadata": {},
170-
"execution_count": 116
151+
"output_type": "execute_result"
171152
}
153+
],
154+
"source": [
155+
"api_client = APIClient(base_url=\"https://chat.enso.sh/api\")\n",
156+
"\n",
157+
"await api_client.get(endpoint=\"/info/health\")"
172158
]
173159
},
174160
{
175161
"cell_type": "code",
162+
"execution_count": 113,
163+
"metadata": {
164+
"colab": {
165+
"base_uri": "https://localhost:8080/"
166+
},
167+
"id": "m4JgXE5DwdK8",
168+
"outputId": "8ae5dba6-366f-4395-9ec7-59341756284f"
169+
},
170+
"outputs": [
171+
{
172+
"name": "stdout",
173+
"output_type": "stream",
174+
"text": [
175+
"{'threads': [{'namespace': ['044ab09f-caa6-4324-b23e-d61510364046', 'threads'], 'key': 'bf3610a6-210b-47af-877e-b4022b2971ec', 'value': {'files': {}, 'todos': [{'status': 'in_progress', 'content': 'Explain how to convert JSON to DataFrame in Python using pandas.'}, {'status': 'in_progress', 'content': 'Explain how to convert JSON to DataFrame in Python using pandas.'}], 'messages': [{'id': 'ab0f31c8-59ea-479d-ac1a-92fbe15d810b', 'name': None, 'type': 'human', 'model': 'openai:gpt-4.1-mini', 'content': [{'text': 'How to convert json to df in python?', 'type': 'text'}], 'additional_kwargs': {}, 'response_metadata': {}}, {'id': 'lc_run--92ce76f7-9d63-45dd-97d0-82a9aa4f9ba0', 'name': None, 'type': 'ai', 'content': '', 'tool_calls': [{'id': 'call_YrqgRyYPXgckBOzquQJx6NiG', 'args': {'todos': [{'status': 'in_progress', 'content': 'Explain how to convert JSON to DataFrame in Python using pandas.'}]}, 'name': 'write_todos', 'type': 'tool_call'}], 'usage_metadata': {'input_tokens': 6157, 'total_tokens': 6192, 'output_tokens': 35, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}, 'additional_kwargs': {}, 'response_metadata': {'model_name': 'gpt-4.1-mini-2025-04-14', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'model_provider': 'openai', 'system_fingerprint': 'fp_24710c7f06'}, 'invalid_tool_calls': []}, {'id': 'lc_run--3ab3438e-4b58-423c-a1fd-be39b9487721', 'name': None, 'type': 'ai', 'content': 'You can convert JSON to a DataFrame in Python using pandas with the following methods:\\n\\n1. Using `pd.read_json()` if you have JSON in a string or file:\\n```python\\nimport pandas as pd\\n\\njson_data = \\'{\"name\": [\"Alice\", \"Bob\"], \"age\": [25, 30]}\\'\\ndf = pd.read_json(json_data)\\nprint(df)\\n```\\n\\n2. Using `pd.DataFrame()` if your JSON is a list of dictionaries (common for records):\\n```python\\nimport pandas as pd\\n\\njson_data = [\\n {\"name\": \"Alice\", \"age\": 25},\\n {\"name\": \"Bob\", \"age\": 30}\\n]\\ndf = pd.DataFrame(json_data)\\nprint(df)\\n```\\n\\nBoth will produce a pandas DataFrame from JSON data.', 'tool_calls': [], 'usage_metadata': {'input_tokens': 6230, 'total_tokens': 6393, 'output_tokens': 163, 'input_token_details': {'audio': 0, 'cache_read': 6144}, 'output_token_details': {'audio': 0, 'reasoning': 0}}, 'additional_kwargs': {}, 'response_metadata': {'model_name': 'gpt-4.1-mini-2025-04-14', 'service_tier': 'default', 'finish_reason': 'stop', 'model_provider': 'openai', 'system_fingerprint': 'fp_24710c7f06'}, 'invalid_tool_calls': []}], 'thread_id': 'bf3610a6-210b-47af-877e-b4022b2971ec', 'project_id': None, 'updated_at': '2025-12-04T19:47:49.117503+00:00', 'assistant_id': None, 'checkpoint_id': '1f0d14a1-ce13-6ec2-8010-e2aaa0e4869b'}, 'created_at': '2025-12-04T19:47:50.055722+00:00', 'updated_at': '2025-12-04T19:47:50.055722+00:00', 'score': None}]}\n"
176+
]
177+
}
178+
],
176179
"source": [
177180
"args_schema_spec = {\n",
178181
" \"limit\": {\n",
@@ -251,42 +254,22 @@
251254
"# Example usage\n",
252255
"result = await tool.ainvoke({\"limit\": 1})\n",
253256
"print(result)"
254-
],
255-
"metadata": {
256-
"colab": {
257-
"base_uri": "https://localhost:8080/"
258-
},
259-
"id": "m4JgXE5DwdK8",
260-
"outputId": "8ae5dba6-366f-4395-9ec7-59341756284f"
261-
},
262-
"execution_count": 113,
263-
"outputs": [
264-
{
265-
"output_type": "stream",
266-
"name": "stdout",
267-
"text": [
268-
"{'threads': [{'namespace': ['044ab09f-caa6-4324-b23e-d61510364046', 'threads'], 'key': 'bf3610a6-210b-47af-877e-b4022b2971ec', 'value': {'files': {}, 'todos': [{'status': 'in_progress', 'content': 'Explain how to convert JSON to DataFrame in Python using pandas.'}, {'status': 'in_progress', 'content': 'Explain how to convert JSON to DataFrame in Python using pandas.'}], 'messages': [{'id': 'ab0f31c8-59ea-479d-ac1a-92fbe15d810b', 'name': None, 'type': 'human', 'model': 'openai:gpt-4.1-mini', 'content': [{'text': 'How to convert json to df in python?', 'type': 'text'}], 'additional_kwargs': {}, 'response_metadata': {}}, {'id': 'lc_run--92ce76f7-9d63-45dd-97d0-82a9aa4f9ba0', 'name': None, 'type': 'ai', 'content': '', 'tool_calls': [{'id': 'call_YrqgRyYPXgckBOzquQJx6NiG', 'args': {'todos': [{'status': 'in_progress', 'content': 'Explain how to convert JSON to DataFrame in Python using pandas.'}]}, 'name': 'write_todos', 'type': 'tool_call'}], 'usage_metadata': {'input_tokens': 6157, 'total_tokens': 6192, 'output_tokens': 35, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}, 'additional_kwargs': {}, 'response_metadata': {'model_name': 'gpt-4.1-mini-2025-04-14', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'model_provider': 'openai', 'system_fingerprint': 'fp_24710c7f06'}, 'invalid_tool_calls': []}, {'id': 'lc_run--3ab3438e-4b58-423c-a1fd-be39b9487721', 'name': None, 'type': 'ai', 'content': 'You can convert JSON to a DataFrame in Python using pandas with the following methods:\\n\\n1. Using `pd.read_json()` if you have JSON in a string or file:\\n```python\\nimport pandas as pd\\n\\njson_data = \\'{\"name\": [\"Alice\", \"Bob\"], \"age\": [25, 30]}\\'\\ndf = pd.read_json(json_data)\\nprint(df)\\n```\\n\\n2. Using `pd.DataFrame()` if your JSON is a list of dictionaries (common for records):\\n```python\\nimport pandas as pd\\n\\njson_data = [\\n {\"name\": \"Alice\", \"age\": 25},\\n {\"name\": \"Bob\", \"age\": 30}\\n]\\ndf = pd.DataFrame(json_data)\\nprint(df)\\n```\\n\\nBoth will produce a pandas DataFrame from JSON data.', 'tool_calls': [], 'usage_metadata': {'input_tokens': 6230, 'total_tokens': 6393, 'output_tokens': 163, 'input_token_details': {'audio': 0, 'cache_read': 6144}, 'output_token_details': {'audio': 0, 'reasoning': 0}}, 'additional_kwargs': {}, 'response_metadata': {'model_name': 'gpt-4.1-mini-2025-04-14', 'service_tier': 'default', 'finish_reason': 'stop', 'model_provider': 'openai', 'system_fingerprint': 'fp_24710c7f06'}, 'invalid_tool_calls': []}], 'thread_id': 'bf3610a6-210b-47af-877e-b4022b2971ec', 'project_id': None, 'updated_at': '2025-12-04T19:47:49.117503+00:00', 'assistant_id': None, 'checkpoint_id': '1f0d14a1-ce13-6ec2-8010-e2aaa0e4869b'}, 'created_at': '2025-12-04T19:47:50.055722+00:00', 'updated_at': '2025-12-04T19:47:50.055722+00:00', 'score': None}]}\n"
269-
]
270-
}
271257
]
272258
},
273259
{
274260
"cell_type": "code",
275-
"source": [
276-
"!wget https://chat.enso.sh/openapi.json -O enso_api.json"
277-
],
261+
"execution_count": 23,
278262
"metadata": {
279263
"colab": {
280264
"base_uri": "https://localhost:8080/"
281265
},
282266
"id": "fVmYXiPilhG2",
283267
"outputId": "ab3e12df-0375-4ea5-a1c3-204003d657fb"
284268
},
285-
"execution_count": 23,
286269
"outputs": [
287270
{
288-
"output_type": "stream",
289271
"name": "stdout",
272+
"output_type": "stream",
290273
"text": [
291274
"--2025-12-06 03:01:07-- https://chat.enso.sh/openapi.json\n",
292275
"Resolving chat.enso.sh (chat.enso.sh)... 172.67.190.155, 104.21.51.225, 2606:4700:3034::6815:33e1, ...\n",
@@ -301,10 +284,51 @@
301284
"\n"
302285
]
303286
}
287+
],
288+
"source": [
289+
"!wget https://chat.enso.sh/openapi.json -O enso_api.json"
304290
]
305291
},
306292
{
307293
"cell_type": "code",
294+
"execution_count": 76,
295+
"metadata": {
296+
"colab": {
297+
"base_uri": "https://localhost:8080/"
298+
},
299+
"id": "5drDelPHo2x9",
300+
"outputId": "3c2386d1-f585-4328-9cba-da70ec17d177"
301+
},
302+
"outputs": [
303+
{
304+
"name": "stdout",
305+
"output_type": "stream",
306+
"text": [
307+
"\n",
308+
"\n",
309+
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
310+
"\u001b[32;1m\u001b[1;3mThought: I need to find the current app version from the health data. First, I will plan API calls to retrieve health information, likely involving fetching health status or app version details. Then, I will execute the plan to get the specific app version information.\n",
311+
"Action: api_planner\n",
312+
"Action Input: Generate API calls to retrieve the current app version from health data\u001b[0m\n",
313+
"Observation: \u001b[36;1m\u001b[1;3mThe provided API endpoints do not include any specific endpoint for retrieving application version information from health data. The health check endpoints available are:\n",
314+
"\n",
315+
"- GET /api/info/health/store\n",
316+
"- GET /api/info/health/checkpointer\n",
317+
"\n",
318+
"These endpoints check the health of the store and checkpointer connections, but do not provide app version details.\n",
319+
"\n",
320+
"Therefore, this query cannot be solved with the current API endpoints.\n",
321+
"\n",
322+
"**Plan:** Sorry, there is no API endpoint available in the current documentation to retrieve the app version from health data.\u001b[0m\n",
323+
"Thought:\u001b[32;1m\u001b[1;3mSince there is no API endpoint available in the current documentation to retrieve the app version from health data, I cannot fulfill this request through the API. \n",
324+
"\n",
325+
"Final Answer: I'm sorry, but there is no available API endpoint to retrieve the current app version from health data.\u001b[0m\n",
326+
"\n",
327+
"\u001b[1m> Finished chain.\u001b[0m\n",
328+
"{'input': 'Current app version from health?', 'output': \"I'm sorry, but there is no available API endpoint to retrieve the current app version from health data.\"}\n"
329+
]
330+
}
331+
],
308332
"source": [
309333
"import json\n",
310334
"from langchain.chat_models import init_chat_model\n",
@@ -346,45 +370,21 @@
346370
"# 7) Use it\n",
347371
"response = api_agent.invoke(\"Current app version from health?\")\n",
348372
"print(response)\n"
349-
],
350-
"metadata": {
351-
"colab": {
352-
"base_uri": "https://localhost:8080/"
353-
},
354-
"id": "5drDelPHo2x9",
355-
"outputId": "3c2386d1-f585-4328-9cba-da70ec17d177"
356-
},
357-
"execution_count": 76,
358-
"outputs": [
359-
{
360-
"output_type": "stream",
361-
"name": "stdout",
362-
"text": [
363-
"\n",
364-
"\n",
365-
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
366-
"\u001b[32;1m\u001b[1;3mThought: I need to find the current app version from the health data. First, I will plan API calls to retrieve health information, likely involving fetching health status or app version details. Then, I will execute the plan to get the specific app version information.\n",
367-
"Action: api_planner\n",
368-
"Action Input: Generate API calls to retrieve the current app version from health data\u001b[0m\n",
369-
"Observation: \u001b[36;1m\u001b[1;3mThe provided API endpoints do not include any specific endpoint for retrieving application version information from health data. The health check endpoints available are:\n",
370-
"\n",
371-
"- GET /api/info/health/store\n",
372-
"- GET /api/info/health/checkpointer\n",
373-
"\n",
374-
"These endpoints check the health of the store and checkpointer connections, but do not provide app version details.\n",
375-
"\n",
376-
"Therefore, this query cannot be solved with the current API endpoints.\n",
377-
"\n",
378-
"**Plan:** Sorry, there is no API endpoint available in the current documentation to retrieve the app version from health data.\u001b[0m\n",
379-
"Thought:\u001b[32;1m\u001b[1;3mSince there is no API endpoint available in the current documentation to retrieve the app version from health data, I cannot fulfill this request through the API. \n",
380-
"\n",
381-
"Final Answer: I'm sorry, but there is no available API endpoint to retrieve the current app version from health data.\u001b[0m\n",
382-
"\n",
383-
"\u001b[1m> Finished chain.\u001b[0m\n",
384-
"{'input': 'Current app version from health?', 'output': \"I'm sorry, but there is no available API endpoint to retrieve the current app version from health data.\"}\n"
385-
]
386-
}
387373
]
388374
}
389-
]
390-
}
375+
],
376+
"metadata": {
377+
"colab": {
378+
"provenance": []
379+
},
380+
"kernelspec": {
381+
"display_name": "Python 3",
382+
"name": "python3"
383+
},
384+
"language_info": {
385+
"name": "python"
386+
}
387+
},
388+
"nbformat": 4,
389+
"nbformat_minor": 0
390+
}

0 commit comments

Comments
 (0)