Skip to content

相关的ChatGPT研究实验

NGINX 配置代理 api.openai.com

shell
server {
       listen 443 ssl;
       server_name api.my.com;
       ssl_certificate    /etc/nginx/cert/aigpai.pem;
       ssl_certificate_key   /etc/nginx/cert/aigpai.key;
       ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
       ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
       ssl_prefer_server_ciphers on;
       ssl_session_cache shared:SSL:10m;
       ssl_session_timeout 10m;
       add_header Strict-Transport-Security "max-age=31536000";
       error_log /tmp/test.log;

       location / {
           proxy_ssl_server_name on;
           proxy_pass https://api.openai.com;
           proxy_set_header Host api.openai.com;
           proxy_set_header Connection '';
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_set_header X-Forwarded-Proto $scheme;
       }
}
server {
       listen 443 ssl;
       server_name api.my.com;
       ssl_certificate    /etc/nginx/cert/aigpai.pem;
       ssl_certificate_key   /etc/nginx/cert/aigpai.key;
       ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
       ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
       ssl_prefer_server_ciphers on;
       ssl_session_cache shared:SSL:10m;
       ssl_session_timeout 10m;
       add_header Strict-Transport-Security "max-age=31536000";
       error_log /tmp/test.log;

       location / {
           proxy_ssl_server_name on;
           proxy_pass https://api.openai.com;
           proxy_set_header Host api.openai.com;
           proxy_set_header Connection '';
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_set_header X-Forwarded-Proto $scheme;
       }
}

nginx 配置 chat.oppenai.com 代理

shell
server {
       listen 8091;
       server_name chat1.ccaiai.com; 
       add_header Strict-Transport-Security "max-age=31536000";
       error_log /tmp/test.log;

       location  ^~ /backend-api {
           proxy_ssl_server_name on;
           proxy_pass https://chat.openai.com;
           proxy_set_header Host chat.openai.com;
           proxy_set_header Connection '';
            proxy_set_header sec-fetch-mode 'cors';
           proxy_set_header User-Agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36';
           proxy_set_header Origin 'https://chat.openai.com';
           proxy_set_header Referer 'https://chat.openai.com'; 
           proxy_set_header Accept '*/*';
           proxy_set_header Accept-Encoding 'gzip, deflate, br';
           proxy_hide_header AUTHKEY;
           proxy_hide_header traceparent;
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
       }
       location / {
           proxy_ssl_server_name on;
           proxy_pass https://demo.xyhelper.cn;
           proxy_set_header Host demo.xyhelper.cn;
           proxy_set_header Connection '';
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
       }
}
server {
       listen 8091;
       server_name chat1.ccaiai.com; 
       add_header Strict-Transport-Security "max-age=31536000";
       error_log /tmp/test.log;

       location  ^~ /backend-api {
           proxy_ssl_server_name on;
           proxy_pass https://chat.openai.com;
           proxy_set_header Host chat.openai.com;
           proxy_set_header Connection '';
            proxy_set_header sec-fetch-mode 'cors';
           proxy_set_header User-Agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36';
           proxy_set_header Origin 'https://chat.openai.com';
           proxy_set_header Referer 'https://chat.openai.com'; 
           proxy_set_header Accept '*/*';
           proxy_set_header Accept-Encoding 'gzip, deflate, br';
           proxy_hide_header AUTHKEY;
           proxy_hide_header traceparent;
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
       }
       location / {
           proxy_ssl_server_name on;
           proxy_pass https://demo.xyhelper.cn;
           proxy_set_header Host demo.xyhelper.cn;
           proxy_set_header Connection '';
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
       }
}

接入点docker化

shell
##请到hw机器上 
cd /data/app/chatgpt-web/docker-compose/chat2api-point && git pull
docker build -t chatpoint . && docker tag chatpoint ydlhero/chatpoint && docker push  ydlhero/chatpoint

docker pull  ydlhero/chatpoint
docker rm -f  chatpoint && docker run --name chatpoint  -itd  --restart=always  -p 80:8091  ydlhero/chatpoint
##请到hw机器上 
cd /data/app/chatgpt-web/docker-compose/chat2api-point && git pull
docker build -t chatpoint . && docker tag chatpoint ydlhero/chatpoint && docker push  ydlhero/chatpoint

docker pull  ydlhero/chatpoint
docker rm -f  chatpoint && docker run --name chatpoint  -itd  --restart=always  -p 80:8091  ydlhero/chatpoint

chatgpt-mirror-server 项目

项目地址:https://github.com/openai-hk/chatgpt-mirror-server

部署文件

各个相关的接口

yml

yml
  chatgpt-mirror-server:
    image: xyhelper/chatgpt-mirror-server:latest
    restart: always
    ports:
      - 6019:8001
    environment:
      TZ: Asia/Shanghai # 指定时区
      # 接入网关地址
      CHATPROXY: "https://demo.xyhelper.cn"
      # 接入网关的authkey
      AUTHKEY: "xyhelper"
      # 是否只使用token验证
      ONLYTOKEN: "true" 
    volumes:
      - ./data/chatgpt-mirror-server/:/app/data/
    labels:
      - "com.centurylinklabs.watchtower.scope=xyhelper-chatgpt-mirror-server"
  chatgpt-mirror-server:
    image: xyhelper/chatgpt-mirror-server:latest
    restart: always
    ports:
      - 6019:8001
    environment:
      TZ: Asia/Shanghai # 指定时区
      # 接入网关地址
      CHATPROXY: "https://demo.xyhelper.cn"
      # 接入网关的authkey
      AUTHKEY: "xyhelper"
      # 是否只使用token验证
      ONLYTOKEN: "true" 
    volumes:
      - ./data/chatgpt-mirror-server/:/app/data/
    labels:
      - "com.centurylinklabs.watchtower.scope=xyhelper-chatgpt-mirror-server"

由上yml 转换 docker 部署

shell
docker rm -f chatgpt-mirror-server &&  docker run  --name chatgpt-mirror-server \
-d  --restart=always  -p 6019:8001 \
 --add-host mysql:172.17.0.1 \
 --add-host redis:172.17.0.1 \
-e TZ=Asia/Shanghai \
-e CHATPROXY=https://demo.xyhelper.cn \
-e AUTHKEY=xyhelper \
-e ONLYTOKEN=true  xyhelper/chatgpt-mirror-server
docker rm -f chatgpt-mirror-server &&  docker run  --name chatgpt-mirror-server \
-d  --restart=always  -p 6019:8001 \
 --add-host mysql:172.17.0.1 \
 --add-host redis:172.17.0.1 \
-e TZ=Asia/Shanghai \
-e CHATPROXY=https://demo.xyhelper.cn \
-e AUTHKEY=xyhelper \
-e ONLYTOKEN=true  xyhelper/chatgpt-mirror-server

现在下redis

shell
docker run  --name redis  -d  --restart=always -p 6379:6379 redis
docker run  --name redis  -d  --restart=always -p 6379:6379 redis