通过使用会话,开发人员可以构建聊天应用程序,在与用户的多次交互中维护上下文,这可以带来更具吸引力和自然的对话。
问题:如何使用 c# http 与 gpt-3.5-turbo API 建立会话?
using Newtonsoft.Json;
using System.Text;
namespace MyChatGPT
{
internal class Program
{
static async Task Main(string[] args)
{
// Set up the HttpClient
var client = new HttpClient();
var baseUrl = "https://api.openai.com/v1/chat/completions";
// Set up the API key
var apiKey = "YOUR_API_KEY";
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);
while (true)
{
// Prompt the user for input
Console.Write("> ");
var userInput = Console.ReadLine();
// Set up the request parameters
var parameters = new …Run Code Online (Sandbox Code Playgroud)