ChatGPTNextWeb / ChatGPT-Next-Web

A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini 应用。
https://app.nextchat.dev/
MIT License
74.88k stars 58.96k forks source link

[Feature] 添加对 Azure OpenAI API 的支持 #371

Closed edisonzf2020 closed 10 months ago

edisonzf2020 commented 1 year ago

修改BASE_URL成微软的endpoint,API key修改成微软的key,不能工作。微软还需要设置其他参数。

tiny656 commented 1 year ago

azure openai proxy的项目可以搜一下,这个满足你的需求

ripenedcat commented 1 year ago

258

ripenedcat commented 1 year ago

azure openai proxy的项目可以搜一下,这个满足你的需求

感谢思路,使用的https://github.com/diemus/azure-openai-proxy/blob/main/README.zh-cn.md, 将本项目base url替换成docker server url, https改为http后,成功!

Yidadaa commented 1 year ago

@ripenedcat

感谢反馈,之后我会将此方式补充到 README。

cl1107 commented 1 year ago

azure openai proxy的项目可以搜一下,这个满足你的需求

感谢思路,使用的https://github.com/diemus/azure-openai-proxy/blob/main/README.zh-cn.md, 将本项目base url替换成docker server url, https改为http后,成功!

这个项目也不错 https://github.com/stulzq/azure-openai-proxy

doherty88 commented 1 year ago

怎么搞定的?我用了这个azure-openai-proxy项目搭了个proxy,用代码调用已经成功了,但是用chatgpt next web会出错 error code 1003,感觉好像stream方式 azure API不支持?

ripenedcat commented 1 year ago

怎么搞定的?我用了这个azure-openai-proxy项目搭了个proxy,用代码调用已经成功了,但是用chatgpt next web会出错 error code 1003,感觉好像stream方式 azure API不支持?

看一下chatgpt next web选的model是不是在azure-openai-proxy的环境变量里? 以及common.ts里是否改成了http模式(如果你没有https反代的话)? 具体在看下azure-openai-proxy的log里是否有什么线索呢

haibbo commented 1 year ago

@Yidadaa

如果用户没有服务器可以 通过 cloudflare worker

https://github.com/haibbo/cf-openai-azure-proxy

diemus commented 1 year ago

怎么搞定的?我用了这个azure-openai-proxy项目搭了个proxy,用代码调用已经成功了,但是用chatgpt next web会出错 error code 1003,感觉好像stream方式 azure API不支持?

@doherty88 是我开发的这个吗?https://github.com/diemus/azure-openai-proxy

有问题可以在issue里提供复现场景,有些web项目会调用一些特殊的接口,比如获取model列表,资金余额之类的,Azure是没有的,近期会补上一个mock接口来模拟这类请求的返回。如果是这个问题,临时的解决方案是换一个前端项目,有些项目不会去调类似的接口。另外stream是支持的。

lzhgus commented 1 year ago

怎么搞定的?我用了这个azure-openai-proxy项目搭了个proxy,用代码调用已经成功了,但是用chatgpt next web会出错 error code 1003,感觉好像stream方式 azure API不支持?

我也发现了同样的问题, 用的是cloudflare worker. 问题好像也是和stream有关, 回复的message会keep loading,然后说 “出错了,稍后重试吧”

doherty88 commented 1 year ago

是的,我是用的这个。 现在我用了railway来部署ChatGPT-Next-Web,同样的proxy docker,同样的环境变量设置就可以用了。

lzhgus commented 1 year ago

是的,我是用的这个。 现在我用了railway来部署ChatGPT-Next-Web,同样的proxy docker,同样的环境变量设置就可以用了。

谢谢, 用railway, 我这儿还是有问题。。

{ "cause": { "errno": -3008, "code": "ENOTFOUND", "syscall": "getaddrinfo", "hostname": "https" } }

doherty88 commented 1 year ago

PROTOCOL 这个环境变量设了吗?我的azure代理是http模式,所以我这这个环境变量设成 “http”

Jer-y commented 1 year ago

是的,我是用的这个。 现在我用了railway来部署ChatGPT-Next-Web,同样的proxy docker,同样的环境变量设置就可以用了。

