DEV Community

Arun Kumar Palani
Arun Kumar Palani

Posted on

What is Chat GPT?

Hi, I am Arun Kumar Palani, Senior software engineer in Luxoft. Let’s discuss chat GPT in detail.

Note: I have implemented it in .NET, since I am from .NET background.

What is Chat GPT?

Chat GPT is an AI based (LLM) large language model designed by Open AI which is trained by large amount of data. In Chat GPT the data is trained up to 2021. One of the Open AI co-founders was Elon Musk.

Chat GPT working is based on GPT (Generative Pre-trained Transformer) model, an AI-based conversational agent, to produce intelligent responses to user inputs. A neural network architecture used for understanding and processing natural language is used in GPT model implementation.

Simply, the Chat GPT system tries to understand what a user is saying and then reacts to it in accordance with its training data. It can respond to a variety of topics and is intended to be helpful, knowledgeable, and informative.

The main benefit of Chat GPT is that it can communicate with users in natural language and gives tailored answers to each question. By removing the need for human interaction, this gives users instant access to pertinent information and contributes to time savings.

Mainly in Customer service, e-commerce, and education are just a few sectors where Chat GPT is extensively used. In the big data and machine learning era, it has become an essential tool. Large amounts of data can be analyzed by the software, which can then deliver insights that are tailored to the requirements of businesses.

How Chat GPT is used in real life?

  1. Creating a chat bot.
  2. Generating text-based applications.
  3. Creating a virtual assistant.
  4. Implement a customer service system in an automated way.
  5. Providing answers to most frequently asked questions in many e-commerce and general-purpose applications.
  6. Text summarizing and generating reports.

How is Chat GPT implemented?

The fundamental operating principle of Chat GPT is to take input from users, process the input data, and produce an insightful response.
Here is a step-by-step description of how the system works:
User input: The first step entails gathering information from the users. The users contribute by chatting in natural language via text or voice.

Processing the Input Data: After receiving user input, the data undergoes pre-processing to clean it up and eliminate unnecessary elements like stop words and punctuation. The text is then divided into smaller units by the software, typically words and phrases, which are then examined pairwise.

Application of Machine Learning Model: Following preprocessing of the input data, further analysis is conducted using the machine learning algorithm based on the GPT model. This algorithm creates new sentences with a probability determined by the frequency of appearance in the training sources using previous training data that was learned from millions of lines of publicly available text sources.

Response Generation: Using the linguistic patterns discovered in the earlier steps as a basis, Chat GPT applies the algorithm to produce a pertinent output text.

What is making Chat GPT unique?

Because of its capacity for instant learning and adaptation, Chat GPT is exceptional. Chat GPT uses machine learning to generate conversations based on its training data, in contrast to rule-based systems that adhere to a predetermined set of rules. The system can pick up on various conversational topics and behaviors and respond appropriately.
Another distinguishing feature of Chat GPT is that its models are trained on vast amounts of data, giving it an advantage over competing products of a similar nature. This guarantees that the system is effective at responding to user inquiries in a way that is both helpful and accurate.

What’s more interesting as a developer to do with Chat GPT?

Yes, as a developer we would like to communicate with Chat GPT end points and to create a working model so that we can demonstrate how these models help in real life scenarios and what problems it solves. Along with this we would also like to know the different search models are available and how we can use those models.

NuGet extension: OpenAI.
Different Chat GPT search models:

Chat GPT version 3 models:

1.AdaText
2.BabbageText
3.CurieText
4.Davinci
5.CushmanCode - codex model
6.DavinciCode – codex model
7.AdaTextEmbedding
Let’s see how these models are going to help based on the requirements.

1.AdaText: This model is capable of very simple tasks, usually the fastest model in the GPT-3 series, and this is one of the lowest cost models in the GPT series. The string code for this model is represented by “text-ada-001”.
1.Max token supported: 2049 tokens.
2.Trained data set: up to Oct- 2019

2.BabbageText: This model is capable of straightforward tasks, very fast, and lower cost and the string representation for this model is “text-babbage-001”.
1.Max token supported: 2049 tokens.
2.Trained data set: up to Oct-2019

3.CurieText: This model is Very capable, but faster and lower cost than Davinci and the string representation is “text-curie-001”.
1.Max token supported: 2049 tokens.
2.Trained data set: up to Oct-2019

4.DavinciText: This is the most capable GPT-3 model. Can do any task the other models can do, often with higher quality, longer output and better instruction-following.
1.Max token supported: 2049 tokens.
2.Trained data set: up to Oct-2019

