Personal AI assistant, build a simple version of ChatGPT client

Chatgpt Client Chatgpt has become very popular recently. Everyone is using chatgpt, but there is a certain threshold to use chatgpt. In order to facilitate novice users, a chatgpt client is specially made using WPF and AspNetCore's webapi program to quickly access the chatgpt model to generate dialogues. AI Assistant Stand-alone Chatgpt Client.

Use AspNetCore or WPF to build a personal AI assistant and make a handmade ChatGPT client

Client Recently, chatgpt has become very popular. Everyone is using chatgpt. However, there is a certain threshold for using chatgpt. In order to facilitate new users, a webapi program based on WPF and AspNetCore is specially created. , quickly access the chatgpt model to generate dialogue through the client.Stand-alone chatgpt client.

Building the ChatGPT client

First, create a new WPF project to make the first client example.
Personal AI assistant, build a simple version of ChatGPT client-1
I chose .NET6 as the project framework. I recommend you to choose .NET CORE2.2 or above, otherwise the ChatGPT library will fail to be referenced.
Personal AI assistant, build a simple version of ChatGPT client-2

Reference the following two packages, as shown in the figure. The first one is used to provide a core component for dependency injection, and the second one is a general client library I wrote in advance for quick access to OpenAI.
Personal AI assistant, build a simple version of ChatGPT client-3

Make some small adjustments to the WPF project. In App.Xaml, remove the startup item first.
Personal AI assistant, build a simple version of ChatGPT client-4

In App.xaml.cs, add the following functional code. Because the method implementation of the general library uses dependency injection, a simple registration method is used here to illustrate the point. No other IOC container is used. The simplest way is the best.
Two core registration options: HttpClient, IOpenAiServices interface and implementation
Personal AI assistant, build a simple version of ChatGPT client-5
Just create two input boxes and a button, and give the two input boxes a name to distinguish them, such as Receive and Send. You can customize them yourself and don't need to pay attention to these details.
Personal AI assistant, build a simple version of ChatGPT client-6
The client access interface provided is asynchronous, and it is recommended to call it in an asynchronous manner. Implement it in the button event, as shown in the figure. For other remarks, you can directly refer to the text description in the figure.
Personal AI assistant, build a simple version of ChatGPT client-7
Run the program and do a simple test, such as writing a hello world. The answer provided is a C program code of Hello world, it seems that there is no problem with access, Bingo~
Personal AI assistant, build a simple version of ChatGPT client-8
Next, let's try making a webapi client based on aspnetcore. Create a new webapi project.
Personal AI assistant, build a simple version of ChatGPT client-9
Here I also choose the .NET 6 framework version. It doesn't matter what version you like, .NET CORE 2.2 and above can be used.
Personal AI assistant, build a simple version of ChatGPT client-10
Add the same quote as above
Personal AI assistant, build a simple version of ChatGPT client-11
Add registration.
Personal AI assistant, build a simple version of ChatGPT client-12
Inject the IOpenAiServices service. For simplicity, inject it directly into the default controller.
Personal AI assistant, build a simple version of ChatGPT client-13
Modify the default method and see the picture.
Personal AI assistant, build a simple version of ChatGPT client-14
Start the program and take a look. For example, write a Vue front-end login code
Personal AI assistant, build a simple version of ChatGPT client-15
You can roughly see the content, but it is a bit difficult to look at the return value directly as a string. There happens to be an input box in WPF above, so let's throw it over and see the effect.
Personal AI assistant, build a simple version of ChatGPT client-16
I started it up and took a look at the results. It seems to be OK. Basically, all functions are covered. It is much faster than doing it yourself.
Personal AI assistant, build a simple version of ChatGPT client-17
Since the WPF client is open, I will also ask about the WPF front-end code and use the MVVM mode to see how the layout is. It seems to be almost well written, including Xaml code and ViewModel code
Personal AI assistant, build a simple version of ChatGPT client-18
Switch back to the webapi project. The CallGPT3 parameters are as follows, so the message parameters can also be customized for our own personalized tuning.
Personal AI assistant, build a simple version of ChatGPT client-19

For example,The built-in key has expired or there is no money.,I want to pass my own key to access:
Personal AI assistant, build a simple version of ChatGPT client-20
Take one, enter the content of the request dialogue, and your own key, and take one. Content and return, see the picture by yourself~
Personal AI assistant, build a simple version of ChatGPT client-21
At this point, the self-built AI assistant chatgpt client has been completed.
You can make secondary production based on the above code.
Chatgpt client download:https://www.mediafire.com/file/670l9xrryetbs9e/ChatClient.zip/file
Original link:https://www.cnblogs.com/weskynet/p/16990125.html

score

Leave a Reply

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