haibbo / cf-openai-azure-proxy

A Cloudflare worker script to proxy OpenAI‘s request to Azure OpenAI Service
MIT License
1.66k stars 206 forks source link

in CloudFlare preview shows error 404 #37

Closed IncredibleAaron closed 9 months ago

IncredibleAaron commented 1 year ago

如题。 非程序员, 不是特别懂前端, 麻烦帮助。

问题:error 404

image

我的步骤:

  1. 在 cloudflare --> create worker --> Create"Hello World" script ( default sample ) --> Deploy
  2. cf-openai-azure-proxy.js 复制并粘贴到 Cloudflare Worker 编辑器中 --> 我copy所有内容到上面的worker.js文件里面。 覆盖之前给的hello world code.
  3. 修改 Env Var.
    
    const resourceName="chatgpt" //RESOURCE_NAME

const mapper = { 'gpt-3.5-turbo': "aBot" // DEPLOY_NAME_GPT35, // 'gpt-4': DEPLOY_NAME_GPT4 };


where resourceName seems correct --> endpoint https://chatgpt.openai.azure.com/

![image](https://github.com/haibbo/cf-openai-azure-proxy/assets/13446113/9c67b8b5-7bee-4fbc-be0d-26f6877eac64)

不知道哪里出了问题。 麻烦看看, 谢谢!
IncredibleAaron commented 1 year ago

根据别的Issue, 修改了 Post 地址, 加了 /v1/chat/completions, POST 是ok的, 但是又得到了 Missing model mapper 。。

mapper 加了 0301 也不对。。

    'gpt-3.5-turbo': "aBot", // DEPLOY_NAME_GPT35,
    'gpt-3.5-turbo-0301': 'aBot',

image

Teakowa commented 1 year ago
  1. 确保你添加了正确的 Authorization Header
  2. 确保你的 Request Body 与 OpenAI 一致

一个简单的例子:

POST /v1/chat/completions HTTP/1.1
Content-Type: application/json
Authorization: <Your Azure OpenAI Key>
Host: openai-proxy.exmaple.com
Connection: close
Content-Length: 97

{"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"\u4f60\u597d"}],"temperature":0.7}

Authorization 和 OpenAI 不一样,是没有 Bearer 的,另外建议用第三方 API 工具测,比如 Postman 什么的。

IncredibleAaron commented 1 year ago

谢谢 大佬讲解。

我还是不是特别理解这个地方应该怎么使用。 我以为会自动出现一个网页, 运行生成api key的东西。

那现在来讲的话, 意思是我们只是需要这个post功能? 这个应该正常运作的话会output什么有啊。。

那么这个页面主要有3个部分:

  1. Post 网址
  2. Header -- add key-val pairs
  3. Body 麻烦问一下这3个部分分别应该怎么放呢.

根据前面的, 我试用如下, 感觉还是不太对, 麻烦指点一下, 谢谢

` POST: https://mygpt.incredible_li.workers.dev/v1/chat/completions

Header: Content-Type: application/json Authorization: Host: openai-proxy.exmaple.com // 这个不是很确定放啥。。 Connection: close Content-Length: 97

Body: {"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"Please work as an translator"}],"temperature":0.7} `

Teakowa commented 1 year ago

谢谢 大佬讲解。

我还是不是特别理解这个地方应该怎么使用。 我以为会自动出现一个网页, 运行生成api key的东西。

那现在来讲的话, 意思是我们只是需要这个post功能? 这个应该正常运作的话会output什么有啊。。

那么这个页面主要有3个部分:

  1. Post 网址
  2. Header -- add key-val pairs
  3. Body 麻烦问一下这3个部分分别应该怎么放呢.

根据前面的, 我试用如下, 感觉还是不太对, 麻烦指点一下, 谢谢

` POST: https://mygpt.incredible_li.workers.dev/v1/chat/completions

Header: Content-Type: application/json Authorization: Host: openai-proxy.exmaple.com // 这个不是很确定放啥。。 Connection: close Content-Length: 97

Body: {"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"Please work as an translator"}],"temperature":0.7} `

这个项目只是一个实现 Azure OpenAI 代理的,目的是让 Azure 的 OpenAI 服务响应和 OpenAI API 一致,这样一些只支持 OpenAI API 的第三方客户端也可以使用,要配合其他的 ChatGPT 客户端用的呀,iOS 有 OpenCat,桌面平台有 Chatbox 什么的,可以自己搜一下。

你其实不需要管具体实现,你只要按照 README 步骤在 Cloudflare 上部署好了 proxy,然后找一个第三方客户端填上你的 proxy 地址,在 API key 里面填 Azure OpenAI Key 就可以了。

如果第三方客户端本来就支持 Azure OpenAI,那你就直接在 Azure OpenAI 相关的地方填你的 Azure OpenAI url 和密钥就好了。