microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
22.14k stars 3.3k forks source link

Sample Code: OpenAI service failed to complete the prompt, APIConnectionError issue with Python 3.10 #627

Closed carterwilliamson closed 1 year ago

carterwilliamson commented 1 year ago

Describe the bug Unable to run the sample code here: https://github.com/microsoft/semantic-kernel/blob/main/python/README.md

To Reproduce Steps to reproduce the behavior:

  1. Create new virtual environment python -m venv venv
  2. python -m pip install --upgrade semantic-kernel
  3. Create a .env file following these instructions: https://github.com/microsoft/semantic-kernel/blob/main/python/README.md#openai--azure-openai-api-keys
  4. Copy this code - https://github.com/microsoft/semantic-kernel/blob/main/python/README.md#running-a-prompt into a file named main.py
  5. Error: Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the prompt', APIConnectionError(message='Error communicating with OpenAI', http_status=None, request_id=None))

Expected behavior Expected to see output like Robots must not harm humans.

Desktop (please complete the following information):

Additional context Full error: Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the prompt', APIConnectionError(message='Error communicating with OpenAI', http_status=None, request_id=None))

No VPN enabled. New virtual environment. Tried with my personal account as well as my company account. Both had same result. Tried on a VPN, no luck.

Edit:

I was able to run the sample in an AWS ec2 instance with python 3.9. I then tested on my machine with a python:3.9 docker container which also worked. This appears to be an issue with python 3.10.

poweihuang0817 commented 1 year ago

Hello, I used Python 3.11.3 and it works. I didn't use venv but it does work. The issue you described is strange

JJDawn commented 1 year ago

Have you solved the problem? I am having the same error.

evchaki commented 1 year ago

@alexchaomander can you take a look at this?

alexchaomander commented 1 year ago

@carterwilliamson are you still running into this issue? I was able to get it to work fine using my Python 3.10 environment

2662007798 commented 1 year ago

I have the same problem. I'm currently using python 3.11.3, which doesn't work.

priya-27 commented 1 year ago

Facing same issue with python 3.10 inside Codespaces for semantic kernel python notebooks, any fix ?

2662007798 commented 1 year ago

Partly because of network problems, I switched to the Singapore server to work

阿生 @.***

Original Email

Sender:"PRIYA BHIMJYANI"< @.*** >;

Sent Time:2023/5/18 18:07

To:"microsoft/semantic-kernel"< @.*** >;

Cc recipient:"2662007798"< @. >;"Comment"< @. >;

