Taking GPT-4o-Mini For A Quick Test Drive on Azure AI
Nothing like driving all around the Copilot stack ...

Taking GPT-4o-Mini For A Quick Test Drive on Azure AI

This is a quick introductory guide to folks who are new to using AI models in an enterprise setting, and they juuuuuust can't wait to get started! Scroll to the bottom of this article to understand why I wrote it in the first place. If you bump into any problems along the way, just ask me in the comments!

Pick a region

The first thing you want to ask yourself is the region you want your model(s) to operate in. Why should you care about that? Well, as a dev you're thinking about latency and as a big business you're going to have strict data/processing residency requirements. You want to your Azure Resource to correspond to the region in which you've got access to the Azure OpenAI model.

Doesn't it remind you of the opener in "What is the Matrix?"

Pick a region with a global-standard option

There's a category of regions that give you "global-standard" as an option that can be found here. It's the best option for folks who want to get running quickest without thinking too hard. Bonus: When you think hard, you get the benefit of full control!

Make a hub

In Azure AI Studio, your hub is like a 'team' or 'organization' or 'workspace' like you'll find on most enterprise software out there that's been designed for complex organizations. Why's it called a "hub"? Well, that's because of the genesis of Azure AI and a long hubby-ness that's existed in this neighborhood. Once you've got a hub, everything will be fine. Make the hub once and you're good to go.

Make a hub — note that I chose East US based on my research. Be sure to do your own research

When you set this all in motion, note that it will create two resources you may not recognize: 1/ a key vault, and 2/ blob storage. If you're paranoid of getting enormous hidden charges when playing in the cloud, no worries as those are a tiny tax on your hub and immaterial. I play with Azure AI all the time on my own dollars to make sure I'm giving indie folks decent advice!

Pro-tip: If you add a new Azure AI Search into your Hub, you're going to end up with an enterprise-class hybrid vector database instance that will cost you some $$ so be sure to choose "Skip connecting" if you're running on your own wallet/purse right now. It's super powerful so definitely connect to it when you're ready and properly funded!

Okay, you've got a hub. Aces! Let's check out your resources in Connections. You've got access to Azure OpenAI and you have access to Azure AI Services. Our attention is on Azure OpenAI, but keep in mind you can do all kinds of cool things with AI Services any time you like!

"AI Services" means task-specific models that you are more deterministic than their LLM counterparts for a narrow set of use cases.

Setting up gpt-4o-mini

Since I want to use the latest in coolness factor by using gpt-4o-mini, I go to the Model Catalog (it's in the left nav) and then in the catalog I select gpt-4o-mini, and then ... deploy. PSA: Deploy is a fancy nerd word for "create" :-).

Global Standard deployment makes it easy-peasier. Just take my word for it.

With great power comes great responsibility

If you feel this new kind of AI feels a bit risky, then you should check out my course on The Art and Craft of Business Resilience become more risk-versed. Being knowledgeable about something you don't understand is how you tackle being risk-averse. Right?


If you're wading into the AI space and feeling a little afraid, this course

With Azure, you're in luck on the risk-management side because Azure OpenAI is designed to keep your AI pipeline safe by monitoring what goes in and out of your AI model processing. In fact, Azure OpenAI has safety turned on by default! And it's already V2-d!


The "Monitoring & safety" part of your deployment is a sign that Azure's taking care of you as best as we can! When you're just starting out, safety is a good thing!

Feeling safe? Then let's keep going!

Chat to your heart's content

And just like that with your deployment, you've got gpt-4o-mini in your corner. And you can easily test it out in the corresponding playground for chat.

The playground is unusually powerful. I like to just chat a bit and then switch to my own coding world.

Let's switch to code

If you click on "</> View code" in the playground, you can choose your favorite language to get going with your new key and endpoint. Keep in mind that keys aren't a good thing in general, and it's best to use Azure to authenticate to go fully keyless. That said, we're just getting started here so let's do it the simplest way possible.

Because I'm running with gpt-4o, I've been given an example that lets me analyze an image stored locally on my computer.

Let's assume you have the latest dotnet (.NET) installed on your computer. If so, then go to terminal and make a new console project.

% mkdir tmp
% cd tmp
% dotnet new console -o .        

The "console -o" option puts everything inside the directory you're sitting in. You should get the following:

(base) ?  tmp dotnet new console -o .
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /Users/maeda/dev/tmp/tmp.csproj:
  Determining projects to restore...
  Restored /Users/maeda/dev/tmp/tmp.csproj (in 28 ms).
Restore succeeded.
You should be rewarded with something happy like this.

Ready to code?

I simplified the program so that it doesn't require Newtonsoft.json and instead uses the default newer built-in json utilities of .NET. Use this version if you like as your new Program.cs:

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    private const string API_KEY = "..."; // Get your key from the code dialog
    private const string IMAGE_PATH = "maedaold.jpeg"; // Set your image path here
    private const string QUESTION = "Describe the image as if it were to be recreated by an AI image prompt."; // Set your question here

    private const string ENDPOINT = <this gets filled in automatically in the original code>;

    static async Task Main()
    {
        var encodedImage = Convert.ToBase64String(File.ReadAllBytes(IMAGE_PATH));
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("api-key", API_KEY);
            var payload = new
            {
                messages = new object[]
                {
                    new
                    {
                        role = "system",
                        content = new object[]
                        {
                            new
                            {
                                type = "text",
                                text = "You are an AI assistant that helps people find information."
                            }
                        }
                    },
                    new
                    {
                        role = "user",
                        content = new object[]
                        {
                            new
                            {
                                type = "image_url",
                                image_url = new
                                {
                                    url = $"data:image/jpeg;base64,{encodedImage}"
                                }
                            },
                            new
                            {
                                type = "text",
                                text = QUESTION
                            }
                        }
                    }
                },
                temperature = 0.7,
                top_p = 0.95,
                max_tokens = 800,
                stream = false
            };

            var jsonPayload = JsonSerializer.Serialize(payload);
            var response = await httpClient.PostAsync(ENDPOINT, new StringContent(jsonPayload, Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                var responseData = JsonSerializer.Deserialize<dynamic>(await response.Content.ReadAsStringAsync());
                Console.WriteLine(responseData);
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}, {response.ReasonPhrase}");
            }
        }
    }
}        

