{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import wallaroo\n",
    "import os\n",
    "import json\n",
    "os.environ['DEPLOYMENT_CONFIG'] = json.dumps({\"cpus\": 0.1, \"replica_count\": 1, \"memory\": \"100Mi\"})\n",
    "os.environ[\"WALLAROO_SDK_CREDENTIALS\"] = \"creds.json\"\n",
    "if os.environ.get(\"WALLAROO_SDK_CREDENTIALS\"):\n",
    "    auth_type=\"user_password\"\n",
    "else:\n",
    "    auth_type=\"none\"\n",
    "client = wallaroo.Client(auth_type=auth_type)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "workspace_id = client.get_current_workspace().id()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from wallaroo.ModelConversion import ConvertKerasArguments, ModelConversionSource\n",
    "source_model_file = open(\"model_conversion_resources/sentiment_model.zip\", \"rb\")\n",
    "model_conversion_args = ConvertKerasArguments(\n",
    "    name=\"sentiment-model\",\n",
    "    comment=\"e2e test model\",\n",
    "    workspace_id=workspace_id\n",
    ")\n",
    "model_conversion_type = ModelConversionSource.KERAS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'source_model_id': 31, 'model_id': 48}\n",
      "(48, 31)\n"
     ]
    }
   ],
   "source": [
    "response = client.convert_model(\n",
    "    \"sentiment_model.zip\",\n",
    "    model_conversion_type,\n",
    "    model_conversion_args\n",
    ")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "assert type(response).__name__ == \"tuple\"\n",
    "assert type(response[0]).__name__ == \"int\"\n",
    "assert type(response[1]).__name__ == \"int\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
