CF的AI Worker如何转openai API格式

有大佬能知道有啥开源项目可以转CF的AI Worker到OpenAI的标准API吗?

常规话题快问快答

#openai添加

这估计要自己写代码适配

这个还可以调用stable diffusion的模型,生成图片,还有语音转文字的

猜你想要这个

我自己试着跟着README.md部署了一个
url: https://openai-cf.test-375.workers.dev
自定义token: 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

跟着文档走的测试

curl https://openai-cf.test-375.workers.dev/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer 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" \
  -d '{
    "model": "@cf/meta/llama-2-7b-chat-int8",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'```

结果
```json
{"id":"3f4f7d8e-9c71-455e-92ba-f2bf8a65c24d","model":"@cf/meta/llama-2-7b-chat-int8","created":1717823001,"object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"Hello there! *adjusts glasses* It's a pleasure to meet you! Is there something I can help you with or would you like to chat? I'm here to assist you in any way I can. 😊"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}```
tip:
选那些bata版的模型进行请求不会计费
2 个赞

或者可以参考这个

cloudflare 本身支持openai形式的请求

1 个赞

我试试

这也能转?

1 个赞

确实不需要转,只要在oneapi填个代理就可以用

1 个赞