谢谢, 用railway, 我这儿还是有问题。。

{ "cause": { "errno": -3008, "code": "ENOTFOUND", "syscall": "getaddrinfo", "hostname": "https" } }

@lzhgus

lzhgus commented 1 year ago

是的,我是用的这个。 现在我用了railway来部署ChatGPT-Next-Web,同样的proxy docker,同样的环境变量设置就可以用了。

谢谢, 用railway, 我这儿还是有问题。。 { "cause": { "errno": -3008, "code": "ENOTFOUND", "syscall": "getaddrinfo", "hostname": "https" } }

@lzhgus

感谢回复, 我觉得base url应该是问题,现在已经工作了。 对的, 我也是全部部署在Azure 上的, 用的是Container App。 有一个问题不知道大家是否注意到, 可能是因为Proxy, client side的behavior 改变了, 现在不会像之前一样逐字输出, 而是会略显卡顿的输出或者是一次性显示全部。

Jer-y commented 1 year ago

@lzhgus

感谢回复, 我觉得base url应该是问题,现在已经工作了。 对的, 我也是全部部署在Azure 上的, 用的是Container App。 有一个问题不知道大家是否注意到, 可能是因为Proxy, client side的behavior 改变了, 现在不会像之前一样逐字输出, 而是会略显卡顿的输出或者是一次性显示全部。

我没猜错的话,这个应该是Azure Container App的问题,默认的Container APP用的ingress proxy开启了buffer造成了打字机效果被影响。因为不影响我的使用我倒是没有去深究。如果你想有打字机效果的话还是用其他手段(Azure VM, AKS, etc)自行部署最合适

diemus commented 1 year ago

未必是代理的问题,azure直连也缺少打字机效果,之前测试过,感觉不用太纠结这个问题

Jer-y commented 1 year ago

你是说PlayGround嘛。哈哈哈哈他们都没加打字机效果的实现,另外就是代码输出都没调试过,把markdown原始内容都返回来了,我已经给开发组开了issue了,不过估计他们暂时不会修。另外我倒是同意,不用太纠结这个问题。又不是不能用.jpg

diemus commented 1 year ago

不是playground,就是直接请求azure openai,流式返回的时候,azure不是按字返回的,而是一次返回一大段,然后又是一段。感觉在azure那一层就已经不是打字机效果了

Jer-y commented 1 year ago

那么你的判断肯定就没错了,我下周一开个feature的work item给他们,不过,这种功能估计优先级不高,可能会拖。

lzhgus commented 1 year ago

我相信playground 应该也用了ReadableStream 去处理流式返回和实现打字机效果, 我可以去codebase找找看确认下,不过相较于直接call openai, azure openai service 的 latency 更高, 但是download 时间却大幅变短, 可能因此打字机的效果变得怪异了。 不过确实这也不影响使用 :)

image image
haibbo commented 1 year ago

大家可以试试这个, 它实现了打印机效果

https://github.com/haibbo/cf-openai-azure-proxy

原理就是, 从Azure OpenAI Service拿到的消息虽然是一段一段的, 但给客户端的时候我拆出一条条的消息, 依次给.

yinm0591 commented 1 year ago

大家可以试试这个, 它实现了打印机效果

https://github.com/haibbo/cf-openai-azure-proxy

原理就是, 从Azure OpenAI Service拿到的消息虽然是一段一段的, 但给客户端的时候我拆出一条条的消息, 依次给.

cf-openai-azure-proxy这个项目太赞了,谢谢~~~

Jer-y commented 1 year ago

@haibbo 感谢分享!星星已送出 @lzhgus 说的是是对的。我周末测了一下并和OpenAI做了比较,Azure的流式返回是一段一段地吐,虽然实际返回速度比原生的要好,但是视觉感官有点顿顿的。另外很奇怪的点是中文/日文/韩文等响应的latency比英文要高很多,这一点很费解。美国那边的PM说用的和OpenAI是同样的方案。我可以体会到追这种问题要多久。anyway,有需求的暂时就前台处理吧

hbsgithub commented 1 year ago

