Created
December 7, 2022 02:13
-
-
Save kkdai/49bb4816f137295240beb3c34ba814a8 to your computer and use it in GitHub Desktop.
Refine of https://github.com/isdaviddong/chatGPTLineBot/blob/main/Controllers/ChatGPT.cs by ChatGPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Net; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Net.Http; | |
| using System.Web; | |
| namespace isRock.Template | |
| { | |
| public class ChatGPT | |
| { | |
| private static HttpClient client = new HttpClient(); | |
| private static string JSONString = @" | |
| {{ | |
| ""model"": ""text-davinci-003"", | |
| ""prompt"": ""{0}"", | |
| ""max_tokens"": 4000, | |
| ""temperature"": 0 | |
| }} | |
| "; | |
| private static Newtonsoft.Json.JsonSerializerSettings serializerSettings = new Newtonsoft.Json.JsonSerializerSettings() | |
| { | |
| NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore | |
| }; | |
| public static Result CallChatGPT(string msg) | |
| { | |
| string uri = "https://api.openai.com/v1/completions"; | |
| // Request headers. | |
| client.DefaultRequestHeaders.Add( | |
| "Authorization", "Bearer ________chatGPT_Token_______________"); | |
| var JSON = String.Format(JSONString, msg); | |
| var content = new StringContent(JSON, Encoding.UTF8, "application/json"); | |
| var response = client.PostAsync(uri, content).Result; | |
| return Newtonsoft.Json.JsonConvert.DeserializeObject<Result>(response.Content. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment