Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
toolai-io opened this issue Feb 12, 2024 · 1 comment
Open

Comments

@toolai-io
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants