<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:webfeeds="http://webfeeds.org/rss/1.0" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>AI on Mart&#39;s blog</title>
    <link>https://blog.martdegraaf.nl/tags/ai/</link>
    <description>Recent content in AI on Mart&#39;s blog</description>
    <webfeeds:analytics id="G-ZFQGR29JJQ" engine="GoogleAnalytics"/>
    <webfeeds:accentColor>0078D3</webfeeds:accentColor>
    <webfeeds:related layout="card" target="browser"/>
    <webfeeds:icon>https://gravatar.com/userimage/91624600/fb51d6d9172e5043a1e59d59f3f84e62.jpeg?v=1666815123000&amp;size=200</webfeeds:icon>
    <generator>Hugo -- 0.166.0</generator>
    <language>en-us</language>
    <managingEditor>blog@martdegraaf.nl (Mart de Graaf)</managingEditor>
    <webMaster>blog@martdegraaf.nl (Mart de Graaf)</webMaster>
    <copyright>Mart de Graaf</copyright>
    <lastBuildDate>Wed, 30 Oct 2024 00:46:22 +0100</lastBuildDate>
    <atom:link href="https://blog.martdegraaf.nl/tags/ai/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Make Github Copilot a Habit</title>
      <link>https://blog.martdegraaf.nl/posts/make-github-copilot-a-habit/</link>
      <pubDate>Tue, 29 Oct 2024 21:42:43 +0200</pubDate><author>blog@martdegraaf.nl (Mart de Graaf)</author>
      <guid>https://blog.martdegraaf.nl/posts/make-github-copilot-a-habit/</guid>
      <description><![CDATA[Now with the capabilities of AI, we code on steroids. Let&rsquo;s make it a habit to use it the right way.]]></description><content:encoded><![CDATA[<p>GitHub Copilot has made his way into your daily life. For many developers habits are made, but please use the feature that suits your case best. Don&rsquo;t use the Chat or completion as golden hammer for every problem.</p>
<p>The goals in this post are to make you aware of the possibilities and to make you think about how you should look at tools such as GitHub Copilot.</p>
<h2 id="github-copilot">GitHub Copilot</h2>
<p>GitHub Copilot is super cool. Lets see those features!</p>
<h3 id="chat">Chat</h3>
<p>The chat feature in VS or VS Code. It&rsquo;s ChatPGT with knowledge of your code. It&rsquo;s handy to get a quick answer to a question. It&rsquo;s not a golden hammer for every problem. What is the difference when u ask it to do something and you are still copy pasting code?</p>
<p>The chat window can be a big part of your screen, be aware of that.</p>
<h3 id="code-completions">Code completions</h3>
<p>Use a comment to get a completion. When entering the code will appear.

<img loading="lazy" src="completion.png" alt="alt text"  />
</p>
<p>You should know by the way that you can also use only the beginning of the suggestion.</p>
<p>Use <code>Ctrl + right arrow</code> to accept one word at the time of the completion.</p>
<h3 id="inline-chat">Inline chat</h3>
<p>For example using <code>Ctrl + i</code> in VS Code. It will give you a completion for the line you are on.</p>
<div class="codecontainer" hi="mart"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-txt" data-lang="txt"><span class="line"><span class="cl">/tests
</span></span><span class="line"><span class="cl">/fix
</span></span><span class="line"><span class="cl">/explain
</span></span><span class="line"><span class="cl">/docs
</span></span><span class="line"><span class="cl">/help
</span></span><span class="line"><span class="cl">/optimize
</span></span><span class="line"><span class="cl">/generate</span></span></code></pre></td></tr></table>
</div>
</div></div><h4 id="chat-pallete">Chat pallete</h4>
<p>Use <code>Ctrl + Shift + I</code> in VS Code to open the chat in a pallete. This is handy to get a quick chat while keeping focus on your code.</p>
<p>To close the chat pallete, use <code>Esc</code>.</p>
<h3 id="commit-message-generation">Commit message generation</h3>
<p>use the Stars to generate a commit message. It&rsquo;s a good way to save time thinking of a commit message.

<img loading="lazy" src="commit-generation.png" alt="Generate a commit message using GitHub Copilot"  />
</p>
<h3 id="reference-a-filemethod-in-a-prompt">Reference a file/method in a prompt</h3>
<p>Use the <code>#</code> prefix to reference a file in your prompt.</p>
<div class="codecontainer" hi="mart"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-txt" data-lang="txt"><span class="line"><span class="cl">/fix This method should return a #Address.cs</span></span></code></pre></td></tr></table>
</div>
</div></div><h3 id="reference-a-scope">Reference a scope</h3>
<p>Use the <code>@</code> prefix to reference a file in your prompt.</p>
<p>
<img loading="lazy" src="scopes.png" alt="GitHub Copilot scopes"  />
</p>
<h3 id="prompting">Prompting</h3>
<p>Your prompt is is key for good results. You should be clear in what you want to achieve.</p>
<p>If your first prompt is not giving you the results you want, try to be more specific.</p>
<h2 id="code-worthy">Code worthy</h2>
<p>Let me give you a statement:</p>
<blockquote>
<p>Code is less valuable if it&rsquo;s generated by a tool.</p>
</blockquote>
<p>That is a bold statement. I think it&rsquo;s true. The engineers should be aware of the problem and the solution. The tool can help you with the implementation.</p>
<h3 id="engineers-are-puppeteers">Engineers are puppeteers</h3>
<p>The software engineers of the next years are going to tell the story using their puppets. The management will see output of the tooling and think they can do without the engineers. The technology is not there yet, but i think the engineers without the use of AI tooling will be pruned, just like variants in Loki, the Marvel series.</p>
<h2 id="conclusion-and-discussion">Conclusion and discussion</h2>
<p>I Like to have focus and not be distracted by the chat window. I think you should use the feature that suits your case best. For generating tests for example i think its best to do it inline, and accept the completion afterwards instead of copy pasting parts of the code.</p>
<p>I also think you should be reading release notes of GitHub Copilot. It&rsquo;s a tool that is constantly evolving. It&rsquo;s good to know what the changes are.</p>
<h2 id="references">References</h2>
<ul>
<li><a href="https://learn.microsoft.com/en-us/visualstudio/ide/copilot-chat-context?view=vs-2022" target="_blank" rel="noopener">https://learn.microsoft.com/en-us/visualstudio/ide/copilot-chat-context?view=vs-2022</a></li>
</ul>
]]></content:encoded>
      <category>habit</category>
      <category>github copilot</category>
      <category>ai</category>
      <category>tools</category>
    </item>
    <item>
      <title>Getting started with Azure OpenAI</title>
      <link>https://blog.martdegraaf.nl/posts/getting-started-with-azure-openai/</link>
      <pubDate>Thu, 26 Oct 2023 07:00:00 +0200</pubDate><author>blog@martdegraaf.nl (Mart de Graaf)</author>
      <guid>https://blog.martdegraaf.nl/posts/getting-started-with-azure-openai/</guid>
      <description><![CDATA[AI is happening. How can you make sure your organization benefits from AI?]]></description>
      <enclosure url="https://blog.martdegraaf.nl/posts/getting-started-with-azure-openai/cover.webp" type="image/webp" />
      <media:content url="https://blog.martdegraaf.nl/posts/getting-started-with-azure-openai/cover.webp" medium="image" type="image/webp">
        <media:title>AI</media:title>
      </media:content><content:encoded><![CDATA[<img src="https://blog.martdegraaf.nl/posts/getting-started-with-azure-openai/cover.webp" alt="AI" /><br/><br/><h2 id="introduction">Introduction</h2>
<p>Artificial intelligence is hip and happening. Everyone can use ChatGPT right now easily. But there are some worries about where your chats will go. Is it safe? Is the model trained by my conversations?</p>
<p>As a consultant, it is important to know the possibilities and the tradeoffs of using AI.
In this article, we discuss the OpenAI services in Azure. The Azure OpenAI services promise that the data stays in your environment in the cloud. This is a minimal requirement for many companies. We will show how to use the playground, the API, and the Azure Cognitive Search integration.</p>
<h2 id="creating-your-openai-resource">Creating your OpenAI resource</h2>
<p>Before you can start using Azure OpenAI you will need to be accepted by Microsoft. You need to apply for the &lsquo;Azure OpenAI Service&rsquo; preview. You can do this by following the procedure to create this resource, a link to the application form is provided.</p>
<ol>
<li>Create a new resource in Azure.</li>
<li>Search for OpenAI</li>
<li>Select the OpenAI resource</li>
<li>Create the resource</li>
</ol>
<p>
  <figure>
    <img loading="lazy" src="marketplace-openai.png#center" alt="Azure Marketplace - OpenAI"  title="Azure Marketplace - OpenAI"  />
    <figcaption style="text-align: center;">Azure Marketplace - OpenAI</figcaption>
  </figure>
</p>
<h2 id="using-openai-studio">Using OpenAI studio</h2>
<p>After creating the resource you can go to the OpenAI studio.</p>
<p>
  <figure>
    <img loading="lazy" src="openai_studio.png#center" alt="OpenAI Studio"  title="OpenAI Studio"  />
    <figcaption style="text-align: center;">OpenAI Studio</figcaption>
  </figure>
</p>
<p>This is a web-based tool the &lsquo;OpenAI Playground&rsquo; that allows you to test the models and see the results. You can also create your models and train them.</p>
<h3 id="create-a-new-model">Create a new Model</h3>
<p>You can create a new model by clicking the &lsquo;Create Model&rsquo; button. You can select the model you want to use. The default is the GPT-3 turbo model. I did my testing with the GPT-35 turbo Model. From the model, you need to make a deployment. This will take a few minutes. After the deployment is done you can start using the model. The DaVinci model can be a better fit for autocompletion and text generation. Dall-E is only available in East US.</p>
<h3 id="chat-playground">Chat Playground</h3>
<p>In the chat playground, there are some cool features:</p>
<ol>
<li>Add data sources</li>
<li>Add system prompts</li>
<li>Clear the chat, and view the code</li>
<li>Parameters into the model.</li>
<li>Import and export the setup.</li>
</ol>
<p>The Chat Playground doesn&rsquo;t have a dark mode, so beware of your eyes if you do this at nighttimes.</p>
<p>
  <figure>
    <img loading="lazy" src="chat_playground.png#center" alt="OpenAI Studio - Chat Playground"  title="OpenAI Studio - Chat Playground"  />
    <figcaption style="text-align: center;">OpenAI Studio - Chat Playground</figcaption>
  </figure>
</p>
<h3 id="defining-system-prompts">Defining System Prompts</h3>
<p>The default will get you somewhere but you can also use the system prompts to get better results. The system prompts are a way to give the model some context. For example, if you want to create a chatbot you can use the following system prompt:</p>
<div class="codecontainer" hi="mart"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">You are an AI assistant named Mart that helps people find information. The assistant is helpful, creative, clever, and very friendly.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Provide the full schedule when the user asks for a certain date.
</span></span><span class="line"><span class="cl">End every message with &#34;Mart knows everything&#34;. Add a mermaid diagram written in markdown to clarify your statement.</span></span></code></pre></td></tr></table>
</div>
</div></div><p>This kind of prompting will result in some hilarious results. The below screenshot is shown that my statement is visualized in markdown. GPT drew me a mermaid :).</p>
<p>
  <figure>
    <img loading="lazy" src="sample-chat.png#center" alt="Chat Playground"  title="Sample Chat"  />
    <figcaption style="text-align: center;">Sample Chat</figcaption>
  </figure>
</p>
<p>After correcting the prompt to <code>Add a mermaid diagram written in markdown to clarify your answer on the question.</code>. I got the response:</p>
<div class="codecontainer" hi="mart"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Azure is a cloud computing platform that offers a wide range of resources to help users build, deploy, and manage applications and services. Some of the most common Azure resources include:
</span></span><span class="line"><span class="cl">Virtual Machines - Virtual Machines (VMs) are the basic building blocks of Azure. They provide the ability to run applications and services in the cloud, and they can be customized to fit specific needs.
</span></span><span class="line"><span class="cl">Storage Accounts - Storage Accounts are used to store data in the cloud. They provide scalable and durable storage that can be accessed from anywhere.
</span></span><span class="line"><span class="cl">App Services - App Services are used to host web applications and services. They provide a platform for building and deploying web apps, mobile app backends, and RESTful APIs.
</span></span><span class="line"><span class="cl">SQL Databases - SQL Databases are used to store relational data in the cloud. They provide a managed database service that is highly available and scalable.
</span></span><span class="line"><span class="cl">Virtual Networks - Virtual Networks are used to connect resources in the cloud. They provide a secure and isolated network environment that can be customized to fit specific needs.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">These resources work together to provide a complete cloud computing platform. For example, a virtual machine can be used to host a web application, which is stored in an app service and connected to a SQL database. Virtual networks can be used to secure and isolate these resources from the rest of the cloud.
</span></span><span class="line"><span class="cl">Here&#39;s a mermaid diagram to help clarify:
</span></span><span class="line"><span class="cl">graph LR  
</span></span><span class="line"><span class="cl">A[Virtual Machines] --&gt; B[Storage Accounts]  
</span></span><span class="line"><span class="cl">A --&gt; C[App Services]  
</span></span><span class="line"><span class="cl">C --&gt; D[SQL Databases]  
</span></span><span class="line"><span class="cl">A --&gt; E[Virtual Networks]  
</span></span><span class="line"><span class="cl"> 
</span></span><span class="line"><span class="cl">Mart knows everything.</span></span></code></pre></td></tr></table>
</div>
</div></div><p>When putting it in a mermaid renderer I got the following result:</p>
<pre class="mermaid">graph LR  
A[Virtual Machines] --> B[Storage Accounts]  
A --> C[App Services]  
C --> D[SQL Databases]  
A --> E[Virtual Networks]  
</pre>

<p>This was more what I expected. Only the mermaid diagram connections don&rsquo;t make sense. This is a limitation, it can&rsquo;t model the connections well enough. You should check the output and test when integrating these features. ChatGPT is a statistical model, so it will give you a result that is the best fit based on its data. That does not imply everything is correct. You should always be critical at the output.</p>
<h2 id="properties">Properties</h2>
<p>In the parameters tab, you can play with some settings. You will need to know about those to get the best results.</p>
<h3 id="max-response">Max response</h3>
<p>The <code>Max response</code> setting sets a limit on tokens that can be used per response. I found better results with complex prompts with the Max response just above 2000.</p>
<h3 id="temperature">Temperature</h3>
<p>The temperature is a setting that controls the randomness of the model. The higher the temperature the more random the results will be. For more theoretical information see: <a href="https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/" target="_blank" rel="noopener">https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/</a>.</p>
<p>The <code>Top P</code> setting works like the temperature setting, 0 is low probability and 1 is high probability. The higher the value, the more diverse probabilities will be allowed.</p>
<h2 id="documenting-code-to-using-openai">Documenting code to using OpenAI</h2>
<div class="codecontainer" hi="mart"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">create a mermaid diagram for the flow that is done in this c# code   
</span></span><span class="line"><span class="cl">  
</span></span><span class="line"><span class="cl">public static voidFibonacci_Iterative(int len)    
</span></span><span class="line"><span class="cl">{    
</span></span><span class="line"><span class="cl">    int a = 0, b = 1, c = 0;    
</span></span><span class="line"><span class="cl">    Console.Write(&#34;{0} {1}&#34;, a,b);    
</span></span><span class="line"><span class="cl">    for (int i = 2; i &lt; len; i++)    
</span></span><span class="line"><span class="cl">    {    
</span></span><span class="line"><span class="cl">        c= a + b;    
</span></span><span class="line"><span class="cl">        Console.Write(&#34; {0}&#34;, c);    
</span></span><span class="line"><span class="cl">        a= b;    
</span></span><span class="line"><span class="cl">        b= c;    
</span></span><span class="line"><span class="cl">    }    
</span></span><span class="line"><span class="cl">}  </span></span></code></pre></td></tr></table>
</div>
</div></div><p>This prompt resulted in the code being explained in a good flowchart. This is a great way to document your code.</p>
<div class="codecontainer" hi="mart"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">To create a mermaid diagram for the flow in the given C# code, you can follow these steps:
</span></span><span class="line"><span class="cl">Start by creating a sequenceDiagram block in your mermaid code.
</span></span><span class="line"><span class="cl">Add a participant for the Fibonacci_Iterative method.
</span></span><span class="line"><span class="cl">Add a participant for the Console class.
</span></span><span class="line"><span class="cl">Add a note to the Fibonacci_Iterative participant to indicate that it takes an integer parameter len.
</span></span><span class="line"><span class="cl">Add a note to the Console participant to indicate that it writes to the console.
</span></span><span class="line"><span class="cl">Add a loop block to represent the for loop in the code.
</span></span><span class="line"><span class="cl">Inside the loop block, add a note to indicate that c is the sum of a and b.
</span></span><span class="line"><span class="cl">Inside the loop block, add a note to indicate that a is assigned the value of b.
</span></span><span class="line"><span class="cl">Inside the loop block, add a note to indicate that b is assigned the value of c.
</span></span><span class="line"><span class="cl">Connect the Fibonacci_Iterative participant to the Console participant with an arrow to indicate that it writes to the console.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Here&#39;s an example of what the mermaid code could look like:</span></span></code></pre></td></tr></table>
</div>
</div></div><pre class="mermaid">sequenceDiagram  
    participant Fibonacci_Iterative  
    participant Console  
  
    Note over Fibonacci_Iterative: Takes integer parameter len  
    Note over Console: Writes to console  
  
    loop for i=2 to len  
        Note over Fibonacci_Iterative: c = a + b  
        Note over Fibonacci_Iterative: a = b  
        Note over Fibonacci_Iterative: b = c  
    end  
  
    Fibonacci_Iterative->>Console: Writes to console  
 
</pre>

<h2 id="adding-your-data-using-cognitive-search">Adding your data using Cognitive Search</h2>
<p>You can also add your data to the model. This can be done by using the Cognitive Search feature. You can upload your data and use it to train the model. You can also use the data to create completions.</p>
<p>In the playground click &lsquo;add your data&rsquo; and click &lsquo;+ add Data source&rsquo;.</p>
<p>
  <figure>
    <img loading="lazy" src="chat_playground_add_data_source.png#center" alt="Chat Playground - add data source"  title="Chat playground - Add Data Source"  />
    <figcaption style="text-align: center;">Chat playground - Add Data Source</figcaption>
  </figure>
</p>
<h3 id="structure">Structure</h3>
<p>Whatever you choose in the data source dropdown you will always end up with a Blob storage containing some blob files with a Cognitive Search resource. Make sure when creating the cognitive search resource you select the same region as the OpenAI resource and it has to be at least basic.</p>
<pre class="mermaid">flowchart LR
OpenAI --> |uses| CognitiveSearch
CognitiveSearch -->| indexes| BlobStorage
</pre>

<h3 id="steps-to-add-data">Steps to add data</h3>
<ol>
<li>Create a Blob storage account and put files in a container. I recommend using the Azure Storage Explorer. Upload some PDF files you want to be able to search for. Or use HTML pages from your public website as feed for your data source.</li>
<li>Create a Cognitive Search resource. This has to be at least Basic, performance will be better on higher sku, but costs will be higher too.</li>
<li>Create a data source in the Playground.
<ul>
<li>Select &lsquo;Azure Blob Storage&rsquo;.</li>
<li>Select the Blob storage resource you created.</li>
<li>Select the container you created or want to use.</li>
<li>Select the Cognitive Search resource you created.</li>
<li>Enter an index name</li>
<li>Check the box that you know about the pricing. And continue.</li>
<li>Click Save and Close on the Review and Finish page.</li>
</ul>
</li>
<li>Wait for the Indexer to finish. You can watch the progress in the Cognitive Search resource. Navigate to the Indexers and Indexes tab. Indexers run to create the index.</li>
</ol>
<p>
  <figure>
    <img loading="lazy" src="cognitive_search_indexers.png#center" alt="Cognitive Search - Indexers"  title="Cognitive Search - Indexers"  />
    <figcaption style="text-align: center;">Cognitive Search - Indexers</figcaption>
  </figure>
</p>
<h3 id="chatting-to-your-documents">Chatting to your documents</h3>
<p>Now that the indexer is ready and the index is loaded, let&rsquo;s chat to documents. The blob storage is fed with a slide deck of my Git presentation as PDF to the blob storage. Let&rsquo;s ask GPT about Git.</p>
<p>
  <figure>
    <img loading="lazy" src="playground_chat_with_data_source_git.png#center" alt="Chatting with presentations"  title="Chatting with presentations"  />
    <figcaption style="text-align: center;">Chatting with presentations</figcaption>
  </figure>
</p>
<p>Please note that in the screenshot you can choose to limit responses specific to your data content. Sources will be shown in the response. This is a great way to get insights into your data.</p>
<h3 id="cost-management">Cost management</h3>
<p>The basic sku on Cognitive search is a pay-per-month model, which means you should delete the resource after you are done testing with it. The OpenAI resource is pay-per-use as is the storage account.</p>
<h2 id="deploy-it-to-an-app-service">Deploy it to an App Service</h2>
<p>So you have now seen some power or some stupidity of the OpenAI model. You can also deploy it to an App Service. This can be on a free sku, but make sure when using this that your Chat application will be open on {your-app-name}.azurewebsites.net. You will need to configure VNET integration if you are dealing with company information.</p>
<h3 id="resource-group-overview">Resource group overview</h3>
<p>As wrap up for all the resources we created during our testing. We can see the following resources in our resource group. I know you will be all testing if MartGPT is still online.</p>
<p>
  <figure>
    <img loading="lazy" src="resource_group_overview.png#center" alt="Resource group overview"  title="Resource group overview"  />
    <figcaption style="text-align: center;">Resource group overview</figcaption>
  </figure>
</p>
<h2 id="using-openai-api-services-through-c-sharp">Using OpenAI API services through C sharp</h2>
<p>The OpenAI API is a REST API that allows you to use the models in your applications. You can use the API to create completions and chat. Some real power is when we can use the OpenAI services through our code, where we can create our business scope.</p>
<h3 id="sample-case">Sample case</h3>
<p>Make sure you have <code>Include prerelease</code> enabled when searching for the NuGet package <code>Azure.AI.OpenAI</code>.</p>
<div class="codecontainer" hi="mart"><div class="code-name">Program.cs</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span><span class="lnt">46
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-csharp" data-lang="csharp"><span class="line"><span class="cl"><span class="c1">// Note: The Azure OpenAI client library for .NET is in preview.</span>
</span></span><span class="line"><span class="cl"><span class="c1">// Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5 </span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">using</span> <span class="nn">Azure</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="k">using</span> <span class="nn">Azure.AI.OpenAI</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">var</span> <span class="n">dieren</span> <span class="p">=</span> <span class="k">new</span><span class="p">[]</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="s">&#34;Penguins&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="s">&#34;Giraffes&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="s">&#34;Smurfen&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// more</span>
</span></span><span class="line"><span class="cl">    <span class="p">};</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">OpenAIClient</span> <span class="n">client</span> <span class="p">=</span> <span class="k">new</span> <span class="n">OpenAIClient</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">    <span class="k">new</span> <span class="n">Uri</span><span class="p">(</span><span class="s">&#34;https://martgpt-openai.openai.azure.com/&#34;</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">    <span class="k">new</span> <span class="n">AzureKeyCredential</span><span class="p">(</span><span class="s">&#34;HERE COMES YOUR API KEY&#34;</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// ### If streaming is not selected</span>
</span></span><span class="line"><span class="cl"><span class="k">foreach</span> <span class="p">(</span><span class="kt">var</span> <span class="n">dier</span> <span class="k">in</span> <span class="n">dieren</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">Response</span><span class="p">&lt;</span><span class="n">ChatCompletions</span><span class="p">&gt;</span> <span class="n">responseWithoutStream</span> <span class="p">=</span> <span class="k">await</span> <span class="n">client</span><span class="p">.</span><span class="n">GetChatCompletionsAsync</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">        <span class="s">&#34;MartGPT&#34;</span><span class="p">,</span> <span class="c1">//&lt;= This is the deployment name</span>
</span></span><span class="line"><span class="cl">        <span class="k">new</span> <span class="n">ChatCompletionsOptions</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">        <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="n">Messages</span> <span class="p">=</span>
</span></span><span class="line"><span class="cl">            <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="k">new</span> <span class="n">ChatMessage</span><span class="p">(</span><span class="n">ChatRole</span><span class="p">.</span><span class="n">User</span><span class="p">,</span> <span class="n">dier</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">            <span class="k">new</span> <span class="n">ChatMessage</span><span class="p">(</span><span class="n">ChatRole</span><span class="p">.</span><span class="n">User</span><span class="p">,</span> <span class="s">@&#34;Geef antwoord in JSON met categorie property van het type string met als waarde een van deze categorien:
</span></span></span><span class="line"><span class="cl"><span class="s">Landdieren
</span></span></span><span class="line"><span class="cl"><span class="s">Zeedieren
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">In welke categorie valt deze diersoort en geef een omschrijving met maximaal 5 woorden en geef ook de naam van het dier terug.&#34;</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">            <span class="p">},</span>
</span></span><span class="line"><span class="cl">            <span class="n">Temperature</span> <span class="p">=</span> <span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="m">1</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="n">MaxTokens</span> <span class="p">=</span> <span class="m">800</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="n">NucleusSamplingFactor</span> <span class="p">=</span> <span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="m">1</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="n">FrequencyPenalty</span> <span class="p">=</span> <span class="m">0</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="n">PresencePenalty</span> <span class="p">=</span> <span class="m">0</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="p">});</span>
</span></span><span class="line"><span class="cl">    <span class="n">ChatCompletions</span> <span class="n">completions</span> <span class="p">=</span> <span class="n">responseWithoutStream</span><span class="p">.</span><span class="n">Value</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="k">foreach</span> <span class="p">(</span><span class="kt">var</span> <span class="n">choice</span> <span class="k">in</span> <span class="n">completions</span><span class="p">.</span><span class="n">Choices</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">choice</span><span class="p">.</span><span class="n">Message</span><span class="p">.</span><span class="n">Content</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></td></tr></table>
</div>
</div></div><p>The output I got from this. I laughed a lot about the response I hope you can do too. What is shown is that even <code>Smurfen</code> is placed in the <code>Landdieren</code> category. Even when you don&rsquo;t edit the parameters or temperature it will give you a different response every time. You have to be very precise if you want to standardize the output.</p>
<div class="codecontainer" hi="mart"><div class="code-name">ProgramOutput.json</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;categorie&#34;</span><span class="p">:</span> <span class="s2">&#34;Zeedieren&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;omschrijving&#34;</span><span class="p">:</span> <span class="s2">&#34;Vogels die niet vliegen&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;naam&#34;</span><span class="p">:</span> <span class="s2">&#34;Pinguïns&#34;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;naam&#34;</span><span class="p">:</span> <span class="s2">&#34;Giraffe&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;categorie&#34;</span><span class="p">:</span> <span class="s2">&#34;Landdieren&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;omschrijving&#34;</span><span class="p">:</span> <span class="s2">&#34;Hoge nek, gevlekte vacht&#34;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;categorie&#34;</span><span class="p">:</span> <span class="s2">&#34;Landdieren&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;omschrijving&#34;</span><span class="p">:</span> <span class="s2">&#34;Blauwe wezentjes in het bos&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;naam&#34;</span><span class="p">:</span> <span class="s2">&#34;Smurfen&#34;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></td></tr></table>
</div>
</div></div><p>Think of the possibilities by lowering the temperature and making materialized categories of some huge text inputs, for example in an Azure Function reacting to business events.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I just wanted to try out the OpenAI API and see the possibilities it has. Soon corporates will be ready to use AI for their use cases and as a consultant, you should be able to advise them on the possibilities. I learned that the GPT model is statistically choosing output, and the response needs to be verified. That&rsquo;s why Microsoft calls its products `Copilot``. It helps you but isn&rsquo;t perfect.</p>
<!-- Quoteblock here?-->
<p>May the AI be with you.</p>
<h2 id="further-reading">Further reading</h2>
<ul>
<li>
<p><a href="https://learn.microsoft.com/en-us/legal/cognitive-services/openai/overview" target="_blank" rel="noopener">https://learn.microsoft.com/en-us/legal/cognitive-services/openai/overview</a></p>
</li>
<li>
<p><a href="https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/completions#completion" target="_blank" rel="noopener">https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/completions#completion</a></p>
</li>
<li>
<p><a href="https://blog.iusmentis.com/2023/03/21/van-wie-is-mijn-werk-als-ik-chatgpt-mijn-werk-laat-doen/" target="_blank" rel="noopener">https://blog.iusmentis.com/2023/03/21/van-wie-is-mijn-werk-als-ik-chatgpt-mijn-werk-laat-doen/</a></p>
</li>
<li>
<p><a href="https://blog.iusmentis.com/2023/06/08/mag-een-iso27001-gecertificeerde-organisatie-chatgpt-gebruiken/" target="_blank" rel="noopener">https://blog.iusmentis.com/2023/06/08/mag-een-iso27001-gecertificeerde-organisatie-chatgpt-gebruiken/</a></p>
</li>
<li>
<p><a href="https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/" target="_blank" rel="noopener">https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/</a></p>
</li>
</ul>
<!--Link to Documentation about Playground adding data.-->
<!--Link to Documentation about Cognitive Search.-->
<!--Link to Documentation about System Prompts.-->
<!-- Date and privacy explained Azure vs GPT-->
<!-- Date and privacy explained-->
]]></content:encoded>
      <category>Azure</category>
      <category>AI</category>
      <category>GPT</category>
      <category>OpenAI</category>
      <category>Cognitive Search</category>
    </item>
  </channel>
</rss>
