|
16 | 16 | "cell_type": "code", |
17 | 17 | "metadata": { |
18 | 18 | "ExecuteTime": { |
19 | | - "end_time": "2025-10-30T16:19:55.580574Z", |
20 | | - "start_time": "2025-10-30T16:19:55.572729Z" |
| 19 | + "end_time": "2025-11-02T13:09:29.782458Z", |
| 20 | + "start_time": "2025-11-02T13:09:29.780008Z" |
21 | 21 | } |
22 | 22 | }, |
23 | 23 | "source": [ |
24 | 24 | "# Install dependencies if needed\n", |
25 | 25 | "# !pip install numpy pandas matplotlib statsmodels" |
26 | 26 | ], |
27 | 27 | "outputs": [], |
28 | | - "execution_count": 60 |
| 28 | + "execution_count": 1 |
29 | 29 | }, |
30 | 30 | { |
31 | 31 | "cell_type": "code", |
32 | 32 | "metadata": { |
33 | 33 | "ExecuteTime": { |
34 | | - "end_time": "2025-10-30T16:19:55.594776Z", |
35 | | - "start_time": "2025-10-30T16:19:55.592104Z" |
| 34 | + "end_time": "2025-11-02T13:09:30.664688Z", |
| 35 | + "start_time": "2025-11-02T13:09:29.885721Z" |
36 | 36 | } |
37 | 37 | }, |
38 | 38 | "source": [ |
|
48 | 48 | "from faim_sdk import FlowStateForecastRequest, ForecastClient" |
49 | 49 | ], |
50 | 50 | "outputs": [], |
51 | | - "execution_count": 61 |
| 51 | + "execution_count": 2 |
52 | 52 | }, |
53 | 53 | { |
54 | 54 | "cell_type": "markdown", |
|
59 | 59 | "cell_type": "code", |
60 | 60 | "metadata": { |
61 | 61 | "ExecuteTime": { |
62 | | - "end_time": "2025-10-30T16:19:55.637833Z", |
63 | | - "start_time": "2025-10-30T16:19:55.620782Z" |
| 62 | + "end_time": "2025-11-02T13:09:31.749271Z", |
| 63 | + "start_time": "2025-11-02T13:09:30.681133Z" |
64 | 64 | } |
65 | 65 | }, |
66 | 66 | "source": [ |
|
106 | 106 | ] |
107 | 107 | } |
108 | 108 | ], |
109 | | - "execution_count": 62 |
| 109 | + "execution_count": 3 |
110 | 110 | }, |
111 | 111 | { |
112 | 112 | "cell_type": "code", |
113 | 113 | "metadata": { |
114 | 114 | "ExecuteTime": { |
115 | | - "end_time": "2025-10-30T16:19:55.666166Z", |
116 | | - "start_time": "2025-10-30T16:19:55.660954Z" |
| 115 | + "end_time": "2025-11-02T13:09:31.764649Z", |
| 116 | + "start_time": "2025-11-02T13:09:31.759429Z" |
117 | 117 | } |
118 | 118 | }, |
119 | 119 | "source": [ |
|
184 | 184 | "</div>" |
185 | 185 | ] |
186 | 186 | }, |
187 | | - "execution_count": 63, |
| 187 | + "execution_count": 4, |
188 | 188 | "metadata": {}, |
189 | 189 | "output_type": "execute_result" |
190 | 190 | } |
191 | 191 | ], |
192 | | - "execution_count": 63 |
| 192 | + "execution_count": 4 |
193 | 193 | }, |
194 | 194 | { |
195 | 195 | "cell_type": "code", |
196 | 196 | "metadata": { |
197 | 197 | "ExecuteTime": { |
198 | | - "end_time": "2025-10-30T16:19:55.729968Z", |
199 | | - "start_time": "2025-10-30T16:19:55.716535Z" |
| 198 | + "end_time": "2025-11-02T13:09:31.803405Z", |
| 199 | + "start_time": "2025-11-02T13:09:31.796959Z" |
200 | 200 | } |
201 | 201 | }, |
202 | 202 | "source": [ |
|
227 | 227 | ] |
228 | 228 | } |
229 | 229 | ], |
230 | | - "execution_count": 64 |
| 230 | + "execution_count": 5 |
231 | 231 | }, |
232 | 232 | { |
233 | 233 | "cell_type": "markdown", |
|
240 | 240 | "cell_type": "code", |
241 | 241 | "metadata": { |
242 | 242 | "ExecuteTime": { |
243 | | - "end_time": "2025-10-30T16:19:55.994396Z", |
244 | | - "start_time": "2025-10-30T16:19:55.906651Z" |
| 243 | + "end_time": "2025-11-02T13:09:31.971193Z", |
| 244 | + "start_time": "2025-11-02T13:09:31.871029Z" |
245 | 245 | } |
246 | 246 | }, |
247 | 247 | "source": [ |
|
284 | 284 | "output_type": "display_data" |
285 | 285 | } |
286 | 286 | ], |
287 | | - "execution_count": 65 |
| 287 | + "execution_count": 6 |
288 | 288 | }, |
289 | 289 | { |
290 | 290 | "cell_type": "code", |
291 | 291 | "metadata": { |
292 | 292 | "ExecuteTime": { |
293 | | - "end_time": "2025-10-30T16:19:56.025546Z", |
294 | | - "start_time": "2025-10-30T16:19:56.022577Z" |
| 293 | + "end_time": "2025-11-02T13:09:31.986196Z", |
| 294 | + "start_time": "2025-11-02T13:09:31.983898Z" |
295 | 295 | } |
296 | 296 | }, |
297 | 297 | "source": [ |
|
326 | 326 | ] |
327 | 327 | } |
328 | 328 | ], |
329 | | - "execution_count": 66 |
| 329 | + "execution_count": 7 |
330 | 330 | }, |
331 | 331 | { |
332 | 332 | "cell_type": "markdown", |
|
337 | 337 | "**Note**: Replace `base_url` with your actual FAIM inference API endpoint." |
338 | 338 | ] |
339 | 339 | }, |
| 340 | + { |
| 341 | + "metadata": { |
| 342 | + "ExecuteTime": { |
| 343 | + "end_time": "2025-11-02T13:09:32.012024Z", |
| 344 | + "start_time": "2025-11-02T13:09:32.010425Z" |
| 345 | + } |
| 346 | + }, |
| 347 | + "cell_type": "code", |
| 348 | + "source": "", |
| 349 | + "outputs": [], |
| 350 | + "execution_count": null |
| 351 | + }, |
340 | 352 | { |
341 | 353 | "cell_type": "code", |
342 | 354 | "metadata": { |
343 | 355 | "ExecuteTime": { |
344 | | - "end_time": "2025-10-30T16:19:56.053034Z", |
345 | | - "start_time": "2025-10-30T16:19:56.043036Z" |
| 356 | + "end_time": "2025-11-02T13:09:32.047796Z", |
| 357 | + "start_time": "2025-11-02T13:09:32.044621Z" |
346 | 358 | } |
347 | 359 | }, |
348 | 360 | "source": [ |
|
351 | 363 | "# BASE_URL = \"http://localhost:8003\" # Example: \"https://api.faim.example.com\"\n", |
352 | 364 | "# BASE_URL = (\"http://34.141.187.117\") # Example: \"https://api.faim.example.com\"\n", |
353 | 365 | "BASE_URL = (\"https://api.faim.it.com\") # Example: \"https://api.faim.example.com\"\n", |
354 | | - "FAIM_API_KEY = os.environ[\"FAIM_API_KEY\"] # \"your-secret-api-key\"\n", |
| 366 | + "# FAIM_API_KEY = os.environ[\"FAIM_API_KEY\"] # \"your-secret-api-key\"\n", |
| 367 | + "FAIM_API_KEY = \"api_key_1_28bbe832-bbb3-4444-83bd-06d8615bffbb_6hCNkGmAy4TUgcXD8s71t9ALz39CIxJKksHRKBU-dzM\"\n", |
355 | 368 | "client = ForecastClient(\n", |
356 | 369 | " base_url=BASE_URL,\n", |
357 | 370 | " api_key=FAIM_API_KEY, # Optional: API key for authentication\n", |
|
367 | 380 | " assert False, 'you need to set up your API key'" |
368 | 381 | ], |
369 | 382 | "outputs": [ |
370 | | - { |
371 | | - "name": "stderr", |
372 | | - "output_type": "stream", |
373 | | - "text": [ |
374 | | - "INFO:faim_sdk.client:Initialized ForecastClient with authentication: base_url=https://api.faim.it.com, timeout=60.0s\n" |
375 | | - ] |
376 | | - }, |
377 | 383 | { |
378 | 384 | "name": "stdout", |
379 | 385 | "output_type": "stream", |
|
383 | 389 | ] |
384 | 390 | } |
385 | 391 | ], |
386 | | - "execution_count": 67 |
| 392 | + "execution_count": 8 |
387 | 393 | }, |
388 | 394 | { |
389 | 395 | "cell_type": "code", |
390 | 396 | "metadata": { |
391 | 397 | "ExecuteTime": { |
392 | | - "end_time": "2025-10-30T16:19:56.105543Z", |
393 | | - "start_time": "2025-10-30T16:19:56.099754Z" |
| 398 | + "end_time": "2025-11-02T13:09:32.064134Z", |
| 399 | + "start_time": "2025-11-02T13:09:32.062414Z" |
394 | 400 | } |
395 | 401 | }, |
396 | 402 | "source": [ |
397 | 403 | "import logging\n", |
398 | 404 | "\n", |
399 | 405 | "# Enable debug logging\n", |
400 | | - "logging.basicConfig(level=logging.DEBUG)\n" |
| 406 | + "# logging.basicConfig(level=logging.DEBUG)\n" |
401 | 407 | ], |
402 | 408 | "outputs": [], |
403 | | - "execution_count": 68 |
| 409 | + "execution_count": 9 |
| 410 | + }, |
| 411 | + { |
| 412 | + "metadata": { |
| 413 | + "ExecuteTime": { |
| 414 | + "end_time": "2025-11-02T13:09:32.077835Z", |
| 415 | + "start_time": "2025-11-02T13:09:32.075596Z" |
| 416 | + } |
| 417 | + }, |
| 418 | + "cell_type": "code", |
| 419 | + "source": "x.shape", |
| 420 | + "outputs": [ |
| 421 | + { |
| 422 | + "data": { |
| 423 | + "text/plain": [ |
| 424 | + "(1, 250, 1)" |
| 425 | + ] |
| 426 | + }, |
| 427 | + "execution_count": 10, |
| 428 | + "metadata": {}, |
| 429 | + "output_type": "execute_result" |
| 430 | + } |
| 431 | + ], |
| 432 | + "execution_count": 10 |
404 | 433 | }, |
405 | 434 | { |
406 | 435 | "cell_type": "markdown", |
|
411 | 440 | "cell_type": "code", |
412 | 441 | "metadata": { |
413 | 442 | "ExecuteTime": { |
414 | | - "end_time": "2025-10-30T16:19:56.133897Z", |
415 | | - "start_time": "2025-10-30T16:19:56.131085Z" |
| 443 | + "end_time": "2025-11-02T13:09:32.091706Z", |
| 444 | + "start_time": "2025-11-02T13:09:32.088676Z" |
416 | 445 | } |
417 | 446 | }, |
418 | 447 | "source": [ |
|
445 | 474 | ] |
446 | 475 | } |
447 | 476 | ], |
448 | | - "execution_count": 69 |
| 477 | + "execution_count": 11 |
449 | 478 | }, |
450 | 479 | { |
451 | 480 | "cell_type": "markdown", |
|
458 | 487 | "cell_type": "code", |
459 | 488 | "metadata": { |
460 | 489 | "ExecuteTime": { |
461 | | - "end_time": "2025-10-30T16:19:58.648828Z", |
462 | | - "start_time": "2025-10-30T16:19:56.151677Z" |
| 490 | + "end_time": "2025-11-02T13:09:32.883338Z", |
| 491 | + "start_time": "2025-11-02T13:09:32.114395Z" |
463 | 492 | } |
464 | 493 | }, |
465 | 494 | "source": [ |
|
488 | 517 | "name": "stderr", |
489 | 518 | "output_type": "stream", |
490 | 519 | "text": [ |
491 | | - "DEBUG:faim_sdk.client:Starting forecast: model=flowstate, version=1, x.shape=(1, 250, 1), horizon=20\n", |
492 | | - "DEBUG:faim_sdk.client:Serialized request: 1520 bytes, metadata={'horizon': 20, 'output_type': 'point', 'scale_factor': 0.65, 'prediction_type': 'mean'}\n", |
493 | | - "DEBUG:httpcore.connection:connect_tcp.started host='api.faim.it.com' port=443 local_address=None timeout=60.0 socket_options=None\n", |
494 | | - "DEBUG:httpcore.connection:connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x125c7e200>\n", |
495 | | - "DEBUG:httpcore.connection:start_tls.started ssl_context=<ssl.SSLContext object at 0x125c1ba40> server_hostname='api.faim.it.com' timeout=60.0\n", |
496 | | - "DEBUG:httpcore.connection:start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x125c7f250>\n", |
497 | | - "DEBUG:httpcore.http11:send_request_headers.started request=<Request [b'POST']>\n", |
498 | | - "DEBUG:httpcore.http11:send_request_headers.complete\n", |
499 | | - "DEBUG:httpcore.http11:send_request_body.started request=<Request [b'POST']>\n", |
500 | | - "DEBUG:httpcore.http11:send_request_body.complete\n", |
501 | | - "DEBUG:httpcore.http11:receive_response_headers.started request=<Request [b'POST']>\n", |
502 | | - "DEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 401, b'Unauthorized', [(b'date', b'Thu, 30 Oct 2025 16:19:57 GMT'), (b'server', b'uvicorn'), (b'Content-Length', b'74'), (b'content-type', b'application/json'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000')])\n", |
503 | | - "INFO:httpx:HTTP Request: POST https://api.faim.it.com/v1/ts/forecast/flowstate/1 \"HTTP/1.1 401 Unauthorized\"\n", |
504 | | - "DEBUG:httpcore.http11:receive_response_body.started request=<Request [b'POST']>\n", |
505 | | - "DEBUG:httpcore.http11:receive_response_body.complete\n", |
506 | | - "DEBUG:httpcore.http11:response_closed.started\n", |
507 | | - "DEBUG:httpcore.http11:response_closed.complete\n", |
508 | | - "ERROR:faim_sdk.client:Unexpected status code: 401\n" |
| 520 | + "API error: status=401, code=INVALID_API_KEY, message=API key not found or inactive, request_id=<faim_client.types.Unset object at 0x1222da620>\n" |
509 | 521 | ] |
510 | 522 | }, |
511 | 523 | { |
512 | 524 | "name": "stdout", |
513 | 525 | "output_type": "stream", |
514 | 526 | "text": [ |
515 | | - "✗ Forecast failed: Unexpected status code: 401 | status=401\n", |
| 527 | + "✗ Forecast failed: API key not found or inactive | status=401 | error_code=INVALID_API_KEY\n", |
516 | 528 | "\n", |
517 | | - "Error type: APIError\n", |
| 529 | + "Error type: AuthenticationError\n", |
518 | 530 | "Details: {}\n" |
519 | 531 | ] |
520 | 532 | }, |
521 | 533 | { |
522 | | - "ename": "APIError", |
523 | | - "evalue": "Unexpected status code: 401 | status=401", |
| 534 | + "ename": "AuthenticationError", |
| 535 | + "evalue": "API key not found or inactive | status=401 | error_code=INVALID_API_KEY", |
524 | 536 | "output_type": "error", |
525 | 537 | "traceback": [ |
526 | 538 | "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", |
527 | | - "\u001B[0;31mAPIError\u001B[0m Traceback (most recent call last)", |
528 | | - "Cell \u001B[0;32mIn[70], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# Make forecast request\u001B[39;00m\n\u001B[0;32m----> 3\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mforecast\u001B[49m\u001B[43m(\u001B[49m\u001B[43mModelName\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mFLOWSTATE\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 5\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m✓ Forecast successful!\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mResponse: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n", |
529 | | - "File \u001B[0;32m~/Documents/Personal/research/FAIM/faim-client/faim_sdk/client.py:225\u001B[0m, in \u001B[0;36mForecastClient.forecast\u001B[0;34m(self, model, request)\u001B[0m\n\u001B[1;32m 223\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m200\u001B[39m:\n\u001B[1;32m 224\u001B[0m logger\u001B[38;5;241m.\u001B[39merror(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mUnexpected status code: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mstatus_code\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m--> 225\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m APIError(\n\u001B[1;32m 226\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mUnexpected status code: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mstatus_code\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 227\u001B[0m status_code\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mstatus_code,\n\u001B[1;32m 228\u001B[0m response\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mparsed \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(response, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mparsed\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01melse\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m,\n\u001B[1;32m 229\u001B[0m )\n\u001B[1;32m 231\u001B[0m \u001B[38;5;66;03m# Deserialize successful response\u001B[39;00m\n\u001B[1;32m 232\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n", |
530 | | - "\u001B[0;31mAPIError\u001B[0m: Unexpected status code: 401 | status=401" |
| 539 | + "\u001B[0;31mAuthenticationError\u001B[0m Traceback (most recent call last)", |
| 540 | + "Cell \u001B[0;32mIn[12], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# Make forecast request\u001B[39;00m\n\u001B[0;32m----> 3\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mforecast\u001B[49m\u001B[43m(\u001B[49m\u001B[43mModelName\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mFLOWSTATE\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 5\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m✓ Forecast successful!\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mResponse: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n", |
| 541 | + "File \u001B[0;32m~/Documents/Personal/research/FAIM/faim-client/faim_sdk/client.py:247\u001B[0m, in \u001B[0;36mForecastClient.forecast\u001B[0;34m(self, model, request)\u001B[0m\n\u001B[1;32m 245\u001B[0m \u001B[38;5;66;03m# Map HTTP status code to exception class\u001B[39;00m\n\u001B[1;32m 246\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;129;01min\u001B[39;00m (\u001B[38;5;241m401\u001B[39m, \u001B[38;5;241m403\u001B[39m):\n\u001B[0;32m--> 247\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m AuthenticationError(\n\u001B[1;32m 248\u001B[0m message\u001B[38;5;241m=\u001B[39mmessage,\n\u001B[1;32m 249\u001B[0m status_code\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mstatus_code,\n\u001B[1;32m 250\u001B[0m error_response\u001B[38;5;241m=\u001B[39merror_response,\n\u001B[1;32m 251\u001B[0m )\n\u001B[1;32m 252\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;241m==\u001B[39m \u001B[38;5;241m402\u001B[39m:\n\u001B[1;32m 253\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m InsufficientFundsError(\n\u001B[1;32m 254\u001B[0m message\u001B[38;5;241m=\u001B[39mmessage,\n\u001B[1;32m 255\u001B[0m status_code\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mstatus_code,\n\u001B[1;32m 256\u001B[0m error_response\u001B[38;5;241m=\u001B[39merror_response,\n\u001B[1;32m 257\u001B[0m )\n", |
| 542 | + "\u001B[0;31mAuthenticationError\u001B[0m: API key not found or inactive | status=401 | error_code=INVALID_API_KEY" |
531 | 543 | ] |
532 | 544 | } |
533 | 545 | ], |
534 | | - "execution_count": 70 |
| 546 | + "execution_count": 12 |
535 | 547 | }, |
536 | 548 | { |
537 | 549 | "cell_type": "markdown", |
|
0 commit comments