Azure

Overview Of Azure OpenAI Modules With A Focus On Davinci Module

This text supplies an summary of the Azure OpenAI modules, explicitly specializing in the Davinci module. Pattern code written in C# is included to display its utilization. We’ll discover the opposite modules in additional element in an upcoming weblog submit.

Azure OpenAI affords a variety of fashions categorized by their meant process and functionality. These fashions are grouped into completely different households, every related to a particular set of duties. Nonetheless, not all fashions can be found in all areas at current. The under describes the mannequin households which can be at present accessible.

There are three units of fashions supplied by OpenAI. Under is simply an summary of the module info.

  • GPT-3 for pure language understanding and era
  • Codex for code understanding and era (together with translation from pure language to code), and Embeddings for using and understanding semantic representations of textual content information.
  • The Embeddings fashions are available three households for various capabilities: similarity, textual content search, and code search.

Let’s begin intimately GPT-Three Module

GPT-Three Module

The GPT-Three fashions are able to pure language understanding and era and can be found in 4 completely different capabilities, every with various ranges of energy and velocity suited to particular duties. Essentially the most succesful mannequin is Davinci, whereas Ada is the quickest. The next checklist reveals the newest variations of the GPT-Three fashions ordered by growing functionality:

  • text-ada-001
  • text-babbage-001
  • text-curie-001
  • text-davinci-003

Davinici

Davinci is probably the most potent GPT-Three mannequin and might carry out all of the duties of different fashions with much less instruction. It is the only option for purposes that require a deep understanding of content material, comparable to summarizing particular audiences and producing inventive content material. Nonetheless, Davinci requires extra computing assets, making it slower and dearer than different fashions.

Davinci additionally excels in understanding the intent of the textual content, fixing varied logic issues, and explaining character motives. It has efficiently tackled a few of the most difficult AI issues, particularly these involving trigger and impact.

Davinci is advisable to be used in complicated intent, cause-and-effect evaluation, and summarization for audiences.

How you can Create an Azure OpenAI Deployment and Check a Mannequin: A Step-by-Step Information

To start out this pattern, it’s essential create an Azure OpenAI deployment. This part focuses on tips on how to create an Azure OpenAI deployment.

  • After creating the useful resource, go to “Mannequin deployments” and create a brand new deployment.
  • Present a reputation for the Mannequin deployment and choose the mannequin you want to take a look at.
  • For this instance, we’ve got chosen “text-davinci-002”.

Overview of Azure OpenAI Modules with a Focus on Davinci module

Instance

This C# code instance showcases the Azure OpenAI GPT-Three Davinci mannequin’s capability to deal with complicated intent. The code generates an e mail textual content that follows up with a possible shopper after a gathering. As a gross sales consultant for a software program firm, the e-mail ought to clarify some great benefits of the corporate’s software program, tackle any issues the shopper could have raised, and invite them to a demo of the software program.

To make use of C# language, I’ve created a Console utility utilizing Visual Studio 2022.

The code initializes a string variable “inputMessage” with a message immediate for the OpenAI GPT-Three mannequin. The message immediate features a situation the place a gross sales consultant for a software program firm wants to write down an e mail to a possible shopper explaining the advantages of the corporate’s software program, addressing any issues the shopper could have expressed, and alluring them to a demo of the software program.

The code then calls the “ConnectAzureOpenAI” technique with the “Url” and “key” variables as parameters to ship the immediate to the OpenAI GPT-Three mannequin and acquire a response. The response is saved within the “consequence” variable utilizing the “await” key phrase to attend for the response.

static async Activity Fundamental(string[] args) {
    Console.WriteLine("Welcome to Azure OpenAI Davinci Instance");
    var inputMessage = "You're a gross sales consultant for a software program firm. You could have simply completed a gathering with a possible shopper, and it's essential comply with up with them through e mail." + " Write an e mail to the shopper that explains the advantages of your organization's software program, addresses any issues the shopper could have expressed, and invitations them to a demo of the software program..";
    var consequence = await ConnectAzureOpenAI(Url, key, inputMessage);
    Console.WriteLine(consequence);
    Console.Learn();
}

The code initializes a JSON object named “jsonContent” with varied properties, together with “immediate”, “max_tokens”, “temperature”, “frequency_penalty”, “presence_penalty”, “top_p”, and “best_of”. These properties are used to configure parameters for the OpenAI GPT-Three mannequin.

The code then creates an HTTP POST request message and units the request URL. It creates a brand new string content material object “immediate” utilizing the serialized JSON object “jsonContent” because the content material, with UTF8 encoding and “utility/json” media sort. The “immediate” content material is then set because the content material of the request message.

utilizing
var shopper = new HttpClient();
shopper.BaseAddress = new Uri(url);
shopper.DefaultRequestHeaders.Settle for.Add(new MediaTypeWithQualityHeaderValue("utility/json"));
shopper.DefaultRequestHeaders.Add("api-key", key);
var jsonContent = new {
    immediate = message,
        max_tokens = 1024,
        temperature = 0.7,
        frequency_penalty = 0.5,
        presence_penalty = 0,
        top_p = 0.5,
        best_of = 1
};
var msg = new HttpRequestMessage(HttpMethod.Put up, url);
var immediate = new StringContent(JsonConvert.SerializeObject(jsonContent), Encoding.UTF8, "utility/json");
msg.Content material = immediate;

The code sends the HTTP POST request message to the OpenAI GPT-Three mannequin through the HttpClient occasion “shopper”. It makes use of the “await” key phrase to attend for the response and the “ConfigureAwait(false)” technique to make sure that the continuation doesn’t should run in the identical context because the earlier code.

If the response standing code signifies success, the code reads the response content material as a string and parses it right into a JObject. It then checks if the “selections” key exists within the consequence and has no less than one worth. In that case, it extracts the abstract textual content from the primary selection within the “selections” array, saved within the “abstract” variable.

var res = await shopper.SendAsync(msg).ConfigureAwait(false);
if (res.IsSuccessStatusCode) {
    // Learn the response content material as a string
    var stringResult = await res.Content material.ReadAsStringAsync().ConfigureAwait(false);
    // Parse the string consequence as a JObject
    var consequence = JObject.Parse(stringResult);
    // If the "selections" key exists within the consequence and it has no less than one worth
    if (consequence["choices"] != null && consequence["choices"].Any()) {
        // Extract the abstract textual content from the primary selection within the "selections" array
        abstract = consequence["choices"][0]["text"].ToString();
    }
}

Right here is an instance of how every request to Azure OpenAI will produce a unique output.

Overview of Azure OpenAI Modules with a Focus on Davinci module

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button