Code Monkey home page Code Monkey logo

claude-to-chatgpt's Introduction

English | 简体中文 | 日本語

Claude to ChatGPT

release GitHub Repo stars GitHub Repo Badge GitHub Repo Language

This project converts the API of Anthropic's Claude model to the OpenAI Chat API format.

  • ✨ Call Claude API like OpenAI ChatGPT API
  • 💦 Support streaming response
  • 🐻 Support claude-instant-1, claude-2 models
  • 🌩️ Deploy by Cloudflare Workers or Docker

Getting Started

You can run this project using Cloudflare Workers or Docker:

Deployment

Using Cloudflare Workers

By using Cloudflare Workers, you don't need a server to deploy this project.

  1. Create a Cloudflare Worker
  2. Paste the code in cloudflare-worker.js to Cloudflare Worker "Quick Edit" Editor
  3. Save and deploy
  4. (Optional) Set custom domain for your Cloudflare Worker

The Cloudfalre Workers support 100k requests a day, If you need to call more than that, you can use Docker to deploy as below.

Using Docker

docker run -p 8000:8000 wtzeng/claude-to-chatgpt:latest

Using Docker Compose

docker-compose up

The API will then be available at http://localhost:8000. API endpoint: /v1/chat/completions

Usage

When you input the model parameter as gpt-3.5-turbo or gpt-3.5-turbo-0613, it will be substituted with claude-instant-1. otherwise, claude-2 will be utilized.

GUI

Here are some recommended GUI software that supports this project:

CLI

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CLAUDE_API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Conversion Details

The Claude Completion API has an endpoint /v1/complete which takes the following JSON request:

{
  "prompt": "\n\nHuman: Hello, AI.\n\nAssistant: ",
  "model": "claude-instant-1",
  "max_tokens_to_sample": 100,
  "temperature": 1,
  "stream": true
}

And returns JSON with choices and completions.

The OpenAI Chat API has a similar /v1/chat/completions endpoint which takes:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "Hello, AI."
    }
  ],
  "max_tokens": 100,
  "temperature": 1,
  "stream": true
}

And returns JSON with a response string.

This project converts between these two APIs, get completions from the Claude model and formatting them as OpenAI Chat responses.

License

This project is licensed under the MIT License - see the LICENSE file for details.

claude-to-chatgpt's People

Contributors

eltociear avatar jamesflare1212 avatar jtsang4 avatar teralomaniac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

claude-to-chatgpt's Issues

docker部署无法用chatbox访问

