Hello everyone, Here we are going to discuss, how to integrate OpenAI with .Net Core and Angular 15.
ChatGPT (Generative Pre-trained Transformer) is the chatbot developed by OpenAI on November 30, 2022.
Previously we discussed OpenAI and we have seen how to create a ChatGTP application using OpenAI,
For more please follow the below link 👇
- What Is Chatgpt And Purpose Of Chatgpt
- Create First Application In ChatGPT By OpenAI - ChatGPT Tutorial
- Microsoft Extend Partnership With OpenAI
Step 1 - Create an OpenAI account
First, we need to create an OpenAI account; you can follow the below link to how to create an OpenAI account.
Step 2 - Get the OpenAI API key
Login to your OpenAI account and click on profile (personal, right-hand side) and click on view API
Once you click on View API Keys, you will ‘Create a new secret key, once you click on it an API key will generate in the Popup window, and you can copy it for using it in the application.
Now open visual studio 2022 and create an Asp.net Core web API project like below
Give additional information as per your requirement.
Once the project is created, now go to the NuGet package manager and add the OpenAI package like below
Now right-click on the Controller folder and add a new controller Called OpenAI and write the below code in it
Now click on the program.cs class and add the cors origin like below,
When you will run this application, we will see our API in swagger and our API is ready to use in angular
Now we need to create the Angular 15 application, you can follow the below link for the same
once the angular 15 application is created, now open the app.component.ts file and add the below code
Add the below code in app.component.html file
Now create a service file with the below command, here service name is ‘OpenAI’
And write the below code in the openAI.service.ts file
In the above the Url path is ‘'https://localhost:7285’, you need to replace the port, which you are looking at locally, once you run your .Net Core application.
Now add this service reference in the app.model.ts file in the provider array and apart from it we need to add the FormsModule and HttpClientModule like below
Now when you will run your angular 15 application, you will see UI like below
Here, now you can write your query and click on the getResult button, you will see the output below
The output will be like below
This is the way we can integrate the OpenAI with our angular application.
Below is the video, on how we can integrate OpenAI with our angular application practically,
----------------------------------------------------------------
EmoticonEmoticon