```csharp using System.Text; using System.Text.Json; namespace Gpt; class Program { static async Task Main(string[] args) { var client = new HttpClient(); if (!args.Any()) { Console.WriteLine("This program uses the OpenAI GPT API to generate text based on user prompts. "); Console.WriteLine("It sends HTTP POST requests to the API endpoint and uses JSON deserialization to extract the generated text. "); Console.WriteLine("Usage: gpt <prompt>"); return; } var prompt = string.Join(" ", args); var request = CreateHttpRequestMessage(prompt); var response = await GetResponse(client, request); Console.WriteLine(quot;GPT: {response}"); } private static async Task<string?> GetResponse(HttpClient client, HttpRequestMessage request) { using var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStringAsync(); var jsonResponse = JsonSerializer.Deserialize<JsonElement>(responseBody); var choices = jsonResponse.GetProperty("choices"); return choices[0].GetProperty("text").GetString(); } private static HttpRequestMessage CreateHttpRequestMessage(string? prompt) => new() { Method = HttpMethod.Post, RequestUri = new Uri("https://api.openai.com/v1/completions"), Headers = { { "Authorization", "Bearer " + Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY") } }, Content = CreateStringContent(prompt) }; private static StringContent CreateStringContent(string? prompt) => new(JsonSerializer.Serialize(new { model = "text-davinci-003", prompt = prompt, max_tokens = 200, temperature = 0.3 }), Encoding.UTF8, "application/json"); } ```