<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Itay Podhajcer on Medium]]></title>
        <description><![CDATA[Stories by Itay Podhajcer on Medium]]></description>
        <link>https://medium.com/@itaypodhajcer?source=rss-7c3a8d08bc48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XOSQvn7aelKLC76u</url>
            <title>Stories by Itay Podhajcer on Medium</title>
            <link>https://medium.com/@itaypodhajcer?source=rss-7c3a8d08bc48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:51:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@itaypodhajcer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Making the Most of GPU Nodes on Azure Kubernetes Service Using the Nvidia GPU Operator]]></title>
            <link>https://itaypodhajcer.medium.com/making-the-most-of-gpu-nodes-on-azure-kubernetes-service-using-the-nvidia-gpu-operator-39b9f1431549?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/39b9f1431549</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Tue, 27 Aug 2024 13:13:15 GMT</pubDate>
            <atom:updated>2024-08-28T09:28:50.291Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ejNohnDNCEPzO3uodwDqZw.png" /></figure><p>The NVIDIA GPU Operator simplifies the use of NVIDIA GPUs in Kubernetes clusters by automating the installation and configuration of necessary software components, managing the lifecycle of GPU resources, and ensuring smooth updates and maintenance. It reduces manual configuration efforts, minimizes errors, and allows GPU resources to scale efficiently within the cluster, making it easier to handle workloads that require GPU acceleration.</p><p>This article will show how to use the Nvidia GPU Operator to configure the Multi-Instance GPU (MIG) feature, introduced with NVIDIA’s Ampere architecture, which allows a single GPU to be partitioned into multiple smaller, independent instances, each with its own dedicated resources like memory, cache, and compute cores. This enables multiple workloads to run in parallel on a single physical GPU, ensuring predictable performance and enhanced isolation, which is particularly beneficial in multi-tenant environments such as cloud services.</p><h4>Prerequisites</h4><p>To deploy the infrastructure, Terraform and its azurerm provider will be used, so the following should be installed on the workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><p>Also, because the script will be creating a NC A100 v4 based node pool, a request to increase the quota in the used region is required to at least 24 vCPUs (which means one virtual machine instance of the mentioned series), if it hadn’t been done before.</p><h4>Example Repository</h4><p>A complete example Terraform script, which creates a private network, an Azure Kubernetes Service cluster, with an additional GPU-enabled node pool, creates the Nvidia GPU Operator, configures MIG and creates an Ollama service with four replicas, can be found in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/nvidia-gpu-operator-aks">GitHub - ItayPodhajcer/nvidia-gpu-operator-aks</a></p><h4>The Script</h4><p>For brevity, I will only cover the area of the Terraform script that specifically address the steps related to enabling and later scheduling GPU reliant workloads.</p><p>Once an Azure Kubernetes Service resource is defined, the additional GPU node pool based on NC A100 v4 series virtual machines can be created:</p><pre>resource &quot;azurerm_kubernetes_cluster_node_pool&quot; &quot;this&quot; {<br>  name                  = var.name<br>  kubernetes_cluster_id = azurerm_kubernetes_cluster.this.id<br>  vm_size               = &quot;Standard_NC24ads_A100_v4&quot;<br>  node_count            = 1<br>  vnet_subnet_id        = var.subnet_id<br><br>  tags = {<br>    SkipGPUDriverInstall = true<br>  }<br><br>  node_labels = {<br>    &quot;nvidia.com/mig.config&quot; = &quot;all-1g.20gb&quot;<br>  }<br>}</pre><p>Note that a special nvidia.com/mig.config label is being configured on the node pool. That label is used to select a MIG profile that the Nvidia GPU Controller should set up on each new node that is added to the node pool.</p><p>This example uses the all-1g.20gb profile, which is available for Nvidia A100 GPUs with 80GB of VRAM (note that both the A100 and the H100 have various variations with different VRAM capacities, which affect the profiles that are available for that GPU variation), that splits the GPU to four virtual GPUs, each with 20GB of VRAM, an amount that comfortably fits the Llama 3.1 8B model this example is using.</p><p>Once all the cluster related resources are defined, it’s time to move to the actual services, the Nvidia GPU Operator, which can be deployed using the <a href="https://helm.ngc.nvidia.com/nvidia/gpu-operator">https://helm.ngc.nvidia.com/nvidia/gpu-operator</a> chart, and the Ollama service which can be deployed using the <a href="https://otwld.github.io/ollama-helm/ollama">https://otwld.github.io/ollama-helm/ollama</a> chart.</p><p>The Terraform resource for the Nvidia GPU operator Helm chart is pretty straight forward:</p><pre>resource &quot;helm_release&quot; &quot;gpu_operator&quot; {<br>  name             = &quot;gpu-operator&quot;<br>  repository       = &quot;https://helm.ngc.nvidia.com/nvidia&quot;<br>  chart            = &quot;gpu-operator&quot;<br>  version          = var.gpu_operator_chart_version<br>  namespace        = var.deployment_name<br>  create_namespace = true<br><br>  values = [<br>    &quot;${templatefile(&quot;${path.module}/gpu-operator-values.tpl&quot;, {})}&quot;<br>  ]<br>}</pre><p>And uses the following file to load values to the chart:</p><pre>migManager:<br>  env:<br>    - name: WITH_REBOOT<br>      value: &quot;true&quot;</pre><p>Note that this file only includes a setting required when running on cloud-mananged Kubernetes clusters, as the Nvidia GPU Operator needs to be able to restart the new node once it’s done configuring it.</p><p>The next resource is the Ollama service’s Helm chart:</p><pre>resource &quot;helm_release&quot; &quot;ollama&quot; {<br>  name             = local.ollama_service_name<br>  repository       = &quot;https://otwld.github.io/ollama-helm/&quot;<br>  chart            = &quot;ollama&quot;<br>  version          = var.ollama_chart_version<br>  namespace        = var.deployment_name<br>  create_namespace = true<br>  timeout          = 900<br><br>  values = [<br>    &quot;${templatefile(&quot;${path.module}/ollama-values.tpl&quot;, {<br>      port           = var.ollama_port<br>      resource_group = azurerm_resource_group.this.name<br>      ip_address     = azurerm_public_ip.this.ip_address<br>      dns_label_name = local.ollama_service_name<br>    })}&quot;<br>  ]<br><br>  depends_on = [helm_release.gpu_operator]<br>} </pre><p>Note that it relies on the Nvidia GPU Operator Helm chart resource and that it has a longer than default timeout configured, to allow the Nvidia GPU Operator to complete its configuration work.</p><p>The template for the values of the Ollama service sets four replicas, turns on GPU inference, selects the Llama 3.1 model, sets up the external endpoint of the service and defines a toleration that will only allow the containers to be scheduled to a GPU enabled node:</p><pre>replicaCount: 4<br><br>ollama:<br>  gpu:<br>    enabled: true<br>  models:<br>    - llama3.1<br><br>service:<br>  type: LoadBalancer<br>  port: ${port}<br>  annotations:<br>    service.beta.kubernetes.io/azure-load-balancer-resource-group: &quot;${resource_group}&quot;<br>    service.beta.kubernetes.io/azure-load-balancer-ipv4: &quot;${ip_address}&quot;<br>    service.beta.kubernetes.io/azure-dns-label-name: &quot;${dns_label_name}&quot;<br><br>tolerations:<br>  - key: nvidia.com/gpu<br>    operator: Exists<br>    effect: NoSchedule</pre><p>Now that all the resources are defined, the only thing left to do is execute terraform apply and wait for the execution to complete.</p><h4>Testing The deployment</h4><p>Once the deployment is complete, any tool for sending HTTP POST requests can be used to send requests to the Ollama service running on the cluster, for example cUrl:</p><pre>curl http://&lt;ollama-service-hostname&gt;:11434/api/generate -d &#39;{<br>  &quot;model&quot;: &quot;llama3.1&quot;,<br>  &quot;prompt&quot;: &quot;Why is the sky blue?&quot;,<br>  &quot;stream&quot;: false<br>}&#39;</pre><p>That should result in a repose generated by the Llama 3.1 model, with additional statistical information about the generation process.</p><p>The easiest way to send multiple requests to the service would be to just add &amp; to the end of the cUrl command, to let it run in the background instead of blocking the console, run it multiple times and later check the results.</p><h4>Conclusion</h4><p>The Nvidia GPU Operator helps to squeeze out the most out of GPUs by allowing more than one container to be scheduled to a single physical GPU. The caveat with this sort of scheduling is that testing is required to reach the best balance of cost/output ratio, as the more a GPU is split, the more it would take a single model instance to respond.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39b9f1431549" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Ollama on Azure Kubernetes Service]]></title>
            <link>https://medium.com/microsoft/running-ollama-on-azure-kubernetes-service-d98378e10ef7?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/d98378e10ef7</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 15:57:57 GMT</pubDate>
            <atom:updated>2024-08-05T13:58:26.691Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPjZ8CQFRD1vvmJW_r5fVg.png" /></figure><p>Ollama is a framework that simplifies deployment and interaction with Large Language Models without the need for complex setup. It supports popular models like Llama (multiple versions), Mistral and more, all based on transformer architectures. Ollama basically allows us to run our own models without relying on any third party model providers, therefore keeping our information always private and our spending more predictable.</p><p>In this article we will be creating resources on Azure to run Ollama as a container on a GPU-enabled Azure Kubernetes Service managed cluster. This requires, on top of the normal Kubernetes deployment, some additional steps to allow detection of GPUs as allocatable resources in the cluster and scheduling to those resources.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm provider, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><p>Also, because we will be creating a node pool using GPU-enabled virtual machines (VM), we need to make sure we have enough available vCPU quota on azure for the VM family (NCv3 in the case of the examples here) in the region we plan to use (eastus).</p><h4>Example Repository</h4><p>A complete example Terraform script, which creates a private network, an Azure Kubernetes Service cluster, with an additional GPU-enabled node pool, the Nvidia container that enables GPU resources and the actual Ollama container, can be found in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/terraform-ollama-aks">GitHub - ItayPodhajcer/terraform-ollama-aks</a></p><h4>The Script</h4><p>For brevity, I will only cover the area of the Terraform script that specifically address the steps related to enabling and later scheduling GPU reliant workloads.</p><p>Once we have an Azure Kubernetes Service resource defined, we will create the GPU node pool</p><pre>resource &quot;azurerm_kubernetes_cluster_node_pool&quot; &quot;this&quot; {<br>  name                  = &quot;gpu&quot;<br>  kubernetes_cluster_id = azurerm_kubernetes_cluster.this.id<br>  vm_size               = &quot;Standard_NC6s_v3&quot;<br>  node_count            = 1<br>  vnet_subnet_id        = var.subnet_id<br><br>  node_labels = {<br>    &quot;nvidia.com/gpu.present&quot; = &quot;true&quot;<br>  }<br><br>  node_taints = [&quot;sku=gpu:NoSchedule&quot;]<br>}</pre><p>Note the label “nvidia.com/gpu.present” = “true”, which scheduling of the Nvidia Device Plugin pod on that node, and the sku=gpu:NoSchedule taint, which blocks pod who don’t explicitly define that toleration from being scheduled on that node (as we only want pods that require GPU to be scheduled here).</p><p>Next, we create two helm resources, one for running the Nvidia Device Plugin helm chart (https://nvidia.github.io/k8s-device-plugin/nvidia-device-plugin by Nvidia), and one for running the Ollama helm chart (https://otwld.github.io/ollama-helm/ollama by Outworld)</p><pre>resource &quot;helm_release&quot; &quot;nvidia_device_plugin&quot; {<br>  name             = &quot;nvidia-device-plugin&quot;<br>  repository       = &quot;https://nvidia.github.io/k8s-device-plugin&quot;<br>  chart            = &quot;nvidia-device-plugin&quot;<br>  version          = var.nvidia_device_plugin_chart_version<br>  namespace        = var.deployment_name<br>  create_namespace = true<br><br>  values = [<br>    &quot;${templatefile(&quot;${path.module}/nvidia-device-plugin-values.tpl&quot;, {<br>      tag = var.nvidia_device_plugin_tag<br>    })}&quot;<br>  ]<br>}</pre><p>Which uses the nvidia-device-plugin-values.tpl values template file</p><pre>image:<br>  tag: &quot;${tag}&quot;<br><br>tolerations:<br>  - key: CriticalAddonsOnly<br>    operator: Exists<br>  - key: nvidia.com/gpu<br>    operator: Exists<br>    effect: NoSchedule<br>  - key: &quot;sku&quot;<br>    operator: &quot;Equal&quot;<br>    value: &quot;gpu&quot;<br>    effect: &quot;NoSchedule&quot;</pre><p>And</p><pre>resource &quot;helm_release&quot; &quot;ollama&quot; {<br>  name             = local.ollama_service_name<br>  repository       = &quot;https://otwld.github.io/ollama-helm/&quot;<br>  chart            = &quot;ollama&quot;<br>  version          = var.ollama_chart_version<br>  namespace        = var.deployment_name<br>  create_namespace = true<br><br>  values = [<br>    &quot;${templatefile(&quot;${path.module}/ollama-values.tpl&quot;, {<br>      tag            = var.ollama_tag<br>      port           = var.ollama_port<br>      resource_group = azurerm_resource_group.this.name<br>      ip_address     = azurerm_public_ip.this.ip_address<br>      dns_label_name = local.ollama_service_name<br>    })}&quot;<br>  ]<br><br>  depends_on = [helm_release.nvidia_device_plugin]<br>}</pre><p>Which uses the ollama-values.tpl values template file which has llama3 as the model we will be running</p><pre>image:<br>  tag: &quot;${tag}&quot;<br><br>ollama:<br>  gpu:<br>    enabled: true<br>  models:<br>    - llama3<br><br>service:<br>    type: LoadBalancer<br>    port: ${port}<br>    annotations:<br>      service.beta.kubernetes.io/azure-load-balancer-resource-group: &quot;${resource_group}&quot;<br>      service.beta.kubernetes.io/azure-load-balancer-ipv4: &quot;${ip_address}&quot;<br>      service.beta.kubernetes.io/azure-dns-label-name: &quot;${dns_label_name}&quot;<br><br>tolerations:<br>  - key: &quot;sku&quot;<br>    operator: &quot;Equal&quot;<br>    value: &quot;gpu&quot;<br>    effect: &quot;NoSchedule&quot;</pre><p>Note the additional annotations that will allow automatically creating a public hostname for this service, which we can later use for testing, using an IP address defined like this</p><pre>resource &quot;azurerm_public_ip&quot; &quot;this&quot; {<br>  name                = &quot;pip-${local.ollama_service_name}-${var.location}&quot;<br>  location            = azurerm_resource_group.this.location<br>  resource_group_name = azurerm_resource_group.this.name<br>  allocation_method   = &quot;Static&quot;<br>  sku                 = &quot;Standard&quot;<br><br>  lifecycle {<br>    ignore_changes = [<br>      domain_name_label<br>    ]<br>  }<br>}</pre><p>Once all resources are defined, we need to run terraform apply to deploy everything to Azure (you might need to do az login if haven’t done so lately).</p><h4>Testing The deployment</h4><p>Now that the deployment is complete, we can use any tool for sending HTTP POST requests to our cluster, for example cUrl:</p><pre>curl http://&lt;ollama-service-hostname&gt;:11434/api/generate -d &#39;{<br>  &quot;model&quot;: &quot;llama3&quot;,<br>  &quot;prompt&quot;: &quot;Why is the sky blue?&quot;,<br>  &quot;stream&quot;: false<br>}&#39;</pre><p>And get the generated response back from the model, with additional statistical information about the generation process.</p><h4>Conclusion</h4><p>In this article we used the simplest way (at least at the writing of this article) for running workloads that require GPUs on Kubernetes. Some other options which allow more advanced configuration and utilization of the GPU resources, like Nvidia’s GPU Operator and Triton Inference Server, can significantly improve “bang-for-buck” when using GPU VMs, but at the cost of higher complexity. This trade-off sums down to how AI intensive a given system is, meaning the more it requires GPUs, the higher the cost benefits will be from more advanced options.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d98378e10ef7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/running-ollama-on-azure-kubernetes-service-d98378e10ef7">Running Ollama on Azure Kubernetes Service</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Automatic1111’s Stable Diffusion Web UI on Azure]]></title>
            <link>https://medium.com/microsoft/running-automatic1111s-stable-diffusion-web-ui-on-azure-22b3299413ba?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b3299413ba</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Wed, 06 Mar 2024 15:07:42 GMT</pubDate>
            <atom:updated>2024-07-22T14:13:39.600Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EiVofp_TN0i0vCkVUQj1Yg.png" /></figure><p>Automatic1111 Stable Diffusion Web UI is a web interface for Stable Diffusion, an AI model that can generate images from text prompts or modify existing images with text prompts. It is developed under AUTOMATIC1111, a GitHub organization that forked the original Stable Diffusion repository and added many features and improvements. Some of the features of web UI include outpainting, inpaiting, color sketch, prompt matrix, upscale, attention, loopback, z/y/z plot, textual inversion and more.<br>In this article we will be installing Automatic1111’s Stable Diffusion web UI on Azure on a virtual machine that includes an Nvidia V100 GPU, so it has all the processing power it needs and more.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm provider to deploy the environment, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><p>Note that because we will be using a NC6s v3 virtual machine, a quota increase request for that resource will need to be opened through the Azure portal (just search for Quotas in the portal’s search bar).</p><h4>Example Repository</h4><p>A complete Terraform script that creates all the needed resources, installs the required GPU drivers and Automatic1111’s Stable Diffusion web UI on the virtual machine, can be found in the following repository:</p><p><a href="https://github.com/ItayPodhajcer/azure-vm-automatic1111">GitHub - ItayPodhajcer/azure-vm-automatic1111</a></p><h4>Deployment Script</h4><p>For brevity, I will only cover the resources that have configurations specifically related to running the web UI on an Azure VM. The rest, which includes creating a resource group, virtual network, subnet, public IP and key for SSH communication, can be found in the linked repository.</p><p>The first resource that requires configuration specific to web UI is the network security group, which needs to allow communication to the VM through the port used by web UI, which by default is 7860.</p><pre>resource &quot;azurerm_network_security_group&quot; &quot;this&quot; {<br>  name                = &quot;nsg-${var.deployment_name}-${var.location}&quot;<br>  location            = azurerm_resource_group.this.location<br>  resource_group_name = azurerm_resource_group.this.name<br><br>  security_rule {<br>    name                       = &quot;SSH&quot;<br>    priority                   = 1001<br>    direction                  = &quot;Inbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;Tcp&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = &quot;22&quot;<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br><br>  security_rule {<br>    name                       = &quot;HTTO&quot;<br>    priority                   = 1002<br>    direction                  = &quot;Inbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;Tcp&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = local.port<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br>}</pre><p>We will also create two template files, one for the script that will be used to initialize the VM and one to setup the systemd unit for running web UI as a background service.</p><p>The first file, service.tpl, will hold the definition of the systemd unit, setting up the working directory, user and group for running the service and the execution entry point with the arguments that will have web UI configured to listen for external connections and enable API access (so it can also be accessed programmatically).</p><pre>[Unit]<br>Description=Automatic1111 Stable Deffusion WebUI<br><br>[Service]<br>Type=simple<br>WorkingDirectory=/stable-diffusion-webui<br>ExecStart=/stable-diffusion-webui/webui.sh --listen --api<br>User=${user}<br>Group=${user}<br><br>[Install]<br>WantedBy=default.target</pre><p>The second file, custom-date.tpl, will install the drivers for the Nvidia GPU and CUDA cores, install packages needed by web UI, clone the web UI GitHub repository, create the Python environment, and configure the unit using the injected service.tpl file.</p><pre>#!/bin/sh<br><br>add-apt-repository ppa:deadsnakes/ppa<br>apt update<br>apt upgrade<br>apt install git python3.10-venv google-perftools ubuntu-drivers-common -y<br>ubuntu-drivers install<br>wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb<br>apt install ./cuda-keyring_1.1-1_all.deb -y<br>apt update<br>apt install cuda-toolkit-12-3 -y<br>git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui<br>cd stable-diffusion-webui<br>python3.10 -m venv venv<br>chown -R ${user}:${user} /stable-diffusion-webui/<br>echo &#39;${service}&#39; &gt; /etc/systemd/system/automatic1111.service<br>systemctl daemon-reload<br>systemctl enable automatic1111.service<br>reboot</pre><p>Next, add code to read the files to local variables and apply the values to the templates.</p><pre>locals {<br>  port     = &quot;7860&quot;<br>  username = &quot;a1111root&quot;<br><br>  service = templatefile(&quot;${path.module}/service.tpl&quot;, {<br>    user = local.username<br>  })<br><br>  custom_data = templatefile(&quot;${path.module}/custom-data.tpl&quot;, {<br>    service = local.service,<br>    user    = local. Username<br>  })<br>}</pre><p>And lastly, we pass the processed templates’ value to the resource configuration that creates the VM, note that we are using Standard_NC6s_v3, which has a Nvidia V100 GPU.</p><pre>resource &quot;azurerm_linux_virtual_machine&quot; &quot;this&quot; {<br>  name                  = &quot;vm-${var.deployment_name}-${var.location}&quot;<br>  location              = azurerm_resource_group.this.location<br>  resource_group_name   = azurerm_resource_group.this.name<br>  network_interface_ids = [azurerm_network_interface.this.id]<br>  size                  = &quot;Standard_NC6s_v3&quot;<br>  custom_data           = base64encode(local.custom_data)<br><br>  os_disk {<br>    name                 = &quot;disk-${var.deployment_name}-${var.location}&quot;<br>    caching              = &quot;ReadWrite&quot;<br>    storage_account_type = &quot;Premium_LRS&quot;<br>  }<br><br>  source_image_reference {<br>    publisher = &quot;Canonical&quot;<br>    offer     = &quot;0001-com-ubuntu-server-focal&quot;<br>    sku       = &quot;20_04-lts-gen2&quot;<br>    version   = &quot;latest&quot;<br>  }<br><br>  computer_name                   = &quot;vm-${var.deployment_name}-${var.location}&quot;<br>  admin_username                  = local.username<br>  disable_password_authentication = true<br><br>  admin_ssh_key {<br>    username   = local.username<br>    public_key = tls_private_key.this.public_key_openssh<br>  }<br>}</pre><h4>Testing The Deployment</h4><p>To have Terraform deploy the resources, call terraform apply. Once the script is complete, web UI will still not be available, as it takes it a few minutes to install everything on the VM, so you can either wait, or connect to the VM using SSH to follow the logs as everything is being installed.</p><h4>Conclusion</h4><p>The above solution is a very simple, bare minimum, deployment to allow web UI to function properly. To enhance it for production purposes, it would be better to have the VM placed behind something that can provide HTTPS and possibly restrict access using authentication (see Azure Application Gateway or Azure API Management for ideas on that).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b3299413ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/running-automatic1111s-stable-diffusion-web-ui-on-azure-22b3299413ba">Running Automatic1111’s Stable Diffusion Web UI on Azure</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple UniswapV3 Assistant with Azure OpenAI & Semantic Kernel]]></title>
            <link>https://medium.com/microsoft/a-simple-uniswapv3-assistant-with-azure-openai-semantic-kernel-f47b138959af?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/f47b138959af</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 15:33:26 GMT</pubDate>
            <atom:updated>2024-07-22T14:13:12.391Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sj6yuxyGjZDxKldgyUVR0A.png" /></figure><p>Semantic Kernel is an open-source SDK that lets you easily build agents that can integrate existing code and AI models like OpenAI, Azure OpenAI, which we will be using in this article, and Hugging Face. We will use it to create a small tool that can query a subgraph, which is an open API on The Graph that organizes and serves blockchain data using GraphQL queries, specifically for the purposes of this article, UniswapV3’s subgraph.</p><h4>Prerequisites</h4><p>To develop and run our command line app we will need:</p><ul><li>The <a href="https://dotnet.microsoft.com/en-us/download">.NET SDK</a>.</li><li>An IDE, like <a href="https://code.visualstudio.com/download">Visual Studio Code</a> for example.</li><li>An Azure subscription with Azure OpenAI enabled (at the writing of this article there is still a wait list an individual needs to register to through <a href="https://go.microsoft.com/fwlink/?linkid=2222006&amp;clcid=0x409">this form</a>).</li></ul><p>Also, to deploy the Azure OpenAI resources we will be using Terraform’s azurerm provider, so the following are also required</p><ul><li>Terraform, which can be found <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI, which can be found <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><h4>Example Repository</h4><p>As always, the complete code implementation and deployment script can be found in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/azure-openai-semantickernel-subgraph">GitHub - ItayPodhajcer/azure-openai-semantickernel-subgraph</a></p><h4>The Deployment Script</h4><p>We will keep this very simple, a resource group, an Azure AI Services account, an Azure AI Services deployment, a few variables for the deployment name and region, and outputs so we can read the AI service endpoint and access key:</p><pre>provider &quot;azurerm&quot; {<br>  features {}<br>}<br><br>variable &quot;deployment_name&quot; {<br>  default = &quot;uniswapv3assitant&quot;<br>}<br><br>variable &quot;location&quot; {<br>  default = &quot;eastus&quot;<br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;this&quot; {<br>  name     = &quot;rg-${var.deployment_name}-${var.location}&quot;<br>  location = var.location<br>}<br><br>resource &quot;azurerm_cognitive_account&quot; &quot;this&quot; {<br>  name                = &quot;cog-${var.deployment_name}-${var.location}&quot;<br>  location            = azurerm_resource_group.this.location<br>  resource_group_name = azurerm_resource_group.this.name<br>  kind                = &quot;OpenAI&quot;<br>  sku_name            = &quot;S0&quot;<br>}<br><br>resource &quot;azurerm_cognitive_deployment&quot; &quot;this&quot; {<br>  cognitive_account_id = azurerm_cognitive_account.this.id<br>  name                 = var.deployment_name<br><br>  model {<br>    format  = &quot;OpenAI&quot;<br>    name    = &quot;gpt-4-32k&quot;<br>    version = &quot;0613&quot;<br>  }<br><br>  scale {<br>    type     = &quot;Standard&quot;<br>    capacity = 60<br>  }<br>}<br><br>output &quot;endpoint&quot; {<br>  value = azurerm_cognitive_account.this.endpoint<br>}<br><br>output &quot;primary_access_key&quot; {<br>  value     = azurerm_cognitive_account.this.primary_access_key<br>  sensitive = true<br>}</pre><p>Note that we set the capacity of the azurerm_cognitive_deployment to 60, which is the maximum allowed by default, as we will be dealing with big text results (the results of the queries) and we don’t want to get throttled.</p><p>Once the script is done, just execute terraform apply -auto-approve and that should deploy the resources to your Azure subscription (you might need to use az login before running the script to log in to Azure).</p><p>To get the endpoint and access key we execute:</p><pre>terraform output endpoint<br>&gt; Will return the HTTP endpoint<br>terraform output primary_access_key<br>&gt; Will return the access key</pre><h4>The App</h4><p>Now we can start with the app. create a new .NET console using the following command:</p><pre>dotnet new console</pre><p>And add a reference to the Microsoft.SemanticKernel nuget package:</p><pre>dotnet add package Microsoft.SemanticKernel</pre><p>Once our project is setup, we can begin writing the code, starting from the Semantic Kernel plugin, which will be the one actually sending the queries to the UniswapV3 subgraph endpoint:</p><pre>using System.ComponentModel;<br>using System.Net.Http.Json;<br>using Microsoft.SemanticKernel;<br><br>public class UniswapV3SubgraphPlugin<br>{<br>  const string UniswapV3SubgraphEndpoint = &quot;https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3&quot;;<br><br>  private readonly HttpClient _client = new();<br><br>  [KernelFunction]<br>  [Description(&quot;Queries the Uniswap V3 subgraph using GraphQL queries and returns the result in json format.&quot;)]<br>  public async Task&lt;string&gt; QueryAsync([Description(&quot;The GraphQL query&quot;)] string query)<br>  {<br>    HttpRequestMessage request = new(HttpMethod.Post, UniswapV3SubgraphEndpoint)<br>    {<br>      Content = JsonContent.Create(new { query = query })<br>    };<br>    <br>    var response = await _client.SendAsync(request).ConfigureAwait(false);<br>    var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);<br><br>    return result;<br>  }<br>}</pre><p>What makes the QueryAsync functions special, is the KernelFunction attribute, combined with the Description attributes for the function, which describes what the function does, and the function’s argument which describes what that argument should receive. Those descriptions are the ones that are used to determine how the function should be used by the kernel which we will be creating in the next section.</p><p>Now that we have the plugin, we can create the program that will be using it:</p><pre> using Microsoft.SemanticKernel;<br>using Microsoft.SemanticKernel.ChatCompletion;<br>using Microsoft.SemanticKernel.Connectors.OpenAI;<br><br>var builder = Kernel.CreateBuilder();<br><br>var openAiDeployment = Environment.GetEnvironmentVariable(&quot;OPENAI_DEPOYMENT&quot;);<br>var openAiUri = Environment.GetEnvironmentVariable(&quot;OPENAI_URI&quot;);<br>var openAiApiKey = Environment.GetEnvironmentVariable(&quot;OPENAI_API_KEY&quot;);<br><br>builder.Services.AddAzureOpenAIChatCompletion(<br>  deploymentName: openAiDeployment, <br>  endpoint: openAiUri, <br>  apiKey: openAiApiKey);<br><br>builder.Plugins.AddFromType&lt;UniswapV3SubgraphPlugin&gt;();<br><br>var kernel = builder.Build();<br><br>ChatHistory history = [];<br><br>var chatCompletionService = kernel.GetRequiredService&lt;IChatCompletionService&gt;();<br><br>while (true)<br>{<br>    Console.Write(&quot;&gt;&gt; &quot;);<br>    history.AddUserMessage(Console.ReadLine()!);<br><br>    OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()<br>    {<br>        ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions<br>    };<br><br>    var result = await chatCompletionService.GetChatMessageContentAsync(<br>        history,<br>        executionSettings: openAIPromptExecutionSettings,<br>        kernel: kernel);<br><br>    Console.WriteLine(&quot;&lt;&lt; &quot; + result);<br><br>    history.AddAssistantMessage(result.Content);<br>}</pre><p>We read the deployment name, endpoint and access key, which were created by the Terraform script, from environment variables and use them to initialize Azure OpenAI chat completion.</p><p>Next, we add our plugin and call build to get a kernel, a core component that provides states and services for invoking functions and AI models, we can use for interactions during our chat loop, which has the chat completion service configured to automatically call tools, which in this case the tool is our plugin.</p><p>Note that we didn’t configure any prompts or model parameters, we keep everything to the defaults and see how good the results with minimum tweaking are.</p><p>And we’re done! Yes, it’s that simple!</p><p>The only thing left is to execute dotnet run and start querying our command line-based assistant, with text like “top 10 active pools”, for example.</p><p>If there were no failures, you will get a nicely printed result of UniswapV3 pool addresses with some additional information.</p><h4>Conclusion</h4><p>The power of AI, when it can be easily combined with external data sources and operations, becomes much more apparent. To be able to almost effortlessly integrate existing code with generative AI and turn existing services more accessible to non-technical individuals without the need to develop complex user interfaces, like we did in this article to allow plain text queries that hide the complexity crafting GraphQL payloads, is a huge opportunity of new and unique innovations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f47b138959af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/a-simple-uniswapv3-assistant-with-azure-openai-semantic-kernel-f47b138959af">A Simple UniswapV3 Assistant with Azure OpenAI &amp; Semantic Kernel</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Generative AI for a Self-Evolving Software Component]]></title>
            <link>https://medium.com/microsoft/using-generative-ai-for-a-self-evolving-software-component-1d090d8974b2?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d090d8974b2</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Mon, 11 Sep 2023 16:26:26 GMT</pubDate>
            <atom:updated>2024-07-22T14:12:50.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y3v8EGSed29qg4lQJ1zU1Q.png" /></figure><p>With all the hype around generative AI and the question of whether developers will be needed in the future or not, I decided to experiment with on whether software can “write itself” or not, and that is exactly what we will be trying to implement in this article.</p><p>To keep it simple, we will be developing an ASP.NET Core web API that exposes math functions, but instead of writing the functions, we will be using the Azure OpenAI service and the Roslyn .NET compiler to generate and compile code dynamically as HTTP requests arrive to our API.</p><h4>Prerequisites</h4><p>To develop and run our web API we will need:</p><ul><li>The <a href="https://dotnet.microsoft.com/en-us/download">.NET SDK</a>.</li><li>An IDE, like <a href="https://code.visualstudio.com/download">Visual Studio Code</a> for example.</li><li>An Azure subscription with Azure OpenAI enabled (at the writing of this article there is still a wait list an individual needs to register to through <a href="https://go.microsoft.com/fwlink/?linkid=2222006">this form</a>) and GPT-4 Enabled (another wait list, registration through <a href="https://aka.ms/oai/get-gpt4">this form</a>, but should work with earlier version as well).</li><li><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">Azure CLI</a> to create the resources on Azure (the portal can be used instead if prefered).</li></ul><h4>Example Repository</h4><p>As always, the complete code implementation can be found in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/azure-openai-evolving-webapi">GitHub - ItayPodhajcer/azure-openai-evolving-webapi</a></p><h4>The Code</h4><p>We will start by creating a new ASP.NET Core Web API project using the following command:</p><pre>dotnet new webapi -minimal -au None --no-https</pre><p>This will create a minimal Web API project without authentication and HTTPS (to keep it simple).</p><p>Next, we will add the NuGet packages our code will need to do what we want:</p><pre>dotnet add package Azure.AI.OpenAI --prerelease<br>dotnet add package Microsoft.CodeAnalysis.CSharp</pre><p>Note that we are using a prerelease version of the OpenAI package, as at the writing of this article this was the only version available.</p><p>Now we can write the code, starting with Program.cs , first adding some instance registrations for the OpenAIClient and our AI code engine (which we will write next) and few environment variables to pass the URI, deployment name and key for Azure OpenAI (the rest is common Web API wiring):</p><pre>var builder = WebApplication.CreateBuilder(args);<br><br>builder.Services.AddEndpointsApiExplorer();<br>builder.Services.AddSwaggerGen();<br>builder.Services.AddSingleton&lt;IAICodeEngine, AICodeEngine&gt;((services) =&gt; <br>    new AICodeEngine(<br>        services.GetRequiredService&lt;OpenAIClient&gt;(), <br>        Environment.GetEnvironmentVariable(&quot;OPENAI_DEPOYMENT&quot;)));<br>builder.Services.AddSingleton(new OpenAIClient(<br>    new Uri(Environment.GetEnvironmentVariable(&quot;OPENAI_URI&quot;)),<br>    new AzureKeyCredential(Environment.GetEnvironmentVariable(&quot;OPENAI_API_KEY&quot;))));<br>builder.Configuration.AddEnvironmentVariables();<br><br>var app = builder.Build();<br><br>// Configure the HTTP request pipeline.<br>if (app.Environment.IsDevelopment())<br>{<br>    app.UseSwagger();<br>    app.UseSwaggerUI();<br>}</pre><p>And we will add a “catch all” route, which in theory can catch all HTTP verbs at the route we define, but weonly need GET, so it should look like this:</p><pre>app.MapMethods(&quot;/math/{operation}/{*url}&quot;, new[] { &quot;GET&quot; }, async (HttpContext context, IAICodeEngine codeGenerator) =&gt;<br>{<br>    var operationType = &quot;math&quot;;<br>    var operation = context.Request.RouteValues[&quot;operation&quot;]?.ToString() ?? string.Empty;<br>    var valuesString = context.Request.RouteValues[&quot;url&quot;]?.ToString() ?? string.Empty;<br>    var values = valuesString.Split(&#39;/&#39;);<br>    var method = context.Request.Method;<br><br>    if (!codeGenerator.IsImplemented(operationType, operation))<br>    {<br>        await codeGenerator.ImplementAsync(operationType, operation, values.Length, values);<br>    }<br>    <br>    return codeGenerator.Execute(operationType, operation, values);<br>});<br><br>app.Run();</pre><p>Which reads the operation and any additional values (number for the operation) from the path and then calls our AI code engine to check if the operation is implemented, call implement if not and then execute the operation with the passed values.</p><p>Now we will write the AICodeEngine class that is going to do all the magic. First, we will add some private members and a constructor to initialize them:</p><pre>private readonly OpenAIClient _openAIClient;<br>private readonly string _openAIDeployment;<br>private readonly Dictionary&lt;string, OperationInfo&gt; _operations = new();<br>private readonly IEnumerable&lt;PortableExecutableReference&gt; _coreReferences;<br><br>public AICodeEngine(OpenAIClient openAIClient, string openAIDeployment)<br>{<br>    _openAIClient = openAIClient;<br>    _openAIDeployment = openAIDeployment;<br><br>    _coreReferences =<br>        ((string)AppContext.GetData(&quot;TRUSTED_PLATFORM_ASSEMBLIES&quot;))<br>        .Split(Path.PathSeparator)<br>        .Select(path =&gt; MetadataReference.CreateFromFile(path));<br>}</pre><p>They will hold the Azure OpenAI client and deployment name (we will be creating the deployment later), the already implanted operations and a list of code references we need to pass to Roslyn each time we compile generate code (we don’t need to create that list every time, so we do it once in the constructor).</p><p>Next, we add the IsImplemented method, which is pretty straight forward, just checks if an implementation is already available for an operation:</p><pre>public bool IsImplemented(string operationType, string operation) =&gt; <br>    _operations.ContainsKey($&quot;{operationType}-{operation}&quot;);</pre><p>Now we move to the actual generation of new code:</p><pre>private async Task&lt;string&gt; GenerateCodeAsync(string operationType, string operation, int length, string[] examples)<br>{<br>    ChatMessage initializationMessage = new(ChatRole.System,<br>        $&quot;You are a code generation assitant that generates c# classes with random unique names for {operationType} operations. the genrated code should include common using directives. Namespace should have a random unique name. The generated result should be without explanation and without formatting&quot;);<br> <br>    ChatMessage generateCodeMessage = new(ChatRole.User, <br>        $&quot;Generate a non-static {operation} function with a random unique name that accepts {length} arguments like {string.Join(&quot; or &quot;, examples)}&quot;);<br><br>    ChatCompletionsOptions chatCompletionsOptions = new(new [] { initializationMessage, generateCodeMessage })<br>    {<br>        Temperature = 0.5f<br>    };<br><br>    var response = await _openAIClient.GetChatCompletionsAsync(_openAIDeployment, chatCompletionsOptions);<br><br>    return response.Value.Choices[0].Message.Content;<br>}</pre><p>This method first starts with an initialization message, which is our context in this case, that tells the service to generate c# namespaces and classes with unique random names for math operations, include common using directives, required for compilation, and asks for the result to be generated with explanation and formatting (code is usually format in a Markdown code block).</p><p>The second message is a user message asking to generate a function for a given operation using the number of values that were passed in the URL and using the values as examples, so it can determine the types (like int or double for example)</p><p>We also set the Temperature field to 0.5f (default is 1.0f) so the results we get a more predictable and less creative.</p><p>And then call the service and get the response, which is the generated code, that will be passed to the next method for compilation and loading:</p><pre>private Type CompileCode(string code)<br>{<br>    var syntaxTree = CSharpSyntaxTree.ParseText(code);<br><br>    var compilation = CSharpCompilation<br>        .Create(Path.GetRandomFileName())<br>        .WithOptions(new (OutputKind.DynamicallyLinkedLibrary))<br>        .AddReferences(_coreReferences)<br>        .AddSyntaxTrees(syntaxTree);<br><br>    var assembly = ReadAssembly(compilation);<br>    var type = assembly.GetTypes()<br>        .Where(type =&gt; !type.IsAssignableTo(typeof(Attribute)))<br>        .Single();<br>    <br>    return type;<br>}<br><br>private Assembly ReadAssembly(CSharpCompilation compilation)<br>{<br>    using MemoryStream stream = new();<br><br>    compilation.Emit(stream);<br><br>    var assembly = Assembly.Load(stream.ToArray());<br>    <br>    return assembly;<br>}</pre><p>The method parses the code and compiles it as dynamically linked library with the core references we defined in the constructor. Next the compiled code is loaded to get the generated type so an instance can later be created and used by the next method that puts the previous pieces together:</p><pre>public async Task ImplementAsync(string operationType, string operation, int length, string[] examples)<br>{<br>    var code = await GenerateCodeAsync(operationType, operation, length, examples);<br>    var type = CompileCode(code);<br>    var method = type.GetMethods().First();<br>    var instance = Activator.CreateInstance(type);<br><br>    _operations.Add($&quot;{operationType}-{operation}&quot;, <br>        new (instance, <br>            method.GetParameters()<br>                .Select(param =&gt; param.ParameterType)<br>                .ToArray(), <br>            method));<br>}</pre><p>Note that it creates an instance and stores it in our implemented operations dictionary we defined at the beginning, along with the types of the parameters passed to the function extracted from the compiled type (also generated so we need to extract them to know to which types we should convert the values that were passed in the request).</p><p>The last method, after checking if an operation exists and creating an implementation of an operation, is executing it:</p><pre>public object Execute(string operationType, string operation, string[] values)<br>{<br>    var operationInfo = _operations[$&quot;{operationType}-{operation}&quot;];<br>    var args = values<br>      .Select((value, Index) =&gt; Convert.ChangeType(value, operationInfo.argsTypes[Index]))<br>      .ToArray();<br><br>    var result = operationInfo.MethodInfo.Invoke(operationInfo.OperationInstance, args);<br><br>    return result;<br>}</pre><p>Which just pulls the operation from our existing operations dictionary, converts the values to the types the generated code expects, calls it, and returns the value.</p><p>That’s it, we have implemented a self-evolving Web API!</p><h4>Cloud Resources</h4><p>The next thing we need to do is create an Azure OpenAI resource we can use, which is just a few Azure CLI calls away, starting with creating a resource group:</p><pre>az group create \<br>--name rg-evolving-webapi \<br>--location eastus</pre><p>Creating the Azure OpenAI resource:</p><pre>az cognitiveservices account create \<br>--name oai-evolving-webapi \<br>--resource-group rg-evolving-webapi \<br>--location eastus \<br>--kind OpenAI \<br>--sku s0 \</pre><p>Deploying a model:</p><pre>az cognitiveservices account deployment create `<br>--name oai-evolving-webapi `<br>--resource-group  rg-evolving-webapi `<br>--deployment-name evolvingwebapi `<br>--model-name gpt-4 `<br>--model-version &quot;0613&quot; `<br>--model-format OpenAI `<br>--scale-settings-scale-type &quot;Standard&quot;</pre><p>Now we need to pull the endpoint URL:</p><pre>az cognitiveservices account show \<br>--name oai-evolving-webapi \<br>--resource-group rg-evolving-webapi \<br>| jq -r .properties.endpoint</pre><p>And the primary key:</p><pre>az cognitiveservices account keys list \<br>--name oai-evolving-webapi \<br>--resource-group rg-evolving-webapi \<br>| jq -r .key1</pre><p>And we are ready to run!</p><h4>Running The Web API</h4><p>We will need to set the environment variables we defined in code with the values we used and pulled while creating the Azure OpenAI resource:</p><ul><li>OPENAI_DEPOYMENT — the name of the deployment we defined (evolvingwebapi in the example above).</li><li>OPENAI_URI — the endpoint URL.</li><li>OPENAI_API_KEY — the primary key.</li></ul><p>And once we have them set, just run dotnet run.</p><p>To test our service, grab the base URL it’s running on and try the following routes for example:</p><ul><li>/math/add/1.2/3.5</li><li>/math/div/4.5/2</li><li>/math/power/4/3</li></ul><p>Note that the first time an operation is called it takes longer to respond as the code is being generated, but the next calls are fast, as the logic is already ready for use.</p><h4>Conclusion</h4><p>So, to answer the question whether software can write itself, the answer is <strong>yes</strong>, but it’s not as simple as it seems. We intentionally used something simple as math functions because it is quite easy to set a context for that. Real life systems are much more complex and will require setting a context that is much more elaborate, sometimes to elaborate to what is supported by the generative AI services.</p><p>On top of that, this generates code in a running application, which can be nice for small applications (proof-of-concept, simple minimum-viable-product, mockups and similar), but for large systems, which require clear release lifecycles (with everything that it means) and complex architectures, we are still not there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d090d8974b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/using-generative-ai-for-a-self-evolving-software-component-1d090d8974b2">Using Generative AI for a Self-Evolving Software Component</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easily Running Stability AI’s StableStudio on Azure]]></title>
            <link>https://medium.com/microsoft/easily-running-stability-ais-stablestudio-on-azure-312042feec6d?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/312042feec6d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 18:35:30 GMT</pubDate>
            <atom:updated>2024-07-22T14:12:01.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bvo_7ZMNDGboAwliU7jD8g.png" /></figure><p>StableStudio is a web-based application that allows users to create and edit images using generative AI. It is the official open-source variant of DreamStudio, a user interface developed by Stability AI, a company that specializes in generative AI solutions. StableStudio is a community interface that enables anyone to explore the possibilities of generative AI for image creation. In this article we will see how easy it is to deploy StableStudio as a container using Azure Container Instances.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm provider to deploy the environment, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><p>Note that we will need a Stability AI API key, meaning an account, which can be created <a href="https://platform.stability.ai/">here</a>.</p><h4>Example Repository</h4><p>A complete Terraform script that creates a resource group and an Azure Container Instances resource running a generic Node.JS container with instructions for initializing and executing StableStudio web application, can be found in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/terraform-azure-stablestudio">GitHub - ItayPodhajcer/terraform-azure-stablestudio</a></p><h4>Deployment Script</h4><p>We will start by creating a local that will hold the commands needed to inside the container to pull <a href="https://github.com/Stability-AI/StableStudio">StableStudio’s GitHub repository</a>, build the code and run the app:</p><pre>locals {<br>  port = 3000<br>  commands = [<br>    &quot;git clone https://github.com/Stability-AI/StableStudio.git&quot;,<br>    &quot;cd StableStudio&quot;,<br>    &quot;yarn&quot;,<br>    &quot;yarn dev --host&quot;<br>  ]<br>}</pre><p>Note that we also defined a port local as it’s good practice in case the port can be changed in the future, so we will only need to change the value in one place.</p><p>Next, we create a resource group:</p><pre>resource &quot;azurerm_resource_group&quot; &quot;this&quot; {<br>  name     = &quot;rg-${var.deployment_name}-${var.location}&quot;<br>  location = var.location<br>}</pre><p>And lastly, we will create the Azure Container Instances resource to run StableStudio:</p><pre>resource &quot;azurerm_container_group&quot; &quot;this&quot; {<br>  name                = &quot;aci-${var.deployment_name}-${var.location}&quot;<br>  location            = azurerm_resource_group.this.location<br>  resource_group_name = azurerm_resource_group.this.name<br>  ip_address_type     = &quot;Public&quot;<br>  os_type             = &quot;Linux&quot;<br>  dns_name_label      = &quot;${var.deployment_name}-${var.location}&quot;<br><br>  container {<br>    name   = &quot;${var.deployment_name}-container&quot;<br>    image  = &quot;node:latest&quot;<br>    cpu    = &quot;2&quot;<br>    memory = &quot;4&quot;<br><br>    commands = [<br>      &quot;sh&quot;,<br>      &quot;-c&quot;,<br>      join(&quot; &amp;&amp; &quot;, local.commands)<br>    ]<br><br>    ports {<br>      port     = local.port<br>      protocol = &quot;TCP&quot;<br>    }<br>  }<br>}</pre><p>Note that we are using a generic node image and combine all the commands in to one shell command that will be executed by the container when it starts.</p><p>We will also define a variables file with some defaults:</p><pre>variable &quot;deployment_name&quot; {<br>  default = &quot;stablestudio&quot;<br>}<br><br>variable &quot;location&quot; {<br>  default = &quot;eastus&quot;<br>}</pre><p>And an outputs file that will have the final URL to access our StableStudio instance:</p><pre>output &quot;stablestudio_url&quot; {<br>  value = &quot;http://${azurerm_container_group.this.fqdn}:${local. Port}&quot;<br>}</pre><h4>Testing The Deployment</h4><p>All we need to do now, is run the following Terraform command:</p><pre>terraform apply -var=&quot;deployment_name=mystablestudio&quot;</pre><p>Note that although we defined a default value for deployment_name, we should set it to a unique value for our deployment to avoid collisions.</p><h4>Conclusion</h4><p>StableStudio is a very promising user interface for generative AI, as it supports swapping the backend that is being used to perform the actual operations (the default is Stability AI’s servers) to other backends in the future using its plugin system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=312042feec6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/easily-running-stability-ais-stablestudio-on-azure-312042feec6d">Easily Running Stability AI’s StableStudio on Azure</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Decentralized Identifier (DID) Document Hosting on Azure]]></title>
            <link>https://medium.com/microsoft/simple-decentralized-identifier-did-document-hosting-on-azure-ec8b5b139d1?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec8b5b139d1</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Tue, 30 May 2023 14:56:54 GMT</pubDate>
            <atom:updated>2024-07-22T14:11:38.377Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nX0N_hySmLRHAPxN6ImGBQ.png" /></figure><p>Decentralized identifier documents are a new type of digital identity document that enable verifiable and decentralized interactions between any subject and any other entity, without relying on any central authority or intermediary. They are self-sovereign, resolvable, and based on the Decentralized Identifiers (DIDs) v1.0 specification by the World Wide Web Consortium (W3C). One of the methods to create and use them is the did:web method, which leverages the existing web infrastructure and security protocols to host a JSON-LD file at a standard HTTPS URL, meaning they can be hosted and distributed globally using Azure, which is what we will be doing in this article.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm and cloudlare providers to deploy the environment, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><p>Note that we will need a Cloudflare account and a domain in that account for this.</p><h4>Example Repository</h4><p>A complete Terraform script that creates a resource group, a storage account (for a static web site), an Azure CDN instance and a Cloudflare CNAME DNS record, and then uploads various JSON-LD DID documents, can be found in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/terraform-did-web-azure">GitHub - ItayPodhajcer/terraform-did-web-azure</a></p><h4>Deployment Script</h4><p>We will start by reading the Cloudflare zone and creating a resource group:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce8240ea585298546950da42e8a51021/href">https://medium.com/media/ce8240ea585298546950da42e8a51021/href</a></iframe><p>Then create a storage account which will be used to store the documents:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac49e6aaf1732f6ca4233c54abcdd61e/href">https://medium.com/media/ac49e6aaf1732f6ca4233c54abcdd61e/href</a></iframe><p>Next, we create the Azure CDN profile and endpoint to distribute the documents globally:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/618f0634dd16124067786d33f39bfbda/href">https://medium.com/media/618f0634dd16124067786d33f39bfbda/href</a></iframe><p>And lastly create the CNAME record and CDN custom domain configuration to point to the CDN endpoint:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cd633bca03861ab58a0e57f4af309e0/href">https://medium.com/media/9cd633bca03861ab58a0e57f4af309e0/href</a></iframe><p>Now that we have the resources, it is time to upload the JSON-LD DID documents. Note that the DID must match the domain name, having a root DID URI like did:web:eample.com means there must be a did.json file available at the URL https://example.com/.well-known/did.json. For non-root documents, the route in the DID URI did:web:eample.com:sub-docs:doc-a must represent the actual route of the document where it is hosted like so <a href="https://example.com/.well-known/did.json">https://example.com/sub-docs/doc-a/did.json</a> (more on the did:web method specification can be found <a href="https://w3c-ccg.github.io/did-method-web/">here</a>).</p><p>We will use a template for the root document that can look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af193b32cb8427b4468b82fd0dc2bb90/href">https://medium.com/media/af193b32cb8427b4468b82fd0dc2bb90/href</a></iframe><p>And a template for each document hosted in a subdirectory that might look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad9c4d991fcd26e80a2e074b6d490b1b/href">https://medium.com/media/ad9c4d991fcd26e80a2e074b6d490b1b/href</a></iframe><p>Note that both templates have the domain variable defined, so the document can be set with the actual domain used, and in the template that will be used for a document hosted in a subdirectory, there is an additional route variable for setting the documents route to match the path in storage.</p><p>Will upload one document to the root, and have an additional looped resource to upload documents in subdirectories:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/845ec63d9844973b1d6a5ec71f3a435e/href">https://medium.com/media/845ec63d9844973b1d6a5ec71f3a435e/href</a></iframe><h4>Testing The Deployment</h4><p>To check that everything was deployed as expected, we only need to open a browser and point to the correct URLs using the domain we used, like https://example.com/.well-known/did.json for the root document and <a href="https://example.com/.well-known/did.json">https://example.com/route/to/doc/did.json</a> for a document that was placed in the route/to/doc route.</p><h4>Conclusion</h4><p>There are many more DID method specifications, which might be more suitable for other scenarios and systems, so make sure to check the complete list of methods, which can be found <a href="https://w3c.github.io/did-spec-registries/#did-methods">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec8b5b139d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/simple-decentralized-identifier-did-document-hosting-on-azure-ec8b5b139d1">Simple Decentralized Identifier (DID) Document Hosting on Azure</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Mastodon Node Deployment on Azure]]></title>
            <link>https://medium.com/microsoft/simple-mastodon-node-deployment-on-azure-f79f40114d74?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/f79f40114d74</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 16:43:03 GMT</pubDate>
            <atom:updated>2024-07-22T14:11:11.676Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbTANitE5AXzbTl0tw3r8Q.png" /></figure><p>Mastodon is a decentralized social media network that lets users create and join various communities of their choice. Mastodon also supports several types of content, such as audio, video, picture, polls, and more, to help users express themselves online. Mastodon values users’ privacy and freedom of expression by allowing them to choose who can see their posts and who can interact with them. Mastodon allows anyone to run their own server instance and join the network of millions of users, which is exactly what we will be doing in this article.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm provider to deploy the Mastodon instance, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><h4>Example Repository</h4><p>A complete Terraform script that creates a resource group and deploys the Mastodon instance using an Azure Container Instances container group, is available in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/terraform-azure-mastodon">GitHub - ItayPodhajcer/terraform-azure-mastodon</a></p><h4>Deployment Script</h4><p>This script deploys a simple Mastodon instance that can be used for testing purposes, so we will be keeping it as simple as possible, and that’s why will be using Azure Container Instances to do that.</p><p>Also, we will be using <a href="https://hub.docker.com/r/bitnami/mastodon/">Bitnami’s Mastodon image</a> and not the <a href="https://hub.docker.com/r/tootsuite/mastodon/">tootsuite/mastodon</a> image, as it is more automated deployment friendly (the tootsuite image requires running a manual wizard as part of the deployment process).</p><p>We’ll start by creating a few locals (deployment name, database user, mastodon user and Mastodon email), a resource group and passwords (for the database, Elasticsearch and Mastodon admin user):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/524545067f98c436f2aa29c28a117769/href">https://medium.com/media/524545067f98c436f2aa29c28a117769/href</a></iframe><p>Next will create the Azure Container Instances resource and expose the ports 3000 and 4000 for Mastodon web container and the Mastodon streaming container (we will be defining the actual containers inside next):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c6d25471a1695c2087b51384b0e545a/href">https://medium.com/media/9c6d25471a1695c2087b51384b0e545a/href</a></iframe><p>Now we can add the required containers, which are:</p><ul><li>A PostgreSQL database instance</li><li>An Elasticsearch instance</li><li>A Redis instance</li><li>A Mastodon web instance — processes short-lived HTTP requests,</li><li>A Mastodon streaming instance — handles long-lived WebSocket connections for real-time udpates.</li><li>A Mastodon sidekiq instance — handles background processing such as emails, media files and delivering posts to other servers.</li></ul><p>The database container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40f3b7b6a75a6248a9e702d03e13382c/href">https://medium.com/media/40f3b7b6a75a6248a9e702d03e13382c/href</a></iframe><p>The Elasticsearch container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/324c2eb94c9cda800bd2446c3f9637f9/href">https://medium.com/media/324c2eb94c9cda800bd2446c3f9637f9/href</a></iframe><p>The Redis container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6035dd0c72ef293cde3e7313b7d930c0/href">https://medium.com/media/6035dd0c72ef293cde3e7313b7d930c0/href</a></iframe><p>The Mastodon web container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b81e8740937cbc9b2aba58768721668/href">https://medium.com/media/1b81e8740937cbc9b2aba58768721668/href</a></iframe><p>The Mastodon streaming container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10eda05f7c01d5c882c6e7a00c1ba6f2/href">https://medium.com/media/10eda05f7c01d5c882c6e7a00c1ba6f2/href</a></iframe><p>And lastly, the Mastodon sidekiq container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e8187a1bc5c6d0113efb0f29cde1c1/href">https://medium.com/media/26e8187a1bc5c6d0113efb0f29cde1c1/href</a></iframe><p>A few notes:</p><ul><li>The PostgreSQL, Elasticsearch and Redis container all have a dedicated Empty Dir volume.</li><li>The Mastodon web and sidekiq containers have a shred Empty Dir volume.</li><li>Containers inside an Azure Container Instances group communicate with each other using localhost.</li></ul><h4>Testing The Deployment</h4><p>Execute terraform apply, wait for the script to complete, and then let the Mastodon web container run all the initial migrations (this can take a few minutes, you can track the logs from Azure’s portal). Once the migrations are complete, the server will be available through the Azure Container Instances resource FQDN on port 3000.</p><h4>Conclusion</h4><p>The tradeoff of this deployment, being this simple, is that it’s not recommended for a production deployment, as the volumes won’t persist if the containers are stopped. Also, because the Bitnami images use a non-root user, we cannot use Azure Files as volume mounts (they can only be accessed by container running with root), meaning, different services will be required to run the containers (such as Azure Kubernetes Service or Azure Container Apps, which are more complex) and maybe even use Azure managed services for PostgreSQL and Redis.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f79f40114d74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/simple-mastodon-node-deployment-on-azure-f79f40114d74">Simple Mastodon Node Deployment on Azure</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easily Terraforming & Interacting with an Azure Confidential Ledger]]></title>
            <link>https://medium.com/microsoft/easily-terraforming-interacting-with-an-azure-confidential-ledger-374c75a582b?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/374c75a582b</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 14:58:11 GMT</pubDate>
            <atom:updated>2024-07-22T14:10:42.681Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62GtIyxZ2JH81WqyUBAtkg.png" /></figure><p>Azure Confidential Ledger, a managed and decentralized ledger for data entries backed by blockchain, enables maintaining data integrity by either using Azure Active Directory or client certificates to control access and modification permissions with tamper-proof storage and hardware-backed secure enclaves used in Azure confidential computing.</p><p>In this article we will be covering how to deploy an Azure Confidential Ledger using Terraform, which is surprisingly simple, and then create a simple script to interact with both the control plain and the data plain.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm provider to deploy the ledger and Python to interact with the ledger, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li><li>Python: installation guide is <a href="https://www.python.org/downloads/">here</a>.</li></ul><h4>Example Repository</h4><p>A complete Terraform script that creates a resource group and deploys an Azure Confidential Ledger, and a Python script that interacts with the deployed ledger is available in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/terraform-azure-confidential-ledger">GitHub - ItayPodhajcer/terraform-azure-confidential-ledger</a></p><h4>Deployment Script</h4><p>As mentioned earlier, it is surprisingly easy to Terraform an Azure Confidential Ledger, as it only requires creating a resource group and then an Azure Confidential Ledger resource, which in our case, we will grant the user who’s running the script admin permissions on the ledger.</p><p>The entire Terraform script should be similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23f9741fd4f58db10e4892bcf2f8e453/href">https://medium.com/media/23f9741fd4f58db10e4892bcf2f8e453/href</a></iframe><p>To run the script, make sure to run az login first, so Terraform can interact with Azure, then run terraform apply and after a few minutes, you should have a ledger ready for use.</p><h4>Using The Ledger</h4><p>To interact with the ledger, we will be writing a small Python script, that both access the management plain to retrieve ledger properties, and the data plain to write and read transactions.</p><p>We will start by creating a requirements.txt file for the required dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f2e5216d8a9f3e525cf04b14c3b4555/href">https://medium.com/media/1f2e5216d8a9f3e525cf04b14c3b4555/href</a></iframe><p>And then execute pip install -r requirements.txt to install those dependencies.</p><p>Next, we will create the script file, test-ledger.py, starting with the imports and variables with info on our deployed ledger:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad9d87e83c2474354def7a40d8c0f6ca/href">https://medium.com/media/ad9d87e83c2474354def7a40d8c0f6ca/href</a></iframe><p>Then create a ledger management client and retrieve some of the ledger’s properties (name, location, and ID):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf3d410f7f8bbda30f45ecab809088ae/href">https://medium.com/media/cf3d410f7f8bbda30f45ecab809088ae/href</a></iframe><p>Afterwards we create a ledger certificate client to retrieve the ledger’s identity certificate:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d6076e9db7f5f0d9075d14ef1837799/href">https://medium.com/media/7d6076e9db7f5f0d9075d14ef1837799/href</a></iframe><p>And lastly, create a ledger client to write and read data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4264401aac09f19a43c683d62403dc12/href">https://medium.com/media/4264401aac09f19a43c683d62403dc12/href</a></iframe><p>The only thing left now is to run the script using python .\test-ledger.py and you should see the info printed out by the script and the certificate file downloaded locally.</p><h4>Conclusion</h4><p>Although, for simplicity, the above script only associated a single user to the ledger, in a real-world scenario this might have multiple different associations of both users and service accounts, using either Azure Active Directory identities and/or client certificates to control who can access the ledger and with what permissions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=374c75a582b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/easily-terraforming-interacting-with-an-azure-confidential-ledger-374c75a582b">Easily Terraforming &amp; Interacting with an Azure Confidential Ledger</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up ConsenSys's Quorum Key Manager on Azure]]></title>
            <link>https://medium.com/microsoft/setting-up-consensyss-quorum-key-manager-on-azure-7929c53ab1ff?source=rss-7c3a8d08bc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/7929c53ab1ff</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Itay Podhajcer]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 16:51:59 GMT</pubDate>
            <atom:updated>2024-07-22T14:10:19.167Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOsiqSvY81S56BCuvol8xw.png" /></figure><p>A while back I did an article on how to <a href="https://medium.com/microsoftazure/easily-terraforming-an-ethsigner-with-an-azure-key-vault-hsm-based-key-110e25dcc588">deploy EthSigner on Azure</a>. Since then, ConsenSys was hard at work building a solution that’s based on the experience gained from developing EthSigner (and other products), which at its core, provides the same functionality, but with many more advanced features (such as enterprise-grade security and consolidated account and key management), and it’s called Quorum Key Manager (QKM).</p><p>In this article we will be covering the infrastructure and resources needed to deploy the QKM which include a PostgreSQL database, a file share for configuration files, a key vault and a mechanism for running the QKM container both for the migration process and the main service process.</p><h4>Prerequisites</h4><p>Will be using Terraform and its azurerm provider, so we will be needing the following installed on our workstation:</p><ul><li>Terraform: installation guide is <a href="https://learn.hashicorp.com/terraform/getting-started/install.html">here</a>.</li><li>Azure CLI: installation guide is <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">here</a>.</li></ul><h4>Example Repository</h4><p>A complete example Terraform script, which creates a private network, an Azure Database for PostgreSQL, an Azure Key Vault, an Azure Files share, a managed identity and runs QKM’s containers on Azure Container Apps, is available in the following GitHub repository:</p><p><a href="https://github.com/ItayPodhajcer/quorum-key-manager-azure">GitHub - ItayPodhajcer/quorum-key-manager-azure</a></p><h4>The script</h4><p>For brevity, I will only cover the areas of the Terraform script that are unique to the deployment of QKM, such as generating and uploading the configuration files, configuring the Azure Containers App environment, and running the containers.</p><p>First thing, we will create three configuration files for QKM, which include nodes configuration, vaults configuration, stores configuration:</p><ul><li>Nodes configuration file, which has a template variable for the node URL:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bea41e28fa9512b9462af40c5208a8a1/href">https://medium.com/media/bea41e28fa9512b9462af40c5208a8a1/href</a></iframe><ul><li>Vaults configuration file, which has template variables for the vault name, azure tenant ID, client ID and client secret (see the managed identity module in the example mentioned above for details on how to generate those credentials):</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71e15510a4b61c27835b0c52fcb6acf9/href">https://medium.com/media/71e15510a4b61c27835b0c52fcb6acf9/href</a></iframe><ul><li>And the stores configuration file, which is has no dynamic content, but does rely on the name of the value defined in the vaults configuration file:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/362cd8a522a6ea52fb209744a08fe208/href">https://medium.com/media/362cd8a522a6ea52fb209744a08fe208/href</a></iframe><p>Next, we need to upload those configuration files to an Azure Files share, which will be later mounted to our containers. To do that we will use the azurerm_storage_share_file resource, but because at the moment it only supports passing paths of files located in the local file system, we will need to create them (after the templates where populated with values, which some are sensitive) using local_file and then later delete them (because we don’t to keep any files with sensitive information lying around) using a little trick with the null_resource resource:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22f394106eaba9817f4f4e7257ee2674/href">https://medium.com/media/22f394106eaba9817f4f4e7257ee2674/href</a></iframe><p>The creation of the virtual network, database and key vault won’t be discussed here, as they have no special treatment for this deployment, and are included in the example mentioned at the beginning of the article, so we will move to the creation of the Azure Container Apps environment.</p><p>At the writing of this article, there is no dedicated Terraform configuration element for creating any of the Azure Container Apps related resources, so we’ll be using the azapi_resource from the azure/azapi provider.</p><p>Note that as we require to mount the Azure File share to our containers, we need to define a storage in the environment, so the complete environment and storage definitions should be like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac1bb818eb974ec87bfc4b874a348083/href">https://medium.com/media/ac1bb818eb974ec87bfc4b874a348083/href</a></iframe><p>And lastly define the containers, using an initContainers section for running the QKM container with migrations command (so it runs before the main QKM container is started) and the containers section for the main QKM service container (note that the volume is pointing to the name of the storage defined in the previous step):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8f0c0de0510127c956f31f72604b25e/href">https://medium.com/media/a8f0c0de0510127c956f31f72604b25e/href</a></iframe><p>Last part is to run terraform apply and wait for the script to complete before testing the QKM’s external endpoint.</p><h4>Testing The Deployment</h4><p>Because the application is defined with an HTTP ingress, the container will be exposed at 443 (standard HTTPS) and not the internal 8081, due to Azure Container Apps automatically mapping HTTP ingresses in that manner for us, so you only need the ingress’s FQDN to do a simple HTTPS test.</p><h4>Conclusion</h4><p>Exposing the Quorum Key Manager to the internet in this article is only done for demonstration purposes. In a real-world production environment, it will probably be only available to internal systems, or even just to the specific services that require it to function. Note that the Quorum Key Manager doesn’t have any nonce management logic, which is usually required in systems with lots of concurrent connections trying send transactions to the blockchain, so for that it will need to be combined with something like ConsenSys’s Codefi Orchestrate.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7929c53ab1ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft/setting-up-consensyss-quorum-key-manager-on-azure-7929c53ab1ff">Setting up ConsenSys&#39;s Quorum Key Manager on Azure</a> was originally published in <a href="https://medium.com/microsoft">Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>