OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API

Home Page:https://www.nuget.org/packages/OpenAI/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

toolai-io opened this issue · comments

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

}

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

what was the resolution, if at all? Thx!