betalgo / openai

OpenAI .NET sdk - Azure OpenAI, ChatGPT, Whisper, and DALL-E
https://betalgo.github.io/openai/
MIT License
2.88k stars 516 forks source link

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

Closed xbaha closed 1 year ago

xbaha commented 1 year ago

Describe the bug The SSL connection could not be established, see inner exception. SocketException: An existing connection was forcibly closed by the remote host.

Your code piece

        public async Task GenerateResponse2()
        {
            var openAiService = new OpenAIService(new OpenAiOptions()
            {
                ApiKey = apiKey
            });

            var completionResult = await openAiService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
            {
                Messages = new List<ChatMessage>
                {
                    ChatMessage.FromSystem("You are a helpful assistant."),
                    ChatMessage.FromUser("Who won the world series in 2020?"),
                    ChatMessage.FromAssistant("The Los Angeles Dodgers won the World Series in 2020."),
                    ChatMessage.FromUser("Where was it played?")
                },
                Model = Models.ChatGpt3_5Turbo,
                MaxTokens = 50//optional
            });
            if (completionResult.Successful)
            {
                Console.WriteLine(completionResult.Choices.First().Message.Content);
            }
        }
kayhantolga commented 1 year ago

If you need to use a self-signed SSL certificate you may want to pass your own HTTP client to the library. There was a topic in the discussion about this.