docker部署的镜像用chatbox访问会一直failed to fetch, 直接curl是可以正常访问的, 用[ChatGPT-Next-Web 也正常。

Cloudflare部署时输出不全,大概判断是claude响应穿过来的Json数据块处理不对

以下是日志:
{
"outcome": "ok",
"scriptName": "api",
"diagnosticsChannelEvents": [],
"exceptions": [],
"logs": [
{
"message": [
"Error parsing line:",
"data: {"completion": " \u5bf9", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u4e0d", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: ping\r\ndata: {}\r\n\r\nevent: completion\r\ndata: {"completion": "\u8d77", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": ",", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u6211", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u6ca1\u6709", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}"
],
"level": "error",
"timestamp": 1689694428944
},
{
"message": [
"Error details:",
"SyntaxError: Unexpected non-whitespace character after JSON at position 170"
],
"level": "error",
"timestamp": 1689694428944
},
{
"message": [
"Error parsing line:",
"data: {"completion": "\u4e2d", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\n\r\ndata: {"completion": "\u65ad", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u5bf9", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u8bdd", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u3002", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u8bf7", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u95ee", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}"
],
"level": "error",
"timestamp": 1689694429173
},
{
"message": [
"Error details:",
"SyntaxError: Unexpected non-whitespace character after JSON at position 169"
],
"level": "error",
"timestamp": 1689694429173
},
{
"message": [
"Error parsing line:",
"data: {"completion": "\u4f60", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\n\r\ndata: {"completion": "\u505a", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u4ec0", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u4e48", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "\u5417", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}\r\n\r\nevent: completion\r\ndata: {"completion": "?", "stop_reason": null, "model": "claude-instant-1.1", "stop": null, "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}"
],
"level": "error",
"timestamp": 1689694429292
},
{
"message": [
"Error details:",
"SyntaxError: Unexpected non-whitespace character after JSON at position 169"
],
"level": "error",
"timestamp": 1689694429292
},
{
"message": [
"Error parsing line:",
"data: {"completion": "", "stop_reason": "stop_sequence", "model": "claude-instant-1.1", "stop": "\n\nHuman:", "log_id": "a90cd1c2e5cd79dc42e5b8370db171dd7560bc1e4992f532b0788bcdc290d385"}"
],
"level": "error",
"timestamp": 1689694429307
},
{
"message": [
"Error details:",
"SyntaxError: Bad control character in string literal in JSON at position 92"
],
"level": "error",
"timestamp": 1689694429307
}
],
"eventTimestamp": 1689694428393,
"event": {
"request": {
"url": "https://api.gptvpn.workers.dev//v1/chat/completions?path=v1%2Fchat%2Fcompletions",
"method": "POST",
"headers": {
"accept-encoding": "gzip",
"authorization": "REDACTED",
"cache-control": "no-store",
"cf-connecting-ip": "2a06:98c0:3600::103",
"cf-ipcountry": "JP",
"cf-ray": "7e8bc90167688a4a",
"cf-visitor": "{"scheme":"https"}",
"cf-worker": "cloudflare-workers.vercel-infra-production.com",
"connection": "Keep-Alive",
"content-length": "462",
"content-type": "application/json",
"host": "api.gptvpn.workers.dev",
"user-agent": "Vercel Edge Functions",
"x-forwarded-proto": "https",
"x-middleware-subrequest": "108e1acb26c5cd85cc0ba1407b11fcd31c80186c",
"x-real-ip": "2a06:98c0:3600::103",
"x-vercel-id": "hnd1::jt2tb-1689694428378-8c075663a13d"
},
"cf": {
"longitude": "139.68990",
"latitude": "35.68930",
"tlsCipher": "",
"continent": "AS",
"asn": 16509,
"country": "JP",
"tlsClientAuth": {
"certIssuerDNLegacy": "",
"certIssuerSKI": "",
"certSubjectDNRFC2253": "",
"certSubjectDNLegacy": "",
"certFingerprintSHA256": "",
"certNotBefore": "",
"certSKI": "",
"certSerial": "",
"certIssuerDN": "",
"certVerified": "NONE",
"certNotAfter": "",
"certSubjectDN": "",
"certPresented": "0",
"certRevoked": "0",
"certIssuerSerial": "",
"certIssuerDNRFC2253": "",
"certFingerprintSHA1": ""
},
"tlsVersion": "",
"colo": "NRT",
"timezone": "Asia/Tokyo",
"city": "Tokyo",
"edgeRequestKeepAliveStatus": 1,
"requestPriority": "",
"httpProtocol": "HTTP/1.1",
"region": "Tokyo",
"regionCode": "13",
"asOrganization": "Amazon.com",
"postalCode": "151-0053",
"botManagement": {
"corporateProxy": false,
"verifiedBot": false,
"jsDetection": {
"passed": false
},
"staticResource": false,
"detectionIds": {},
"score": 99
}
}
},
"response": {
"status": 200
}
},
"id": 7
}

对于rate limit的处理

今天又测试了一下,发现缺少对Claude API rate_limit_error 的处理,没记错OpenAI 报错会发一个message之类的信息,里面就可以写上rate limit,或者我记得官方就有rate limit error来着。

我的想法是,当探测到返回字段是:

{"error":{"type":"rate_limit_error","message":"Number of concurrent connections to Claude exceeds your rate limit. Please try again, or contact [email protected] to discuss your options for a rate limit increase."}}

的时候,就构造一个message返回,或者429报错。

此外,Claude给的免费API的rate是1秒一次,未来能否搞一个排队之类的功能。

请求返回401

