{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "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": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "workspace_id = client.get_current_workspace().id()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'sentiment-model', 'workspace_id': 1, 'number_of_columns': 617, 'input_type': 'float', 'comment': 'e2e test model'}\n"
     ]
    }
   ],
   "source": [
    "from wallaroo.ModelConversion import ConvertSKLearnArguments, ModelConversionSource, ModelConversionInputType\n",
    "source_model_file = open(\"model_conversion_resources/sentiment_model.zip\", \"rb\")\n",
    "model_conversion_args = ConvertSKLearnArguments(\n",
    "    name=\"sentiment-model\",\n",
    "    comment=\"e2e test model\",\n",
    "    workspace_id=workspace_id,\n",
    "    number_of_columns=617,\n",
    "    input_type=ModelConversionInputType.Float32\n",
    ")\n",
    "model_conversion_type = ModelConversionSource.SKLEARN\n",
    "print(model_conversion_args.to_dict())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Failed to upload model\n",
      "None\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Traceback (most recent call last):\n",
      "  File \"/opt/conda/lib/python3.8/site-packages/wallaroo/client.py\", line 1449, in convert_model\n",
      "    response = requests.post(\n",
      "  File \"/opt/conda/lib/python3.8/site-packages/requests/models.py\", line 900, in json\n",
      "    return complexjson.loads(self.text, **kwargs)\n",
      "  File \"/opt/conda/lib/python3.8/json/__init__.py\", line 357, in loads\n",
      "    return _default_decoder.decode(s)\n",
      "  File \"/opt/conda/lib/python3.8/json/decoder.py\", line 337, in decode\n",
      "    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n",
      "  File \"/opt/conda/lib/python3.8/json/decoder.py\", line 355, in raw_decode\n",
      "    raise JSONDecodeError(\"Expecting value\", s, err.value) from None\n",
      "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n"
     ]
    }
   ],
   "source": [
    "response = client.convert_model(\n",
    "    \"model_conversion_resources/demand_curve.pickle\",\n",
    "    model_conversion_type,\n",
    "    model_conversion_args\n",
    ")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "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
}
