ToB企服应用市场:ToB评测及商务社交产业平台

标题: 如何解决本地开发调用OpenAI接口的问题 [打印本页]

作者: 西河刘卡车医    时间: 2024-1-2 12:14
标题: 如何解决本地开发调用OpenAI接口的问题
  1. 在开发过程中,如果需要在本地调用openAI接口进行开发调试,一般主要是通过以下两种方式:直连和代理转发。欢迎私信交流。
复制代码
1. 直连

2. 代理转发
  1. 代理转发又有两种类型,使用第三方代理和自建代理两种,下面将分别举例说明
复制代码
2.1. 第三方AI网关

2.2. 自建Nginx

  1. # 在原有配置基础上,追加--with-stream --with-stream_realip_module,切记不要漏掉原有配置
  2. ./configure --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-d8gVax/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-d8gVax/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module --with-http_ssl_module --with-stream --with-stream_realip_module
复制代码
  1. # 千万不要执行make install
  2. make
复制代码
  1. location /gpt {
  2.         proxy_pass  https://api.openai.com/v1/;
  3.         proxy_ssl_server_name on;
  4.         proxy_set_header Host api.openai.com;
  5.         proxy_set_header Connection '';
  6.         proxy_http_version 1.1;
  7.         # 不缓存,支持流式输出,打字机效果
  8.         proxy_cache off;  # 关闭缓存
  9.         proxy_buffering off;  # 关闭代理缓冲
  10.         chunked_transfer_encoding on;  # 开启分块传输编码
  11.         tcp_nopush on;  # 开启TCP NOPUSH选项,禁止Nagle算法
  12.         tcp_nodelay on;  # 开启TCP NODELAY选项,禁止延迟ACK算法
  13.         keepalive_timeout 120s;  # 设定keep-alive超时时间
  14.         proxy_set_header X-Forwarded-For $remote_addr;
  15.         proxy_set_header X-Forwarded-Proto $scheme;
  16. }
复制代码

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4