.Net请求Azure的OpenAI
using System; using System.Net.Http; using System.Security.Policy; using System.Text; using System.Threading.Tasks; using static System.Net.Mime.MediaTypeNames; class Program { static string apiKey = ""; static string baseUrl = "https://azure.com/openai/deployments/bushuname/chat/completions"; static async Task Main(string[] args) { // Console.Write("Enter your message: "); string message = "{ \"temperature\": 0.7,\"messages\": [ { \"role\": \"system\" , \"content\": \"You are a helpful assistant.\" } ,{ \"role\": \"user\" , \"content\": \"what the captial of china?\" } ]}"; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("api-key", $"{apiKey}"); string url = $"{baseUrl}?api-version=2023-05-15"; string json = message; HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(url, content); string result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } } }
结果:

,Best Wish 不负年华

浙公网安备 33010602011771号