5.CushmanCode: Almost as capable as Davinci Codex, but slightly faster. This speed advantage may make it preferable for real-time applications and its representation is “code-cushman-001”.
1.Max token supported: 2049 tokens.
2.Trained data set: up to Oct-2019

6.DavinciCode: Most capable Codex model. Particularly good at translating natural language to code. In addition to completing code, also supports inserting completions within code and its representation is “code-davinci-002”.
1.Max token supported: 8001 tokens.
2.Trained data set: up to Jun-2021

7.AdaTextEmbedding: OpenAI offers one second-generation embedding model for use with the embeddings API endpoint and its representation is “text-embedding-ada-002”.
1.Max token supported: 2049 tokens.
2.Trained data set: up to Oct-2019

Chat GPT version 3.5 models:

1.gpt-3.5-turbo
2.gpt-3.5-turbo-0301
3.text-davinci-003
4.text-davinci-002
5.code-davinci-002

1.gpt-3.5-turbo: The most powerful GPT-3.5 model, which is chat-optimized, costs only one-tenth as much as the text-davinci-003. updated with the most recent model iteration.
1.Max token supported: 4096 tokens.
2.Trained data set: up to Sep-2021

2.gpt-3.5-turbo-0301: GPT-3.5-Turbo snapshot taken from gpt-3.5-turbo. Contrary to the GT-3.5 Turbo, this model will only be supported for three months, ending on June 1, 2023, and will not receive any updates.
1.Max token supported: 4096 tokens.
2.Trained data set: up to Sep-2021

3.text-davinci-003: Can perform any language task better, faster, and with more consistency in following instructions than the curie, babbage, or ada models. Additionally supports text completions being inserted.
1.Max token supported: 4097 tokens.
2.Trained data set: up to Sep-2021

4.text-davinci-002: Like text-davinci-003 in terms of abilities but trained using supervised fine-tuning rather than reinforcement learning.
1.Max token supported: 4096 tokens.
2.Trained data set: up to Jun-2021

5.code-davinci-002: Designed code completion task.
1.Max token supported: 8001 tokens.
2.Trained data set: up to Jun-2021

Chat GPT version 4 models:

1.gpt-4
2.gpt-4-0314
3.gpt-4-32k
4.gpt-4-32k-0314

1.gpt-4: More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with our latest model iteration.
1.Max token supported: 8192 tokens.
2.Trained data set: up to Sep-2021.

2.gpt-4-0314: Snapshot of gpt-4 from March 14th, 2023. Unlike gpt-4, this model will not receive updates, and will only be supported for a three-month period ending on June 14th, 2023.
1.Max token supported: 8192 tokens.
2.Trained data set: up to Sep-2021.

3.gpt-4-32k: Same capabilities as the base gpt-4 mode but with 4x the context length. Will be updated with our latest model iteration.
1.Max token supported: 32768 tokens.
2.Trained data set: up to Sep-2021.

4.gpt-4-32k-0314: Snapshot of gpt-4-32 from March 14th, 2023. Unlike gpt-4-32k, this model will not receive updates, and will only be supported for a three-month period ending on June 14th, 2023.
1.Max token supported: 32768 tokens.
2.Trained data set: up to Sep-2021.

Other models:

1.DALL.E
2.Whisper
3.Embedding
4.Moderation

DALL.E: DALLE is an artificial intelligence program that can produce art and realistic images from a description in natural language. We currently provide support for the creation of new images with a specific size, the editing of existing images, and the creation of variations of user-provided images. The DALLE model that is currently available through our API is the second version of DALLE, which has more accurate, realistic, and images with a 4x higher resolution than the first model.

Whisper: A general-purpose speech detection model is whisper. It is a multi-task model that can perform multilingual voice recognition, speech translation, and language identification and was trained on a sizable dataset of varied audio. Our API presently offers the Whisper v2-large model under the name whisper-1.
Right now, there is no distinction between the Whisper accessible through our API and the open-source version. However, we provide an optimized inference procedure through our API, which makes using Whisper through our API much faster than using other methods.

Embedding: It is a numerical representation of text that can be used to quantify the relatedness between two pieces of text. At a fraction of the price, our second-generation embedding model, text-embedding-ada-002, is intended to take the position of the 16 first-generation embedding models that came before it.
Tasks involving search, clustering, recommendations, anomaly detection, and categorization can benefit from embeddings.

Moderation: The Moderation models' purpose is to determine whether material abides by Open Ai’s usage guidelines.
The models offer the ability to categorize material by searching for items that fall under the following headings: hate, hate/threat, self-harm, sexual, sexual/minors, violence, and violence/graphic.

