renaldig / melodistiq-music-generator

MIT License
2 stars 0 forks source link

openai #1

Open dgcovell opened 3 weeks ago

dgcovell commented 3 weeks ago

code fails at response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=conversations[session_id], max_tokens=200 )

where the error points to the version of openai. Suggestions include You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface.

Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28

In response: the README for openai-python for the APL points to a number of possibilities that relate to the API_KEY. From your ReadMe.txt there is the requirement for getting you own API_KEY. Can you provide more details??

In addition, migrate or using openai version 28 do not work.

I am running Python 3.12.3

version('openai') '0.28.0'

dgcovell commented 3 weeks ago

Just spent a few hours getting my secret api code, verifying it (https://keychecker.aikemist.ai/) where it is valid for 'gpt-3.5-turbo-instruct' as well as gpt-4o-mini-2024-07-18. However, getting the secret code into the python script remains unclear. Advice??

dgcovell commented 2 weeks ago

Newest error indicates SSL issue. Bunches of blogs. So far the 'magic' solution has not been found.

File "C:\Users\covelld\AppData\Local\anaconda3\Lib\site-packages\openai\api_requestor.py", line 609, in request_raw raise error.APIConnectionError( openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)')))

renaldig commented 2 weeks ago

Hello @dgcovell , this normally should not be an issue, as you wouldn't have to use SSL verification; at least I did not have to do that on my end. That being said, try to update the certifi package perhaps, which is the Mozilla CA Bumdle in Python:

pip install --upgrade certifi

Afterwards, try verifying the location of the cacert.pem file:

import certifi print(certifi.where())

This will display the path to the CA bundle used by certifi.

Also, ensure Your system's CA certificates Are up-to-date. Sometimes, the system's CA certificates might be outdated, leading to SSL verification failures.

If you're on Windows, Windows relies on its own certificate store. Ensure your system is updated, as updates often include the latest CA certificates.

If you're on MacOS, run the Install Certificates.command script located in the Python installation directory. This script installs the necessary certificates.

Configure Python to Use the Updated CA bundle. If updating certifi doesn't resolve the issue, you can configure Python to use the system's CA certificates. Set the REQUESTS_CA_BUNDLE environment variable to point to your system's CA bundle.

For Windows:, use set REQUESTS_CA_BUNDLE=C:\path\to\cacert.pem. For MacOS and Linux, use export REQUESTS_CA_BUNDLE=/path/to/cacert.pem. Replace /path/to/cacert.pem with the actual path to your CA bundle.

If this still does not work, try disabling SSL verification in the meanwhile with the below:

import openai openai.api_key = 'your-api-key' openai.verify_ssl_certs = False

This is not a security-safe approach but good to verify that the code is working.

Additionally, on the topic of getting the secret key into the code, you store it as an environmental variable. If you're on Windows, for instance, you just type in environmental variables and insert it as one. The code then fetches it with os.getenv('openai_api_key').

Let me know if this is still an issue!

dgcovell commented 1 week ago

renaldig, thanks for your suggestions. still no luck. I believe there is a miscommunication between python and Chrome. Note that the error message reads

The server could not be reached [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)

It is not clear what server is being invoked? And whether the SSL is somehow blocking this. I have explored a few other blogs regarding CA_BUNDLE_PATH and httpx w/o success. But a new error pops up.

context = ssl.create_default_context() context.load_verify_locations(cafile="C:\Users\covelld\AppData\Local\anaconda3\Lib\site-packages\certifi\cacert.pem") httpx.get('https://example.org', verify=context) <Response [200 OK]> response = client.get("https://localhost:8000")

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

I'm unclear as to how to proceed. The IT folks here at the NIH are skeptical that this should work. But they have not really invested much time into a resolution.

Do you have more input?

Thanks