https://github.com/hbsgithub/deno-azure-openai-proxy 基于@haibbo 的卓越工作,我增加了mapper的功能,并改写成ts脚本部署在deno deploy上,特性如下:

  1. 相比于cloudflare workers,可以无需代理,直连使用
  2. 支持自定义二级域名(*.deno.dev)或者绑定自己的域名
  3. 支持打字机模式的流式响应
  4. 支持mapper,可以自定义模型映射规则,也支持直接透传模型名
  5. 无需服务器,免费在线部署,每月10万次请求额度

欢迎大家使用!

DinoFeng commented 1 year ago

@edisonzf2020 至少改四处才可以应用Azure openai API.

  1. BASE_URL 替换成Azure的,例如:[你的SourceName].openai.azure.com/openai/deployments
  2. headers不是用Authorization: `Bearer ${apiKey}`,,而是用"api-key": `${apiKey}`,
  3. "v1/chat/completions"替换成你在Azure Deploy的chat/completions的Path, 例如:[你的DeploymentId]/chat/completions?api-version=2023-03-15-preview
  4. chat-stream\route.ts里其中一段代码:
          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            const queue = encoder.encode(text);
            controller.enqueue(queue);
          } catch (e) {
            controller.error(e);
          }

    替换为:

          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            if (text) {
              // console.debug(text);
              const queue = encoder.encode(text);
              controller.enqueue(queue);
            } else {
              // console.log({ json });
              const stop = json.choices[0].finish_reason;
              if (stop === "stop") {
                controller.close();
                return;
              }
            }
          } catch (e) {
            controller.error(e);
          }
duchenpaul commented 1 year ago

我用stulzq/azure-openai-proxy 就可以把azure的API转成openAI的API给chatgpt-web用, 如下:

version: "3"
services:
  chatgpt-web:
    image: chenzhaoyu94/chatgpt-web:{{ web_version }}
    ports:
      - "{{ http_port }}:3002"
    environment:
      OPENAI_API_KEY: {{ chatgpt_openai_api_key }}
      OPENAI_API_BASE_URL: http://azure-openai-proxy:8080
      AUTH_SECRET_KEY: "" # Leave blank
      MAX_REQUEST_PER_HOUR: 1000
      TIMEOUT_MS: 60000
    depends_on:
      - azure-openai-proxy
    links:
      - azure-openai-proxy
    networks:
      - chatgpt-ns

  azure-openai-proxy:
    image: stulzq/azure-openai-proxy:{{ proxy_version }}
    ports:
      - "{{ proxy_port }}:8080"
    environment:
      AZURE_OPENAI_ENDPOINT: {{ chatgpt_openai_endpoint }}
      AZURE_OPENAI_MODEL_MAPPER: {{ chatgpt_azure_openai_model_mapper }}
      AZURE_OPENAI_API_VER: {{ chatgpt_azure_openai_api_ver }}
    networks:
      - chatgpt-ns

networks:
  chatgpt-ns:
    driver: bridge
xiaoyongzhu commented 1 year ago

