Skip to content

Commit

Permalink
add documentation for azure
Browse files Browse the repository at this point in the history
  • Loading branch information
haesleinhuepf committed Sep 21, 2024
1 parent 34acde7 commit 6c3356e
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ bob.initialize(
model='Phi-3.5-mini-instruct')
```

Alternatively, you can specify the endpoint directly, too:
```
bob.initialize(
endpoint='https://models.inference.ai.azure.com',
model='Phi-3.5-mini-instruct')
```


### Using custom endpoints

Custom endpoints can be used as well if they support the OpenAI API. Examples are [blablador](https://login.helmholtz.de/oauth2-as/oauth2-authz-web-entry) and [ollama](https://ollama.com/).
Expand Down
176 changes: 176 additions & 0 deletions demo/azure.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b95f8f8a-c13f-4002-a969-12e33bc7797a",
"metadata": {},
"source": [
"# Azure\n",
"You can also access models on [Microsoft Azure](https://azure.microsoft.com/).\n",
"You need to sign up at the platform and store API key to your environment as `AZURE_API_KEY`.\n",
"You can then access models like shown below."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d5779abe-11fb-4b7e-928e-061a9a6b23cb",
"metadata": {},
"outputs": [],
"source": [
"from bia_bob import bob"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a2f361fa-ab46-458b-aebe-9be46cc66c76",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div style=\"font-size:7pt\">\n",
" This notebook may contain text, code and images generated by artificial intelligence.\n",
" Used model: meta-llama-3.1-405b-instruct, vision model: None, endpoint: https://models.inference.ai.azure.com, bia-bob version: 0.23.0.. Do not enter sensitive or private information and verify generated contents according to good scientific practice. Read more: <a href=\"https://github.com/haesleinhuepf/bia-bob#disclaimer\">https://github.com/haesleinhuepf/bia-bob#disclaimer</a>\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"bob.initialize(endpoint=\"azure\", model=\"meta-llama-3.1-405b-instruct\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6b3e4eb3-571a-4c1e-b1dc-bb3c2ea32523",
"metadata": {},
"outputs": [],
"source": [
"%bob Please load blobs.tif and print out its dimensions."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6cb3b4a-33cd-44f3-afb4-5a6d4d667ccf",
"metadata": {},
"outputs": [],
"source": [
"import skimage\n",
"\n",
"# Load the image\n",
"image = skimage.io.imread(\"blobs.tif\")\n",
"\n",
"# Print out the dimensions of the image\n",
"print(image.shape)"
]
},
{
"cell_type": "markdown",
"id": "4707a5d0-8ed0-40b7-b1aa-ef9937929c01",
"metadata": {},
"source": [
"Alternatively, you can also specify the endpoint yourself:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f76239eb-c3b7-4b69-8eaf-bdc6fb198c16",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div style=\"font-size:7pt\">\n",
" This notebook may contain text, code and images generated by artificial intelligence.\n",
" Used model: Phi-3-medium-128k-instruct, vision model: None, endpoint: https://models.inference.ai.azure.com, bia-bob version: 0.23.0.. Do not enter sensitive or private information and verify generated contents according to good scientific practice. Read more: <a href=\"https://github.com/haesleinhuepf/bia-bob#disclaimer\">https://github.com/haesleinhuepf/bia-bob#disclaimer</a>\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import os\n",
"\n",
"bob.initialize(endpoint=\"https://models.inference.ai.azure.com\", \n",
" api_key=os.environ.get('AZURE_API_KEY'),\n",
" model=\"Phi-3-medium-128k-instruct\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "48c7250a-3b22-4d3e-b0f8-df498db1e8ce",
"metadata": {},
"outputs": [],
"source": [
"%bob Please load blobs.tif and print out its dimensions."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "527de356-1250-42ce-abfc-a1b5385d7f06",
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"\n",
"# Load the TIFF image\n",
"with Image.open('blobs.tif') as img:\n",
" # Get the dimensions\n",
" width, height = img.size\n",
" \n",
" # Print the dimensions\n",
" print(f\"Image dimensions: {width} x {height}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10095188-b106-4fab-91a6-e5c32c0a55ab",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 6c3356e

Please sign in to comment.