Subject:Re: [microsoft/semantic-kernel] Sample Code: OpenAI service failed tocomplete the prompt, APIConnectionError issue with Python 3.10 (Issue #627)

Facing same issue with python 3.10 inside Codespaces for semantic kernel python notebooks, any fix ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

hot5auce commented 1 year ago

https://github.com/openai/openai-python/issues/278

roshan-gopalakrishnan commented 1 year ago

If you are giving any org_id just comment it in the .env. It is optional.

chenlucu commented 1 year ago

I got the same problem. I traced the error and found that it was not able to verify the local issuer certificate. Cannot connect to host xxxxxx.openai.azure.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')] So I added a config setting in the source code(openai/api_requestor.py line 586):

image

This will ignore the verification of SSL certificate, and this fixed my problem.

priya-27 commented 1 year ago

Yes, for me, the issue was I was using Azure open ai key and in the code in the sample python notebooks, there was a boolean flag variable for using azure open ai set to false by default.

image

so if you Get this Error, either use open ai key or turn the boolean flag to true before using azure open ai key.

bingokunkun commented 1 year ago

I got the same problem. I traced the error and found that it was not able to verify the local issuer certificate. Cannot connect to host xxxxxx.openai.azure.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')] So I added a config setting in the source code(openai/api_requestor.py line 586): image This will ignore the verification of SSL certificate, and this fixed my problem.

It's no use to me : (

chenlucu commented 1 year ago

I got the same problem. I traced the error and found that it was not able to verify the local issuer certificate. Cannot connect to host xxxxxx.openai.azure.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')] So I added a config setting in the source code(openai/api_requestor.py line 586): image This will ignore the verification of SSL certificate, and this fixed my problem.

It's no use to me : (

I think this error is generally the network problem, since it was not able to make a successful http request. (http_status=None, request_id=None, which means no http status and no request id). Might be an VPN problem, or the openai server blocked your request. You'd better debug and trace the error to find the exact reason.

balasubramanian-thiruvenkatesan commented 1 year ago

It turned to an issue with proxy for me. Setting the proxy via the environment variables - HTTP_PROXY and HTTPS_PROXY did not work.

I had to set the proxy using the below way

import openai

openai.proxy = {
    "http": "<HTTP_PROXY>",
    "https": "<HTTPS_PROXY>"
}
dandv commented 1 year ago

I think I've run into the same SSL certificate something error on macOS.

And found this solution on SO:

bash /Applications/Python*/Install\ Certificates.command

After restarting the Jupyter notebook kernel, things worked.

matthewbolanos commented 1 year ago

I think I've run into the same SSL certificate something error.

And found this solution on SO:

bash /Applications/Python*/Install\ Certificates.command

After restarting the Jupyter notebook kernel, things worked.

I ran into the same issue. Thankfully this solution fixed it on my end. Is this problem specific to Macbooks or Windows as well? @JJDawn, @2662007798, @priya-27, @bingokunkun, and @dandv, are all y'all on Macbooks?

dandv commented 1 year ago

@matthewbolanos Yes, I'm on Ventura 13.3.1(a).

priya-27 commented 1 year ago

Yes, on a mac

On Mon, 12 Jun 2023 at 5:48 PM, Matthew Bolaños @.***> wrote:

I think I've run into the same SSL certificate something error.

And found this solution on SO https://stackoverflow.com/questions/42098126/mac-osx-python-ssl-sslerror-ssl-certificate-verify-failed-certificate-verify :

bash /Applications/Python*/Install\ Certificates.command

After restarting the Jupyter notebook kernel, things worked.

I ran into the same issue, but this solution fixed it on my end. Is this problem specific to Macbooks or Windows as well? @JJDawn https://github.com/JJDawn, @2662007798 https://github.com/2662007798, @priya-27 https://github.com/priya-27, @bingokunkun https://github.com/bingokunkun, and @dandv https://github.com/dandv, are all y'all on Macbooks?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/semantic-kernel/issues/627#issuecomment-1587229159, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2EQ7LGDGK5YPGAK33GOGMLXK4CLBANCNFSM6AAAAAAXKHBWYE . You are receiving this because you were mentioned.Message ID: @.***>

2662007798 commented 1 year ago

_我想_我遇到了相同的SSL证书错误。 并在 SO 上找到了这个解决方案

bash /Applications/Python*/Install\ Certificates.command

重新启动Jupyter笔记本内核后,事情开始了。

我遇到了同样的问题。值得庆幸的是,这个解决方案解决了我的问题。这个问题是否也特定于Macbook或Windows?@JJDawn、@2662007798、@priya-27、@bingokunkun和@dandv,你们都在Macbook上吗?

no is windows

garyjkuehn commented 1 year ago

Same error where identical code works on a PC but fails on my MacBook. (side by side test). The code is using the model as deployed in our Azure subscription. (AzureTextCompletion).
Macbook = 12.6.2 python = 3.10.2

fresh venv:

Package Version


aiofiles 23.1.0 aiohttp 3.8.5 aiosignal 1.3.1 async-timeout 4.0.2 attrs 23.1.0 certifi 2023.7.22 charset-normalizer 3.2.0 click 8.1.6 frozenlist 1.4.0 idna 3.4 multidict 6.0.4 numpy 1.25.1 openai 0.27.8 pip 23.2.1 python-dotenv 1.0.0 regex 2023.6.3 requests 2.31.0 semantic-kernel 0.3.4.dev0 setuptools 58.1.0 tqdm 4.65.0 urllib3 2.0.4 yarl 1.9.2

garyjkuehn commented 1 year ago

Corrected on the Mac by upgrading python to version 3.11.4. All other packages previously stated remain as-is within the new virtual environment.

quangngoc commented 1 year ago

I have the same issue on Debian 11, python 3.10.12: Error: (<ErrorCodes.ServiceError: 6>, 'OpenAI service failed to complete the chat', APIConnectionError(message='Error communicating with OpenAI', http_status=None, request_id=None)) In the same environment, I could get response using langchain.

After checking ex.cause, I get the message: Cannot connect to host xxx:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)')]

I finaly found that setup the environment variable SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt (for aiohttp) make it work

shivam-51 commented 1 year ago

Fixed on mac by running on Python 3.9 instead of 3.11. strange.

GhimBoon commented 1 year ago

It turned to an issue with proxy for me. Setting the proxy via the environment variables - HTTP_PROXY and HTTPS_PROXY did not work.

I had to set the proxy using the below way

import openai

openai.proxy = {
    "http": "<HTTP_PROXY>",
    "https": "<HTTPS_PROXY>"
}

This worked for me. It seems that semantic kernel isn't referencing the env variables, and you have to manually set them.

lemillermicrosoft commented 1 year ago

We understand the issue is related to the virtual environment configuration. No changes to be made in the python SDK at present.