|
96 | 96 | "source": [
|
97 | 97 | "import opvious\n",
|
98 | 98 | "\n",
|
99 |
| - "OPVIOUS_TOKEN = '' # Enter your API token here\n", |
100 |
| - "\n", |
101 |
| - "client = opvious.Client.default(\"https://try.opvious.io\", token=OPVIOUS_TOKEN)\n", |
| 99 | + "client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n", |
102 | 100 | "\n",
|
103 | 101 | "FORMULATION_NAME = \"bin-packing\"\n",
|
104 | 102 | "\n",
|
|
167 | 165 | "id": "ddb53774-b219-4a22-8d80-8f85224bc6e5",
|
168 | 166 | "metadata": {},
|
169 | 167 | "source": [
|
170 |
| - "We can also make requests without the SDK: under the hood everything goes through the same API (see its OpenAPI specification [here](https://api.cloud.opvious.io/openapi.yaml)). To show how, we implement below a function which returns the minimum number of bins needed to fit the input items (our model's objective value) using the popular `requests` library." |
| 168 | + "We can also make requests without the SDK: under the hood everything goes through the same API (see its OpenAPI specification [here](https://api.try.opvious.io/openapi.yaml)). To show how, we implement below a function which returns the minimum number of bins needed to fit the input items (our model's objective value) using the popular `requests` library." |
171 | 169 | ]
|
172 | 170 | },
|
173 | 171 | {
|
|
198 | 196 | }
|
199 | 197 | ],
|
200 | 198 | "source": [
|
| 199 | + "import os\n", |
201 | 200 | "import requests\n",
|
202 | 201 | "\n",
|
| 202 | + "_token = os.environ.get('OPVIOUS_TOKEN')\n", |
| 203 | + "\n", |
203 | 204 | "def minimum_bin_count(bin_max_weight, item_weights, version_tag='latest'):\n",
|
204 | 205 | " \"\"\"Returns the minimum number of bins needed to fit the input items\n",
|
205 | 206 | "\n",
|
|
209 | 210 | " version_tag: Model version tag\n",
|
210 | 211 | " \"\"\"\n",
|
211 | 212 | " response = requests.post(\n",
|
212 |
| - " url='https://api.cloud.opvious.io/solve',\n", |
| 213 | + " url=f'{client.executor.endpoint}/solve',\n", |
213 | 214 | " headers={\n",
|
214 | 215 | " 'accept': 'application/json',\n",
|
215 |
| - " 'authorization': f'Bearer {OPVIOUS_TOKEN}',\n", |
| 216 | + " 'authorization': f'Bearer {_token}',\n", |
216 | 217 | " },\n",
|
217 | 218 | " json={\n",
|
218 | 219 | " 'problem': {\n",
|
|
228 | 229 | " )\n",
|
229 | 230 | " return response.json()['outcome']['objectiveValue']\n",
|
230 | 231 | "\n",
|
231 |
| - "if OPVIOUS_TOKEN:\n", |
| 232 | + "if _token:\n", |
232 | 233 | " minimum_bin_count(15, {\n",
|
233 | 234 | " 'light': 5,\n",
|
234 | 235 | " 'medium': 10,\n",
|
|
0 commit comments