我不是web开发者,不过还是非常希望能够加入对于azure openai的原生支持,主要是这个UI相较其他UI很舒服也很实用。根据这个文件(https://github.com/mckaywrigley/chatbot-ui/blob/main/README.md ),应该只需要加入这几个环境变量就可以。我可以提供一个测试环境。

Environment Variable Default value Description
OPENAI_API_KEY The default API key used for authentication with OpenAI
OPENAI_API_HOST https://api.openai.com The base url, for Azure use https://<endpoint>.openai.azure.com
OPENAI_API_TYPE openai The API type, options are openai or azure
OPENAI_API_VERSION 2023-03-15-preview Only applicable for Azure OpenAI
AZURE_DEPLOYMENT_ID Needed when Azure OpenAI, Ref Azure OpenAI API
OPENAI_ORGANIZATION Your OpenAI organization ID
DEFAULT_MODEL gpt-3.5-turbo The default model to use on new conversations, for Azure use gpt-35-turbo
luckyBricks commented 1 year ago

To the users who are seeking a right way of using Azure Open AI proxy in this project:

After building your own Azure Open AI proxy service, you can use below commands to startup the ChatGPT-Next-Web docker container.

  1. If the service is accessible with an URL
docker run -d -p 3000:3000 \
   -e OPENAI_API_KEY="<Your Azure OpenAI API key here>" \
   -e CODE="<your own password>" \
   -e BASE_URL="gpt-proxy.contoso.com" \
   yidadaa/chatgpt-next-web
  1. If the service is accessible locally
# The proxy service available on 0.0.0.0:8080, proxy service and ChatGPT-Next-Web are on same machine.
docker run -d -p 3000:3000 \
   -e OPENAI_API_KEY="<Your Azure OpenAI API key here>" \
   -e CODE="<your own password>" \
   --net=host \
   -e BASE_URL="0.0.0.0:8080" \
   yidadaa/chatgpt-next-web

The configurations are defined in the project but not mentioned in the readme. Appreciate if someone can enrich the doc and list all environment variables there.

zhuyaguang commented 1 year ago

@edisonzf2020 至少改四处才可以应用Azure openai API.

  1. BASE_URL 替换成Azure的,例如:[你的SourceName].openai.azure.com/openai/deployments
  2. headers不是用Authorization: `Bearer ${apiKey}`,,而是用"api-key": `${apiKey}`,
  3. "v1/chat/completions"替换成你在Azure Deploy的chat/completions的Path, 例如:[你的DeploymentId]/chat/completions?api-version=2023-03-15-preview
  4. chat-stream\route.ts里其中一段代码:
          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            const queue = encoder.encode(text);
            controller.enqueue(queue);
          } catch (e) {
            controller.error(e);
          }

替换为:

          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            if (text) {
              // console.debug(text);
              const queue = encoder.encode(text);
              controller.enqueue(queue);
            } else {
              // console.log({ json });
              const stop = json.choices[0].finish_reason;
              if (stop === "stop") {
                controller.close();
                return;
              }
            }
          } catch (e) {
            controller.error(e);
          }

第4点最新的代码已经更新了,可以不用修改

DinoFeng commented 1 year ago

@edisonzf2020 至少改四处才可以应用Azure openai API.

  1. BASE_URL 替换成Azure的,例如:[你的SourceName].openai.azure.com/openai/deployments
  2. headers不是用Authorization: `Bearer ${apiKey}`,,而是用"api-key": `${apiKey}`,
  3. "v1/chat/completions"替换成你在Azure Deploy的chat/completions的Path, 例如:[你的DeploymentId]/chat/completions?api-version=2023-03-15-preview
  4. chat-stream\route.ts里其中一段代码:
          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            const queue = encoder.encode(text);
            controller.enqueue(queue);
          } catch (e) {
            controller.error(e);
          }

替换为:

          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            if (text) {
              // console.debug(text);
              const queue = encoder.encode(text);
              controller.enqueue(queue);
            } else {
              // console.log({ json });
              const stop = json.choices[0].finish_reason;
              if (stop === "stop") {
                controller.close();
                return;
              }
            }
          } catch (e) {
            controller.error(e);
          }

第4点最新的代码已经更新了,可以不用修改

刚测试了,不改的话依然是这样一直loading的: image

doutv commented 1 year ago

我成功用上了Azure OpenAI了

分享具体步骤:

  1. 开通Azure OpenAI服务并部署
  2. 部cf-openai-azure-proxy https://github.com/haibbo/cf-openai-azure-proxy
  3. Vercel部署ChatGPT-Next-Web,配置环境变量
    BASE_URL:cloudfare worker 部署的URL
    OPENAI_API_KEY:在Azure Portal OpenAI 找到 API key,有两个key,用其中一个即可

    image

zhangever commented 1 year ago

@edisonzf2020 至少改四处才可以应用Azure openai API.

  1. BASE_URL 替换成Azure的,例如:[你的SourceName].openai.azure.com/openai/deployments
  2. headers不是用Authorization: `Bearer ${apiKey}`,,而是用"api-key": `${apiKey}`,
  3. "v1/chat/completions"替换成你在Azure Deploy的chat/completions的Path, 例如:[你的DeploymentId]/chat/completions?api-version=2023-03-15-preview
  4. chat-stream\route.ts里其中一段代码:
          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            const queue = encoder.encode(text);
            controller.enqueue(queue);
          } catch (e) {
            controller.error(e);
          }

