OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API
https://www.nuget.org/packages/OpenAI/
Other
1.86k stars 430 forks source link

The SSL connection could not be established, see inner exception. #194

Open toolai-io opened 8 months ago

toolai-io commented 8 months ago

The SSL connection could not be established, see inner exception. I'm using .NET Core 8 and encountering an issue when calling the ChatGPT-4 API through a WebAPI. The WebAPI does not use SSL, and its local address is http://localhost:5273/. It was working initially, but then the error started occurring.

[HttpPost("AIChat")] public async Task AIChat([FromBody] ChatGPT_Request request) { try { OpenAIAPI api = new OpenAIAPI(_openAIOption.APIKey); //api.HttpClientFactory = _httpClientFactory;

     var chat = api.Chat.CreateConversation();
     chat.Model = OpenAI_API.Models.Model.GPT4;
     chat.RequestParameters.Temperature = 0.7;
     chat.RequestParameters.MaxTokens = 2000;

     foreach (var message in request.messages)
     {
         if (message.role == "user")
             chat.AppendUserInput(message.content, ImageArrayToImageListArray(message.images));

         if (message.role == "assistant")
             chat.AppendMessage(new ChatMessage(ChatMessageRole.Assistant, message.content));

         if (message.role == "system")
             chat.AppendMessage(new ChatMessage(ChatMessageRole.System, message.content));
     }

            await foreach (var res in chat.StreamResponseEnumerableFromChatbotAsync())
            {
                if (isfirst)
                {
                    isfirst = false;
                    var p1Tag = Encoding.UTF8.GetBytes("<p>");
                    await Response.Body.WriteAsync(p1Tag, 0, p1Tag.Length);
                    //await Response.Body.FlushAsync();
                }

                Console.WriteLine($"{res}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Message: {ex.Message}");
            await Response.Body.WriteAsync(Encoding.UTF8.GetBytes(ex.Message));
            //await Response.Body.FlushAsync();
        }

}

pavelkozhokar commented 8 months ago

Got the same issue but on the Azure web-app hosted service

sanjay-ram commented 4 months ago

what was the resolution, if at all? Thx!