Excellent software and practical tutorials
Use AspNetCore or WPF to build a personal AI assistant and make a handmade ChatGPT client
chatgptClient 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. chatgpt client , quickly access the chatgpt model to generate dialogue through the client.AI AssistantStand-alone chatgpt client.
Building the ChatGPT client
First, create a new WPF project to make the first client example.
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.
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.
Make some small adjustments to the WPF project. In App.Xaml, remove the startup item first.
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
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.
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.
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~
Next, let's try making a webapi client based on aspnetcore. Create a new webapi project.
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.
Add the same quote as above
Add registration.
Inject the IOpenAiServices service. For simplicity, inject it directly into the default controller.
Modify the default method and see the picture.
Start the program and take a look. For example, write a Vue front-end login code
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.
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.
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
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.
For example,The built-in key has expired or there is no money.,I want to pass my own key to access:
Take one, enter the content of the request dialogue, and your own key, and take one. Content and return, see the picture by yourself~
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