替换为:

          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            if (text) {
              // console.debug(text);
              const queue = encoder.encode(text);
              controller.enqueue(queue);
            } else {
              // console.log({ json });
              const stop = json.choices[0].finish_reason;
              if (stop === "stop") {
                controller.close();
                return;
              }
            }
          } catch (e) {
            controller.error(e);
          }

第4点最新的代码已经更新了,可以不用修改

刚测试了,不改的话依然是这样一直loading的: image

直接用CURL去调用azure的接口,返回来也是打字机效果。 但确实在ChatGPT-Next-Web中看不到打字机效果,只能看到一段段的输出。 另外, curl最后返回的data是[DONE], 但是程序永远都拿不到这个[DONE]的事件, 所以上面有兄台用finish_reason去判断是否结束。 BTW: finish_reason有很多, 不能仅仅判断是stop。 实际上, finish_reason不为空就应该结束了

curl https://xxx-gpt-35.openai.azure.com/openai/deployments/gpt-35-turbo-text/chat/completions\?api-version\=2023-03-15-preview \
  -H "Content-Type: application/json" \
  -H "api-key: xxx" \
  -d '{ 
    "stream": true,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"role":"assistant"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"Hello"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" there"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"!"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" How"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" may"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" I"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" assist"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" you"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" today"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"?"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":"stop","delta":{}}],"usage":null}

data: [DONE]
yinm0591 commented 1 year ago
  1. 目前,CURL去调用azure的接口也是没有打字机效果,是一段一段出来的,你提问复杂些就能发现无打字机效果了
  2. 程序永远都拿不到这个[DONE]的事件,是因为azure接口返回data: [DONE]后面少了\n\n

目前最佳方式还是用这个项目: https://github.com/haibbo/cf-openai-azure-proxy

zhangever commented 1 year ago

兄弟们有没有觉得azure的接口响应很慢, 单一个ssl握手起码都1秒起步,还经常连接超时。

yinm0591 commented 1 year ago

azure美东服务器连azure openai美东接口,ssl握手很快,不会超时,但每次对话要延迟5-8秒才会出内容,一段一段的。

DinoFeng commented 1 year ago

@edisonzf2020 至少改四处才可以应用Azure openai API.

  1. BASE_URL 替换成Azure的,例如:[你的SourceName].openai.azure.com/openai/deployments
  2. headers不是用Authorization: `Bearer ${apiKey}`,,而是用"api-key": `${apiKey}`,
  3. "v1/chat/completions"替换成你在Azure Deploy的chat/completions的Path, 例如:[你的DeploymentId]/chat/completions?api-version=2023-03-15-preview
  4. chat-stream\route.ts里其中一段代码:
          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            const queue = encoder.encode(text);
            controller.enqueue(queue);
          } catch (e) {
            controller.error(e);
          }

替换为:

          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            if (text) {
              // console.debug(text);
              const queue = encoder.encode(text);
              controller.enqueue(queue);
            } else {
              // console.log({ json });
              const stop = json.choices[0].finish_reason;
              if (stop === "stop") {
                controller.close();
                return;
              }
            }
          } catch (e) {
            controller.error(e);
          }

第4点最新的代码已经更新了,可以不用修改

刚测试了,不改的话依然是这样一直loading的: image

直接用CURL去调用azure的接口,返回来也是打字机效果。 但确实在ChatGPT-Next-Web中看不到打字机效果,只能看到一段段的输出。 另外, curl最后返回的data是[DONE], 但是程序永远都拿不到这个[DONE]的事件, 所以上面有兄台用finish_reason去判断是否结束。 BTW: finish_reason有很多, 不能仅仅判断是stop。 实际上, finish_reason不为空就应该结束了

curl https://xxx-gpt-35.openai.azure.com/openai/deployments/gpt-35-turbo-text/chat/completions\?api-version\=2023-03-15-preview \
  -H "Content-Type: application/json" \
  -H "api-key: xxx" \
  -d '{ 
    "stream": true,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"role":"assistant"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"Hello"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" there"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"!"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" How"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" may"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" I"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" assist"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" you"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":" today"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"?"}}],"usage":null}