Attaching to claude-to-chatgpt
claude-to-chatgpt | INFO: Started server process [1]
claude-to-chatgpt | INFO: Waiting for application startup.
claude-to-chatgpt | INFO: Application startup complete.
claude-to-chatgpt | INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
claude-to-chatgpt | INFO: 172.31.0.1:40810 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
claude-to-chatgpt | ERROR: Exception in ASGI application
claude-to-chatgpt | Traceback (most recent call last):
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
claude-to-chatgpt | result = await app( # type: ignore[func-returns-value]
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call
claude-to-chatgpt | return await self.app(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 276, in call
claude-to-chatgpt | await super().call(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/applications.py", line 122, in call
claude-to-chatgpt | await self.middleware_stack(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in call
claude-to-chatgpt | raise exc
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in call
claude-to-chatgpt | await self.app(scope, receive, _send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/cors.py", line 84, in call
claude-to-chatgpt | await self.app(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in call
claude-to-chatgpt | raise exc
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in call
claude-to-chatgpt | await self.app(scope, receive, sender)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
claude-to-chatgpt | raise e
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
claude-to-chatgpt | await self.app(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 718, in call
claude-to-chatgpt | await route.handle(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
claude-to-chatgpt | await self.app(scope, receive, send)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
claude-to-chatgpt | response = await func(request)
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 237, in app
claude-to-chatgpt | raw_response = await run_endpoint_function(
claude-to-chatgpt | File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
claude-to-chatgpt | return await dependant.call(**values)
claude-to-chatgpt | File "/app/claude_to_chatgpt/app.py", line 49, in chat
claude-to-chatgpt | openai_response = await response.anext()
claude-to-chatgpt | File "/app/claude_to_chatgpt/adapter.py", line 148, in chat
claude-to-chatgpt | raise Exception(f"Error: {response.status_code}")
claude-to-chatgpt | Exception: Error: 401

与openai 服务器连接不上 出现403 该如何解决

2023-05-16 02:34:22 INFO: Started server process [1]
2023-05-16 02:34:22 INFO: Waiting for application startup.
2023-05-16 02:34:22 INFO: Application startup complete.
2023-05-16 02:34:22 INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
2023-05-16 02:36:50 ERROR: Exception in ASGI application
2023-05-16 02:36:50 Traceback (most recent call last):
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
2023-05-16 02:36:50 result = await app( # type: ignore[func-returns-value]
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call
2023-05-16 02:36:50 return await self.app(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 276, in call
2023-05-16 02:36:50 await super().call(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/applications.py", line 122, in call
2023-05-16 02:36:50 await self.middleware_stack(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in call
2023-05-16 02:36:50 raise exc
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in call
2023-05-16 02:36:50 await self.app(scope, receive, _send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/cors.py", line 84, in call
2023-05-16 02:36:50 await self.app(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in call
2023-05-16 02:36:50 raise exc
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in call
2023-05-16 02:36:50 await self.app(scope, receive, sender)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
2023-05-16 02:36:50 raise e
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
2023-05-16 02:36:50 await self.app(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 718, in call
2023-05-16 02:36:50 await route.handle(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
2023-05-16 02:36:50 await self.app(scope, receive, send)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
2023-05-16 02:36:50 response = await func(request)
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 237, in app
2023-05-16 02:36:50 raw_response = await run_endpoint_function(
2023-05-16 02:36:50 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
2023-05-16 02:36:50 return await dependant.call(**values)
2023-05-16 02:36:50 File "/app/claude_to_chatgpt/app.py", line 49, in chat
2023-05-16 02:36:50 openai_response = await response.anext()
2023-05-16 02:36:50 File "/app/claude_to_chatgpt/adapter.py", line 145, in chat
2023-05-16 02:36:50 raise Exception(f"Error: {response.status_code}")
2023-05-16 02:36:50 Exception: Error: 403
2023-05-16 03:03:12 ERROR: Exception in ASGI application
2023-05-16 03:03:12 Traceback (most recent call last):
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
2023-05-16 03:03:12 result = await app( # type: ignore[func-returns-value]
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call
2023-05-16 03:03:12 return await self.app(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 276, in call
2023-05-16 03:03:12 await super().call(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/applications.py", line 122, in call
2023-05-16 03:03:12 await self.middleware_stack(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in call
2023-05-16 03:03:12 raise exc
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in call
2023-05-16 02:36:50 INFO: 172.17.0.1:59252 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
2023-05-16 03:00:36 INFO: 172.17.0.1:42472 - "GET /v1/chat/completions HTTP/1.1" 405 Method Not Allowed
2023-05-16 03:00:36 INFO: 172.17.0.1:42472 - "GET /favicon.ico HTTP/1.1" 404 Not Found
2023-05-16 03:03:12 INFO: 172.17.0.1:56096 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
2023-05-16 03:06:19 INFO: 172.17.0.1:41780 - "GET / HTTP/1.1" 404 Not Found
2023-05-16 03:03:12 await self.app(scope, receive, _send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/cors.py", line 84, in call
2023-05-16 03:03:12 await self.app(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in call
2023-05-16 03:03:12 raise exc
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in call
2023-05-16 03:03:12 await self.app(scope, receive, sender)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
2023-05-16 03:03:12 raise e
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
2023-05-16 03:03:12 await self.app(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 718, in call
2023-05-16 03:03:12 await route.handle(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
2023-05-16 03:03:12 await self.app(scope, receive, send)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
2023-05-16 03:03:12 response = await func(request)
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 237, in app
2023-05-16 03:03:12 raw_response = await run_endpoint_function(
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
2023-05-16 03:03:12 return await dependant.call(**values)
2023-05-16 03:03:12 File "/app/claude_to_chatgpt/app.py", line 35, in chat
2023-05-16 03:03:12 openai_params = await request.json()
2023-05-16 03:03:12 File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/requests.py", line 244, in json
2023-05-16 03:03:12 self._json = json.loads(body)
2023-05-16 03:03:12 File "/usr/local/lib/python3.9/json/init.py", line 346, in loads
2023-05-16 03:03:12 return _default_decoder.decode(s)
2023-05-16 03:03:12 File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
2023-05-16 03:03:12 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
2023-05-16 03:03:12 File "/usr/local/lib/python3.9/json/decoder.py", line 355, in raw_decode
2023-05-16 03:03:12 raise JSONDecodeError("Expecting value", s, err.value) from None
2023-05-16 03:03:12 json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

cloudflare部署后不知道如何使用

抱歉这是一个小白问题,我翻看了这个仓库的issues和readme还是不太了解应该怎么使用。

我跟着步骤:

  1. 在cloudflare里创建了一个worker,并在代码里添加了自己的Claude API
  2. 点击部署后生成如“claude-to-chatgpt.abc-d-efg.workers.dev”的网址(点击后跳转网页显示not found)
  3. 然后我使用翻译软件Bob的chatgpt插件,把API Key填了Claude API Key,再把API域名填了https://claude-to-chatgpt.abc-d-efg.workers.dev,但直接报错。

请问我该如何做呢?谢谢!

Not Found

部署完成后打开链接提示Not Found

Docker部署后访问API提示Internal Server Error

按照文档部署docker:docker run -d -p 8000:8000 wtzeng/claude-to-chatgpt:latest

然后执行curl命令报错Internal Server Error

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer sk-xxxxx" -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}] }' http://localhost:8000/v1/chat/completions

docker日志:

INFO:     172.17.0.1:58932 - "GET /v1/chat/completions HTTP/1.1" 405 Method Not Allowed
INFO:     172.17.0.1:58946 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "/app/claude_to_chatgpt/app.py", line 49, in chat
    openai_response = await response.__anext__()
  File "/app/claude_to_chatgpt/adapter.py", line 148, in chat
    raise Exception(f"Error: {response.status_code}")

请问是什么问题呢

New Model *-0613 and gpt-3.5-turbo-16k

OpenAI 发布了新模型:

  • gpt-4-0613
  • gpt-4-32k-0613
  • gpt-3.5-turbo-0613
  • gpt-3.5-turbo-16k

这些新的参数可能导致原有的程序出现 Bug,或许应更新新的 Mapping 了?


OpenAI has released new models:

  • gpt-4-0613
  • gpt-4-32k-0613
  • gpt-3.5-turbo-0613
  • gpt-3.5-turbo-16k

These new parameters may cause bugs in existing programs, so perhaps a new mapping should be updated?

Docker部署报错Exception: Error: 429

Docker部署会出现Exception: Error: 429,更换服务器部署也不行

docker run -p 8000:8000 wtzeng/claude-to-chatgpt:latest
Unable to find image 'wtzeng/claude-to-chatgpt:latest' locally
latest: Pulling from wtzeng/claude-to-chatgpt
99bf4787315b: Pull complete 
a8a848364b53: Pull complete 
0aaf86557fbf: Pull complete 
8c71f16084c0: Pull complete 
290b3a3dbec4: Pull complete 
0810955d261f: Pull complete 
eb731cf60c39: Pull complete 
969d7c703087: Pull complete 
78111175250e: Pull complete 
Digest: sha256:88a65df40ae971be35e8d41031d32117ada5772c693e0b45bc5e676748957140
Status: Downloaded newer image for wtzeng/claude-to-chatgpt:latest
INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO:     xxxxxxxx:62736 - "GET / HTTP/1.1" 404 Not Found
INFO:     xxxxxxxx:60100 - "POST /v1/chat/completions?path=v1&path=chat&path=completions HTTP/1.1" 200 OK
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 69, in app
    await response(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/responses.py", line 277, in __call__
    await wrap(partial(self.listen_for_disconnect, receive))
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/responses.py", line 273, in wrap
    await func()
  File "/root/.cache/pypoetry/virtualenvs/claude-to-chatgpt-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/responses.py", line 262, in stream_response
    async for chunk in self.body_iterator:
  File "/app/claude_to_chatgpt/app.py", line 39, in generate
    async for response in adapter.chat(request):
  File "/app/claude_to_chatgpt/adapter.py", line 160, in chat
    raise Exception(f"Error: {response.status_code}")
Exception: Error: 429

命令行直接调用出现这个:

root@VM-16-8-ubuntu:/home/ubuntu# curl http://XXXXXXXX:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-ant-api03-XXXXXXXXXXXX" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
Internal Server Error

在处理超长对话的时候报错 An error occurred while processing the excessively long conversation.

CloudFlare Workers 的报错和 #7 一样,经过一系列排查,我认为是等待 Claude 响应的过程超过了 CloudFlare Workers 的 CPU 时间限制,免费的版本是 10ms。怎么解决还没想法,要么拆成 Chunk,但是似乎不适用。要么升级付费版,有 50ms,但是考虑到有 100k Token Window,我认为也不是好办法。

随后我尝试了 Docker 版本,但是依旧报错,一次是向 Claude 请求超时(太长了),我添加了一个 TimeOut 的参数解决了;第二次超长对话测试,claude_response 不存在键 completion,导致报错,我就用 get() 处理了一下错误。

几次测试下来没问题(33k + 5k Token),提了 PR #10 作者看看。


The error with CloudFlare Workers is the same as #7. After a series of investigations, I believe that the process of waiting for Claude's response exceeds the CPU time limit of CloudFlare Workers' free version, which is 10ms. I haven't figured out how to solve it yet. Either split it into chunks, but it doesn't seem to be applicable; or upgrade to the paid version, which has 50ms, but considering there are 100k Token Windows, I don't think it's a good solution.

Later on, I tried the Docker version but still encountered errors. The first time was a timeout when requesting from Claude (it took too long), so I added a TimeOut parameter to solve it; and the second time was due to an error where claude_response did not have the key completion, causing an error. So I used get() method to handle this issue.

After several tests (33k + 5k Tokens), everything seems fine and I submitted a PR at #10 for review by the author.

佬,claude疑似修改了API信息格式,您看看,我可以提供多个KEY给您测试

自claude3发布后,好像API格式被改了,有了更多的要求,出现了多种报错,如下:

{
"error": {
"message": "messages: Unexpected role "system". The Messages API accepts a top-level system parameter, not "system" as an input message role. (request id: 2024031217275455426917732821996)",
"type": "invalid_request_error",
"param": "",
"code": null
}
}

{"error":{"message":"messages: first message must use the "user" role (request id: 2024031211095676132633895366427) (request id: 2024031211095627433661757301115)","type":"invalid_request_error","param":"","code":null}}

{"success":false,"content":null,"tokenCount":0,"errorMessage":"{"error":{"message":"messages: roles must alternate between \"user\" and \"assistant\", but found multiple \"user\" roles in a row (request id: 2024031218095472528132521153205)","type":"invalid_request_error","param":"","code":null}}","inputTokens":-1,"outputTokens":-1}

大佬 您有空可以看看 KEY我可以提供很多 您加我QQ84680396,我发给您,或者您留邮箱我发到您邮箱上

`max_tokens_to_sample: 9016` - Is this the Anthropic API maximum?

This is regarding this line.

We cannot find the 9016 token maximum anywhere in the Anthropic or any third-party documentation. The max_tokens_to_sample is mandatory, though, so we must set something (obviously <<10000).

If there is no hard limit in Anthropic's API, why not explicitly leave it to the script user:

// Config constant for max tokens 
const MAX_TOKENS = 9016;

async function handleRequest(request) {

  // ...
  
  const claudeRequestBody = {
    prompt,
    model: claudeModel,
    temperature,
    stop_sequences: stop,
    stream,
    
    // Always include max_tokens, using constant as default
    max_tokens_to_sample: MAX_TOKENS  
  };

  // ...

}

Either way, we appreciate having found your nifty script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.