.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);
        }
    }





}

 结果:

 

posted @ 2023-05-31 15:45  有翅膀的大象  阅读(101)  评论(0)    收藏  举报