Here are the granular steps you need to take with this code in hand. Note that I used .NET because I love it so much, and yes it all works in Python too so don't worry!

  1. After you've installed .NET and made the new project in your tmp directory, type "dotnet run" and you should see some text printed out in your console. Hooray!
  2. Use the code above as your new "Program.cs" or you can use the code that's in the existing dialog box instead with the other Json package.
  3. Grab the API key by copying it from the top of the code dialog into API_KEY. Be sure to copy the ENDPOINT parameter that's in the code body. Pop it into the code above.
  4. File copy an image to your local "tmp" folder. I used an old image I found of myself online from maybe a decade ago that I entitled "maedaold.jpeg." Modify IMAGE_PATH accordingly.
  5. Change the question to something that pertains to the image. I used "Describe the image as if it were to be recreated by an AI image prompt." This goes in QUESTION.

Let's run!

Go ahead and run your AI-powered program!

% dotnet run        

And you will see json output that provides the analysis of the image. I got:

% dotnet run
{"choices":[{"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"protected_material_code":{"filtered":false,"detected":false},"protected_material_text":{"filtered":false,"detected":false},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"finish_reason":"stop","index":0,"logprobs":null,"message":{"content":"The image features a young person standing outdoors in a city setting during a cool season. The background showcases a mix of modern and historic architecture, with red brick buildings and a tree-lined street. The subject is wearing a dark, textured jacket and a colorful striped scarf that adds a pop of color to the scene. The lighting is soft, suggesting either early morning or late afternoon, casting a warm glow on the surroundings. The atmosphere feels calm and urban, highlighting the blend of nature and city life.","role":"assistant"}}],"created":1725764437,"id":"chatcmpl-...","model":"gpt-4o-mini","object":"chat.completion","prompt_filter_results":[{"prompt_index":0,"content_filter_result":{"jailbreak":{"filtered":false,"detected":false},"custom_blocklists":{"filtered":false,"details":[]}}},{"prompt_index":1,"content_filter_result":{"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"},"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"custom_blocklists":{"filtered":false,"details":[]}}}],"system_fingerprint":"....","usage":{"completion_tokens":99,"prompt_tokens":8569,"total_tokens":8668}}        

So let's look at the content:

The image features a young person standing outdoors in a city setting during a cool season. The background showcases a mix of modern and historic architecture, with red brick buildings and a tree-lined street. The subject is wearing a dark, textured jacket and a colorful striped scarf that adds a pop of color to the scene. The lighting is soft, suggesting either early morning or late afternoon, casting a warm glow on the surroundings. The atmosphere feels calm and urban, highlighting the blend of nature and city life.

How kind! It says I was young back then. Well ... I guess I felt that way. But I wasn't that young. Anyways, that's quite flattering of you, gpt-4o-mini (wink).

Take the next step

Now that you know how to deploy an instance of gpt-4o-mini in Azure AI Studio, you might want to take a leap of faith and jump into the world of Semantic Kernel. Watch this Cozy AI Kitchen episode with Stephen Toub to get inspired. I certainly did!

Why did I write this article?

I used to be the Semantic Kernel guy, and about a couple of months ago I jumped deeper into the Copilot Stack from the AI Orchestration layer down into the Models and Infrastructure layer.


The Copilot stack concept

I'm learning how to use everything in these lower layers now, and wanted to share my learnings with the rest of the world. Azure AI rocks! —JM

Arslan Zia

IT Officer | Mobilink Microfinance Bank | Web Developer | WordPress Developer | Ex Database Administrator

2 个月

Great to see John Maeda showcasing this hands-on approach! ?? A quick 4o mini-test drive sounds like a fantastic way to dive into the experience. ?? Embracing practical methods like this can really enhance our understanding and skills. Thanks for sharing!

回复
Noah Paessel

Software engineering leader | Researcher | Educator

2 个月

These are great step-by-step lessons John. Thank you!

John Maeda

AI @ MSFT / Laws of Simplicity + How To Speak Machine / LinkedIn Top US Influencer

2 个月

In a follow-up article I'll be returning to a reboot of driving #SemanticKernel agents. There's a NEW post on this by AI Chef ???? Marco Casalaina Courtney Brewer https://techcommunity.microsoft.com/t5/ai-ai-platform-blog/the-future-of-ai-exploring-multi-agent-ai-systems/ba-p/4226593

Miles Welch

CEO @ North Star Training Solutions | 1000+ CEOs/Execs/Directors coached | I build your leadership bench so you can focus on building your business.

2 个月

Picking the right region is key. It's like finding a cozy cafe spot—gotta blend comfort and tech. What else are you curious about?

要查看或添加评论,请登录