|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "initial_id", |
| 7 | + "metadata": { |
| 8 | + "collapsed": true, |
| 9 | + "ExecuteTime": { |
| 10 | + "end_time": "2023-11-28T06:12:56.855519Z", |
| 11 | + "start_time": "2023-11-28T06:12:56.802199Z" |
| 12 | + } |
| 13 | + }, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "import taskingai\n", |
| 17 | + "# Load TaskingAI API Key fron environment variable" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "source": [ |
| 23 | + "# Tool Module CRUD" |
| 24 | + ], |
| 25 | + "metadata": { |
| 26 | + "collapsed": false |
| 27 | + }, |
| 28 | + "id": "43e38e6ab25cd370" |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": 2, |
| 33 | + "outputs": [], |
| 34 | + "source": [ |
| 35 | + "from taskingai.tool import Action, Function" |
| 36 | + ], |
| 37 | + "metadata": { |
| 38 | + "collapsed": false, |
| 39 | + "ExecuteTime": { |
| 40 | + "end_time": "2023-11-28T06:12:58.243357Z", |
| 41 | + "start_time": "2023-11-28T06:12:58.208415Z" |
| 42 | + } |
| 43 | + }, |
| 44 | + "id": "1da88cd4d728ced9" |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "markdown", |
| 48 | + "source": [ |
| 49 | + "## Action Object" |
| 50 | + ], |
| 51 | + "metadata": { |
| 52 | + "collapsed": false |
| 53 | + }, |
| 54 | + "id": "5ab9d33db7c623a5" |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": 3, |
| 59 | + "outputs": [ |
| 60 | + { |
| 61 | + "name": "stdout", |
| 62 | + "output_type": "stream", |
| 63 | + "text": [ |
| 64 | + "created action: {'action_id': 'bFBdwq9eBsCHelP2Rd1mkaI8',\n", |
| 65 | + " 'authentication': {'content': None, 'secret': None, 'type': 'none'},\n", |
| 66 | + " 'created_timestamp': 1701151980773,\n", |
| 67 | + " 'object': 'Action',\n", |
| 68 | + " 'schema': {'components': {},\n", |
| 69 | + " 'info': {'description': 'API for fetching interesting number facts',\n", |
| 70 | + " 'title': 'Numbers API',\n", |
| 71 | + " 'version': '1.0.0'},\n", |
| 72 | + " 'openapi': '3.0.0',\n", |
| 73 | + " 'paths': {'/{number}': {'get': {'parameters': [{'description': 'The '\n", |
| 74 | + " 'number '\n", |
| 75 | + " 'to '\n", |
| 76 | + " 'get '\n", |
| 77 | + " 'the '\n", |
| 78 | + " 'fact '\n", |
| 79 | + " 'for',\n", |
| 80 | + " 'in': 'path',\n", |
| 81 | + " 'name': 'number',\n", |
| 82 | + " 'required': True,\n", |
| 83 | + " 'schema': {'type': 'integer'}}],\n", |
| 84 | + " 'responses': {'200': {'content': {'text/plain': {'schema': {'type': 'string'}}},\n", |
| 85 | + " 'description': 'A '\n", |
| 86 | + " 'fact '\n", |
| 87 | + " 'about '\n", |
| 88 | + " 'the '\n", |
| 89 | + " 'number'}},\n", |
| 90 | + " 'summary': 'Get fact about a '\n", |
| 91 | + " 'number'}}},\n", |
| 92 | + " 'security': [],\n", |
| 93 | + " 'servers': [{'url': 'http://numbersapi.com'}]}}\n" |
| 94 | + ] |
| 95 | + } |
| 96 | + ], |
| 97 | + "source": [ |
| 98 | + "from taskingai.tool import ActionAuthentication, ActionAuthenticationType\n", |
| 99 | + "from typing import List\n", |
| 100 | + "\n", |
| 101 | + "# create an Action\n", |
| 102 | + "NUMBERS_API_SCHEMA = {\n", |
| 103 | + " \"openapi\": \"3.0.0\",\n", |
| 104 | + " \"info\": {\n", |
| 105 | + " \"title\": \"Numbers API\",\n", |
| 106 | + " \"version\": \"1.0.0\",\n", |
| 107 | + " \"description\": \"API for fetching interesting number facts\"\n", |
| 108 | + " },\n", |
| 109 | + " \"servers\": [\n", |
| 110 | + " {\n", |
| 111 | + " \"url\": \"http://numbersapi.com\"\n", |
| 112 | + " }\n", |
| 113 | + " ],\n", |
| 114 | + " \"paths\": {\n", |
| 115 | + " \"/{number}\": {\n", |
| 116 | + " \"get\": {\n", |
| 117 | + " \"summary\": \"Get fact about a number\",\n", |
| 118 | + " \"parameters\": [\n", |
| 119 | + " {\n", |
| 120 | + " \"name\": \"number\",\n", |
| 121 | + " \"in\": \"path\",\n", |
| 122 | + " \"required\": True,\n", |
| 123 | + " \"description\": \"The number to get the fact for\",\n", |
| 124 | + " \"schema\": {\n", |
| 125 | + " \"type\": \"integer\"\n", |
| 126 | + " }\n", |
| 127 | + " }\n", |
| 128 | + " ],\n", |
| 129 | + " \"responses\": {\n", |
| 130 | + " \"200\": {\n", |
| 131 | + " \"description\": \"A fact about the number\",\n", |
| 132 | + " \"content\": {\n", |
| 133 | + " \"text/plain\": {\n", |
| 134 | + " \"schema\": {\n", |
| 135 | + " \"type\": \"string\"\n", |
| 136 | + " }\n", |
| 137 | + " }\n", |
| 138 | + " }\n", |
| 139 | + " }\n", |
| 140 | + " }\n", |
| 141 | + " }\n", |
| 142 | + " }\n", |
| 143 | + " }\n", |
| 144 | + "}\n", |
| 145 | + "actions: List[Action] = taskingai.tool.bulk_create_actions(\n", |
| 146 | + " schema=NUMBERS_API_SCHEMA,\n", |
| 147 | + " authentication=ActionAuthentication(\n", |
| 148 | + " type=ActionAuthenticationType.NONE,\n", |
| 149 | + " )\n", |
| 150 | + ")\n", |
| 151 | + "action = actions[0]\n", |
| 152 | + "print(f\"created action: {action}\\n\")" |
| 153 | + ], |
| 154 | + "metadata": { |
| 155 | + "collapsed": false, |
| 156 | + "ExecuteTime": { |
| 157 | + "end_time": "2023-11-28T06:13:00.837654Z", |
| 158 | + "start_time": "2023-11-28T06:12:59.549717Z" |
| 159 | + } |
| 160 | + }, |
| 161 | + "id": "1b40bb3464107aa6" |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "code", |
| 165 | + "execution_count": 4, |
| 166 | + "outputs": [ |
| 167 | + { |
| 168 | + "name": "stdout", |
| 169 | + "output_type": "stream", |
| 170 | + "text": [ |
| 171 | + "got action: {'action_id': 'bFBdwq9eBsCHelP2Rd1mkaI8',\n", |
| 172 | + " 'authentication': {'content': None, 'secret': None, 'type': 'none'},\n", |
| 173 | + " 'created_timestamp': 1701151980773,\n", |
| 174 | + " 'object': 'Action',\n", |
| 175 | + " 'schema': {'components': {},\n", |
| 176 | + " 'info': {'description': 'API for fetching interesting number facts',\n", |
| 177 | + " 'title': 'Numbers API',\n", |
| 178 | + " 'version': '1.0.0'},\n", |
| 179 | + " 'openapi': '3.0.0',\n", |
| 180 | + " 'paths': {'/{number}': {'get': {'parameters': [{'description': 'The '\n", |
| 181 | + " 'number '\n", |
| 182 | + " 'to '\n", |
| 183 | + " 'get '\n", |
| 184 | + " 'the '\n", |
| 185 | + " 'fact '\n", |
| 186 | + " 'for',\n", |
| 187 | + " 'in': 'path',\n", |
| 188 | + " 'name': 'number',\n", |
| 189 | + " 'required': True,\n", |
| 190 | + " 'schema': {'type': 'integer'}}],\n", |
| 191 | + " 'responses': {'200': {'content': {'text/plain': {'schema': {'type': 'string'}}},\n", |
| 192 | + " 'description': 'A '\n", |
| 193 | + " 'fact '\n", |
| 194 | + " 'about '\n", |
| 195 | + " 'the '\n", |
| 196 | + " 'number'}},\n", |
| 197 | + " 'summary': 'Get fact about a '\n", |
| 198 | + " 'number'}}},\n", |
| 199 | + " 'security': [],\n", |
| 200 | + " 'servers': [{'url': 'http://numbersapi.com'}]}}\n" |
| 201 | + ] |
| 202 | + } |
| 203 | + ], |
| 204 | + "source": [ |
| 205 | + "# get action\n", |
| 206 | + "action_id: str = action.action_id\n", |
| 207 | + "action: Action = taskingai.tool.get_action(\n", |
| 208 | + " action_id=action_id\n", |
| 209 | + ")\n", |
| 210 | + "\n", |
| 211 | + "print(f\"got action: {action}\\n\")" |
| 212 | + ], |
| 213 | + "metadata": { |
| 214 | + "collapsed": false, |
| 215 | + "ExecuteTime": { |
| 216 | + "end_time": "2023-11-28T06:13:02.735027Z", |
| 217 | + "start_time": "2023-11-28T06:13:01.672743Z" |
| 218 | + } |
| 219 | + }, |
| 220 | + "id": "e991bb600ca2bca9" |
| 221 | + }, |
| 222 | + { |
| 223 | + "cell_type": "code", |
| 224 | + "execution_count": 5, |
| 225 | + "outputs": [ |
| 226 | + { |
| 227 | + "name": "stdout", |
| 228 | + "output_type": "stream", |
| 229 | + "text": [ |
| 230 | + "updated action: {'action_id': 'bFBdwq9eBsCHelP2Rd1mkaI8',\n", |
| 231 | + " 'authentication': {'content': None, 'secret': None, 'type': 'none'},\n", |
| 232 | + " 'created_timestamp': 1701151980773,\n", |
| 233 | + " 'object': 'Action',\n", |
| 234 | + " 'schema': {'info': {'description': 'API for fetching interesting number facts',\n", |
| 235 | + " 'title': 'Numbers API',\n", |
| 236 | + " 'version': '1.0.0'},\n", |
| 237 | + " 'openapi': '3.0.0',\n", |
| 238 | + " 'paths': {'/{number}': {'get': {'parameters': [{'description': 'The '\n", |
| 239 | + " 'number '\n", |
| 240 | + " 'to '\n", |
| 241 | + " 'get '\n", |
| 242 | + " 'the '\n", |
| 243 | + " 'fact '\n", |
| 244 | + " 'for',\n", |
| 245 | + " 'in': 'path',\n", |
| 246 | + " 'name': 'number',\n", |
| 247 | + " 'required': True,\n", |
| 248 | + " 'schema': {'type': 'integer'}}],\n", |
| 249 | + " 'responses': {'200': {'content': {'text/plain': {'schema': {'type': 'string'}}},\n", |
| 250 | + " 'description': 'A '\n", |
| 251 | + " 'fact '\n", |
| 252 | + " 'about '\n", |
| 253 | + " 'the '\n", |
| 254 | + " 'number'}},\n", |
| 255 | + " 'summary': 'Get fun fact about a '\n", |
| 256 | + " 'number)'}}},\n", |
| 257 | + " 'servers': [{'url': 'http://numbersapi.com'}]}}\n" |
| 258 | + ] |
| 259 | + } |
| 260 | + ], |
| 261 | + "source": [ |
| 262 | + "# update action\n", |
| 263 | + "NUMBERS_API_SCHEMA[\"paths\"][\"/{number}\"][\"get\"][\"summary\"] = \"Get fun fact about a number)\"\n", |
| 264 | + "action: Action = taskingai.tool.update_action(\n", |
| 265 | + " action_id=action_id,\n", |
| 266 | + " schema=NUMBERS_API_SCHEMA\n", |
| 267 | + ")\n", |
| 268 | + "\n", |
| 269 | + "print(f\"updated action: {action}\\n\")" |
| 270 | + ], |
| 271 | + "metadata": { |
| 272 | + "collapsed": false, |
| 273 | + "ExecuteTime": { |
| 274 | + "end_time": "2023-11-28T06:13:04.242253Z", |
| 275 | + "start_time": "2023-11-28T06:13:03.300837Z" |
| 276 | + } |
| 277 | + }, |
| 278 | + "id": "495db38e51c0531f" |
| 279 | + }, |
| 280 | + { |
| 281 | + "cell_type": "code", |
| 282 | + "execution_count": 6, |
| 283 | + "outputs": [ |
| 284 | + { |
| 285 | + "name": "stdout", |
| 286 | + "output_type": "stream", |
| 287 | + "text": [ |
| 288 | + "deleted action: bFBdwq9eBsCHelP2Rd1mkaI8\n" |
| 289 | + ] |
| 290 | + } |
| 291 | + ], |
| 292 | + "source": [ |
| 293 | + "# delete action\n", |
| 294 | + "taskingai.tool.delete_action(action_id=action_id)\n", |
| 295 | + "print(f\"deleted action: {action_id}\\n\")" |
| 296 | + ], |
| 297 | + "metadata": { |
| 298 | + "collapsed": false, |
| 299 | + "ExecuteTime": { |
| 300 | + "end_time": "2023-11-28T06:13:05.854062Z", |
| 301 | + "start_time": "2023-11-28T06:13:04.852340Z" |
| 302 | + } |
| 303 | + }, |
| 304 | + "id": "dd53cb15efa35298" |
| 305 | + }, |
| 306 | + { |
| 307 | + "cell_type": "code", |
| 308 | + "execution_count": 7, |
| 309 | + "outputs": [ |
| 310 | + { |
| 311 | + "name": "stdout", |
| 312 | + "output_type": "stream", |
| 313 | + "text": [ |
| 314 | + "fbFBdwq9eBsCHelP2Rd1mkaI8 in action_ids: False\n" |
| 315 | + ] |
| 316 | + } |
| 317 | + ], |
| 318 | + "source": [ |
| 319 | + "# list actions\n", |
| 320 | + "actions = taskingai.tool.list_actions()\n", |
| 321 | + "action_ids = [action.action_id for action in actions]\n", |
| 322 | + "# ensure the action we deleted is not in the list\n", |
| 323 | + "print(f\"f{action_id} in action_ids: {action_id in action_ids}\\n\")" |
| 324 | + ], |
| 325 | + "metadata": { |
| 326 | + "collapsed": false, |
| 327 | + "ExecuteTime": { |
| 328 | + "end_time": "2023-11-28T06:13:07.841316Z", |
| 329 | + "start_time": "2023-11-28T06:13:06.744946Z" |
| 330 | + } |
| 331 | + }, |
| 332 | + "id": "5a1a36d15055918f" |
| 333 | + }, |
| 334 | + { |
| 335 | + "cell_type": "markdown", |
| 336 | + "source": [], |
| 337 | + "metadata": { |
| 338 | + "collapsed": false |
| 339 | + }, |
| 340 | + "id": "2f288bf5d1988887" |
| 341 | + }, |
| 342 | + { |
| 343 | + "cell_type": "markdown", |
| 344 | + "source": [], |
| 345 | + "metadata": { |
| 346 | + "collapsed": false |
| 347 | + }, |
| 348 | + "id": "b1736bf2e80c2dd6" |
| 349 | + } |
| 350 | + ], |
| 351 | + "metadata": { |
| 352 | + "kernelspec": { |
| 353 | + "display_name": "Python 3", |
| 354 | + "language": "python", |
| 355 | + "name": "python3" |
| 356 | + }, |
| 357 | + "language_info": { |
| 358 | + "codemirror_mode": { |
| 359 | + "name": "ipython", |
| 360 | + "version": 2 |
| 361 | + }, |
| 362 | + "file_extension": ".py", |
| 363 | + "mimetype": "text/x-python", |
| 364 | + "name": "python", |
| 365 | + "nbconvert_exporter": "python", |
| 366 | + "pygments_lexer": "ipython2", |
| 367 | + "version": "2.7.6" |
| 368 | + } |
| 369 | + }, |
| 370 | + "nbformat": 4, |
| 371 | + "nbformat_minor": 5 |
| 372 | +} |
0 commit comments