liuyuqi-dellpc 1 year ago
commit
42518d3f0a
6 changed files with 124 additions and 0 deletions
  1. 25 0
      .dockerignore
  2. 6 0
      Dockerfile
  3. 27 0
      README.md
  4. 42 0
      ai.takegpt.cn.conf
  5. 13 0
      docker-compose.debug.yml
  6. 11 0
      docker-compose.yml

+ 25 - 0
.dockerignore

@@ -0,0 +1,25 @@
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/bin
+**/charts
+**/docker-compose*
+**/compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md

+ 6 - 0
Dockerfile

@@ -0,0 +1,6 @@
+FROM nginx:latest
+WORKDIR /usr/share/nginx/html
+COPY ai.takegpt.cn.conf /etc/nginx/conf.d/ai.takegpt.cn.conf
+
+EXPOSE 80 443
+CMD ["nginx", "-g", "daemon off;"]

+ 27 - 0
README.md

@@ -0,0 +1,27 @@
+# ai.takegpt.cn
+
+this is a openai-proxy, using ngixn proxy.
+
+## Develop
+
+```conf
+docker build -t jianboy/aitakegpt:latest .
+docker-compose up -d
+```
+
+## Usage
+
+```python
+import openai
+openai.api_key = api_key
+openai.api_base = "ai.takegpt.cn"
+openai.ChatCompletion.create(
+  model="gpt-3.5-turbo",
+  messages=[
+        {"role": "system", "content": "You are a helpful assistant."},
+        {"role": "user", "content": "Who won the world series in 2020?"},
+        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
+        {"role": "user", "content": "Where was it played?"}
+    ]
+)
+```

+ 42 - 0
ai.takegpt.cn.conf

@@ -0,0 +1,42 @@
+server {
+  listen 80;
+  listen [::]:80;
+#   server_name ai.takegpt.cn;
+  access_log /data/wwwlogs/www.takegpt.cn_nginx.log combined;
+
+  location / {
+    proxy_pass https://api.openai.com;
+	proxy_ssl_server_name on;  # 开启代理SSL服务器名称验证,确保SSL连接的安全性
+	proxy_set_header Host api.openai.com;  # 设置代理请求头中的Host字段为api.openai.com
+	chunked_transfer_encoding off;  # 禁用分块编码传输,避免可能的代理问题
+	proxy_buffering off;  # 禁用代理缓存,避免数据传输延迟
+	proxy_cache off;  # 禁用代理缓存,确保实时获取最新的数据
+	#proxy_set_header X-Forwarded-For $remote_addr;  # 将客户端真实IP添加到代理请求头中的X-Forwarded-For字段中,用于记录客户端真实IP
+    #include proxy.conf;
+  }
+}
+
+server {
+	listen       443 ssl http2;
+	listen       [::]:443 ssl http2;
+	# server_name  ai.takegpt.cn;
+
+	ssl_certificate "/root/.acme.sh/takegpt.cn_ecc/fullchain.cer";
+	ssl_certificate_key "/root/.acme.sh/takegpt.cn_ecc/takegpt.cn.key";
+	ssl_session_cache shared:SSL:1m;
+	ssl_session_timeout  10m;
+	ssl_ciphers HIGH:!aNULL:!MD5;
+	ssl_prefer_server_ciphers on;
+
+	location / {
+		proxy_pass https://api.openai.com;
+	}
+	
+	error_page 404 /404.html;
+		location = /40x.html {
+	}
+
+	error_page 500 502 503 504 /50x.html;
+		location = /50x.html {
+	}
+}

+ 13 - 0
docker-compose.debug.yml

@@ -0,0 +1,13 @@
+version: '3.4'
+
+services:
+  aitakegpt:
+    image: aitakegpt
+    build:
+      context: .
+      dockerfile: ./Dockerfile
+    environment:
+      JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005,quiet=y
+    ports:
+      - 3000:3000
+      - 5005:5005

+ 11 - 0
docker-compose.yml

@@ -0,0 +1,11 @@
+version: '3.4'
+
+services:
+  aitakegpt:
+    image: jianboy/aitakegpt:latest
+    ports:
+      - 80:80
+      - 443:443
+    volumes:
+      - ./ai.takegpt.cn.conf:/etc/nginx/conf.d/ai.takegpt.cn.conf
+    restart: unless-stopped