openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

openai.api_base -Error communicating with OpenAI: Failed to parse:

Open caotao94 opened this issue 1 year ago • 0 comments

Describe the bug

I use nginx proxy api_base “https://api.openai.com” on my server : “http://myserverip:port” and get a error msg:

My server is can connect https://api.openai.com

and i use this way apiBaseUrl on https://github.com/transitive-bullshit/chatgpt-api is no error

To Reproduce

[WARNING][2023-03-08 18:35:58][log.py:39] - Error communicating with OpenAI: Failed to parse: http://myserverip:port/v1/chat/completion

Code snippets

nginx conf:
server {
    listen       9999;
    server_name  127.0.0.1;
    error_log /var/log/nginx/chatgpt.error.log error;
    access_log  /var/log/nginx/chatgpt.access.log combined;
    location / {
       proxy_pass https://api.openai.com/;
    }
}

python code:

class ChatGPTModel(Model):
    def __init__(self):
        openai.api_key = model_conf(const.OPEN_AI).get('api_key')
        # https://api.openai.com/v1/chat/completions
        openai.api_base = model_conf(const.OPEN_AI).get('api_url')

python conf:
    "openai": {
      "api_url": "http://myserverip:port/v1"

OS

Debian10.0

Python version

3.9.2

Library version

0.27.0

caotao94 avatar Mar 08 '23 10:03 caotao94