How to integrate Chat GPT in .NET application?

  1. Create an account in OpenAI.com.
  2. Get the API-key from the Open AI website once successfully logged in.
  3. There are 2 different ways to implement this in .NET
    1. Completion request class
    2. Direct Http client usage to hit Open AI end points.

Completion request implementation:
1.Install Open AI from the NuGet package manager.

Image description

There are few inputs we need to pass to the completion request. They are.
a. Prompt: It is basically the input string where we are sending from the input request.

b. Model: This is the place we need to define which Chat GPT model we are going to use when we are making a API call to Open AI endpoint.

c. Temperature: It gives sampling rate for the search that we are trying with. If we are sampling rate is higher ex) 0.9f we can get creative answer from the endpoint. If we are using 0f we will get the standard answers.

d. Max Tokens: It gives the information how much is the maximum string that the API will give as a response. This can be set manually if we are using either completion request class or from Http Client as well. We need to ensure the maximum token available to generate response for the particular model before specifying the value.

e. TopP: An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommend to use this or OpenAI_API.Completions.CompletionRequest.Temperature but not both.

f. Frequency Penalty: The scale of the penalty for how often a token is used. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. Defaults to 0.

g. Presence Penalty: The scale of the penalty applied if a token is already present at all. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. Defaults to 0.

2.Apply the API key and start running the application.
3.Full code for creating the working model using completion request class.
4.Sample C# code:
var gpt = new OpenAIAPI(apiKey);
CompletionRequest completionRequest = new
CompletionRequest()
{
Prompt = input,
Model = Model.DavinciText,
Temperature = 0.5f,
MaxTokens = 4000,
TopP = 1.0,
FrequencyPenalty = 0.0,
PresencePenalty = 0.0,
};
completionResult = await
gpt.Completions.CreateCompletionAsync(completionRequest);

Http client Implementation:
1.We just need some basic idea of how Http client works before implementing this. We need to pass the proper parameters and request and response formats that should match with the Open API endpoint which is officially released.

2.There are different endpoints which was provided by Open AI for chat completion, Image generation, Image edit, Audio translation, Audio transcription and so on. Let's see one how to implement the chat completion in Http client.

Image description

3.It requires a base address to establish a connection to the open API endpoint. For chat completion we need to use this URL: https://api.openai.com/v1/completions

4.Authorization can be done by the unique API-key given by Open AI this will perform authentication for us.

  1. I have used .NET 6 so the Http client will have PostAsJsonAsync() method where we need to pass the input request.

  2. With the help of ReadFromJsonAsync() method in the response we can get the result from Open AI.

  3. Here is the C# code.
    public async Task
    GenerateCompletion(ChatCompletionRequestcs request,
    CancellationToken cancellationToken = default)
    {
    try
    {
    HttpClient httpClient = new HttpClient();
    httpClient.BaseAddress = new Uri(chatEndpoint);
    httpClient.DefaultRequestHeaders.Add("Authorization",
    $"Bearer {apiKey}");
    httpClient.DefaultRequestHeaders.Add("Accept",
    "application/json");
    var res = await
    httpClient.PostAsJsonAsync(chatEndpoint, request,

    cancellationToken);
    var result = await
    res.Content.ReadFromJsonAsync
    (cancellationToken: cancellationToken);
    return result;
    }
    catch (Exception)
    {
    throw;
    }
    }

Advantages of Chat GPT:

  1. Automated decision making with AI based system.
  2. Precise use case with safety and security of data we search.
  3. Increased accuracy.
  4. Quick response time and increased engagement.
  5. Reduced expense and increased customer service.

Disadvantages of Chat GPT?

  1. Inaccuracies and Ambiguities in some times.
  2. Limited Knowledge of Recent Events - because it is trained with data up to 2021.
  3. Ethical Issues and Concerns.
  4. Other Possible Legal Implications.

Conclusion: Chat GPT is a highly powerful language model with the potential to revolutionize a variety of fields and sectors. It is a useful tool for applications like chatbots, virtual assistants, and content production due to its capacity to generate extremely accurate and contextually relevant responses to natural language inputs. Although if bias and interpretability provide difficulties that must be overcome, Chat GPT represents a promising area for future research and development in the field of artificial intelligence.

Thanks for reading the article, if you have any queries or suggestions, please post it in the comments section.

Top comments (1)

Collapse
 
chatgtpai profile image
chatgtpai

What is Chat gtp AI?
Regular advancement is happening in artificial intelligence, which creates revolutionary changes in interaction and communication in the same way as humans. In this article, I will explain the Chat GPT AI, A great tool in AI technology. Its Open AI company introduced this magical tool, Chat GPT AI, based on neural networks and different language models that create the best user outcome. It is free and depends on language models to understand and communicate with humans.