data: {"id":"chatcmpl-7EuhenN4qKF8VZP5cIXMOhu85xTMK","object":"chat.completion.chunk","created":1683788914,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":"stop","delta":{}}],"usage":null}

data: [DONE]

是有data: [DONE]的 只是给eventsource-parser吃了 image

bob0627 commented 1 year ago

用azure 接口的话,还得通过cf转,响应太慢,不知本程序何时能原生直接支持azure的接口,速度上可能要快一些吧。

crystoneme commented 1 year ago

用azure 接口的话,还得通过cf转,响应太慢,不知本程序何时能原生直接支持azure的接口,速度上可能要快一些吧。

用过一段时间的cf转接口,确实有速度慢的问题,本来用Azure接口就是为了速度快而且不用翻墙,用cf转一下子反而速度慢了。失去了优势

Caixiaopig commented 1 year ago

貌似没有发现能够很好的支持Azure OpenAI Service的 Stream输出的APP 或 Web。大家有推荐的吗?

xiaoyongzhu commented 1 year ago
  • [你的SourceName].openai.azure.com/openai/deployments

@edisonzf2020 至少改四处才可以应用Azure openai API.

  1. BASE_URL 替换成Azure的,例如:[你的SourceName].openai.azure.com/openai/deployments
  2. headers不是用Authorization: `Bearer ${apiKey}`,,而是用"api-key": `${apiKey}`,
  3. "v1/chat/completions"替换成你在Azure Deploy的chat/completions的Path, 例如:[你的DeploymentId]/chat/completions?api-version=2023-03-15-preview
  4. chat-stream\route.ts里其中一段代码:
          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            const queue = encoder.encode(text);
            controller.enqueue(queue);
          } catch (e) {
            controller.error(e);
          }

替换为:

          try {
            const json = JSON.parse(data);
            const text = json.choices[0].delta.content;
            if (text) {
              // console.debug(text);
              const queue = encoder.encode(text);
              controller.enqueue(queue);
            } else {
              // console.log({ json });
              const stop = json.choices[0].finish_reason;
              if (stop === "stop") {
                controller.close();
                return;
              }
            }
          } catch (e) {
            controller.error(e);
          }

在最新的2.0代码中,似乎要改的东西变多了,奈何我前端水平有限,想看看社区中有没有人能够进行相关改动。

目前我看到的是第二条,应该是app/api/auth.ts中

req.headers.set("Authorization", `Bearer ${apiKey}`);

变为

req.headers.set("api-key", `${apiKey}`);

另外第四条中文件的路径似乎变为了app/api/openai/[...path]/route.ts

当实际deploy了app之后,会遇到404的问题,似乎和代码中hard code的OpenAI API path有关。

JinchaoLove commented 1 year ago

设置是是否可以增加一个选择机构的选项,比如[OpenAI, Azure, Baidu, Self-host, ...],并给出默认BASE_URL且支持修改,然后再选择模型(Azure可能还得增加实例名称的填空)和填入api-key?

duronxx commented 1 year ago

各位大神,部署了fastchat,自带的Web界面在太难用,使用next-web,发现可以通,就是显示 不对,请问这个要怎么修改? image

duronxx commented 1 year ago

附上日志,大神分析一下,感谢 image

yinm0591 commented 1 year ago

fastchat api改成stream模式,你可以到fastchat里去问问如何改stream模式。

zpng commented 1 year ago

咨询下大家有申请下来azure gpt4 权限的吗

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Do you have any application for azure gpt4 permission?

zpng commented 1 year ago

用azure 接口的话,还得通过cf转,响应太慢,不知本程序何时能原生直接支持azure的接口,速度上可能要快一些吧。

用过一段时间的cf转接口,确实有速度慢的问题,本来用Azure接口就是为了速度快而且不用翻墙,用cf转一下子反而速度慢了。失去了优势

请教下这个速度慢的问题解决了没?

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


If you use the azure interface, you have to transfer it through cf, and the response is too slow. I don’t know when this program will directly support the azure interface natively. The speed may be faster.

I have used the cf interface for a while, and it does have the problem of slow speed. I originally used the Azure interface for fast speed and no need to go over the wall, but the speed is slow when I use cf to transfer all at once. lost the edge

Please let me know if this slow problem has been solved?