|
333 | 333 | "from mlflow import MlflowClient\n", |
334 | 334 | "\n", |
335 | 335 | "client = MlflowClient()\n", |
336 | | - "registered_model = client.get_registered_model(name=MLFLOW_REGISTERED_MODEL_NAME)\n", |
337 | 336 | "\n", |
338 | | - "latest_version = registered_model.latest_versions[0]\n", |
| 337 | + "# MLflow 3.x removed RegisteredModel.latest_versions - use search_model_versions instead\n", |
| 338 | + "latest_version = client.search_model_versions(\n", |
| 339 | + " filter_string=f\"name='{MLFLOW_REGISTERED_MODEL_NAME}'\",\n", |
| 340 | + " order_by=[\"version_number DESC\"],\n", |
| 341 | + " max_results=1\n", |
| 342 | + ")[0]\n", |
| 343 | + "\n", |
339 | 344 | "model_version = latest_version.version\n", |
340 | 345 | "model_source = latest_version.source\n", |
341 | 346 | "\n", |
342 | | - "# Get S3 URL of model files (for info only)\n", |
343 | | - "artifact_uri = client.get_model_version_download_uri(MLFLOW_REGISTERED_MODEL_NAME, model_version)\n", |
344 | | - "\n", |
345 | 347 | "# MLflow model registry path to use with ModelBuilder\n", |
346 | 348 | "mlflow_model_path = f\"models:/{MLFLOW_REGISTERED_MODEL_NAME}/{model_version}\"\n", |
347 | 349 | "\n", |
348 | 350 | "print(f\"Registered Model: {MLFLOW_REGISTERED_MODEL_NAME}\")\n", |
349 | 351 | "print(f\"Latest Version: {model_version}\")\n", |
350 | | - "print(f\"Source: {model_source}\")\n", |
351 | | - "print(f\"Model artifacts location: {artifact_uri}\")" |
| 352 | + "print(f\"Source (model artifacts location): {model_source}\")\n", |
| 353 | + "print(f\"MLflow model path for deployment: {mlflow_model_path}\")" |
352 | 354 | ] |
353 | 355 | }, |
354 | 356 | { |
|
481 | 483 | "metadata": {}, |
482 | 484 | "outputs": [], |
483 | 485 | "source": [ |
484 | | - "import boto3\n", |
485 | | - "\n", |
486 | 486 | "# Test with JSON input\n", |
487 | 487 | "test_data = [[0.1, 0.2, 0.3, 0.4]]\n", |
488 | 488 | "\n", |
489 | | - "runtime_client = boto3.client('sagemaker-runtime')\n", |
490 | | - "response = runtime_client.invoke_endpoint(\n", |
491 | | - " EndpointName=core_endpoint.endpoint_name,\n", |
492 | | - " Body=json.dumps(test_data),\n", |
493 | | - " ContentType='application/json'\n", |
| 489 | + "result = core_endpoint.invoke(\n", |
| 490 | + " body=json.dumps(test_data),\n", |
| 491 | + " content_type=\"application/json\"\n", |
494 | 492 | ")\n", |
495 | 493 | "\n", |
496 | | - "prediction = json.loads(response['Body'].read().decode('utf-8'))\n", |
| 494 | + "# Decode and display the result\n", |
| 495 | + "prediction = json.loads(result.body.read().decode('utf-8'))\n", |
497 | 496 | "print(f\"Input: {test_data}\")\n", |
498 | 497 | "print(f\"Prediction: {prediction}\")" |
499 | 498 | ] |
|
0 commit comments