-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ feat: Support Cloudflare Workers AI #2966
Conversation
This commit adds support for Cloudflare as a model provider. It includes changes to the `ModelProvider` enum, the `UserKeyVaults` interface, the `getServerGlobalConfig` function, the `DEFAULT_LLM_CONFIG` constant, the `getLLMConfig` function, the `AgentRuntime` class, and the `DEFAULT_MODEL_PROVIDER_LIST` constant.
@sxjeru is attempting to deploy a commit to the LobeHub Pro Team on Vercel. A member of the Team first needs to authorize it. |
👍 @sxjeru Thank you for raising your pull request and contributing to our Community |
Rebase下main |
有不少删了之前代码的地方。要revert回来 |
There are many places where the previous code has been deleted. To revert back |
} | ||
|
||
export const LobeCloudflareAI = LobeOpenAICompatibleFactory({ | ||
baseURL: `https://api.cloudflare.com/client/v4/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}/ai/v1`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里要用 llmEnv.XXX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
换成 llmEnv.CLOUDFLARE_ACCOUNT_ID 之后报下述错误:
`Error: ❌ Attempted to access a server-side environment variable on the client
请教一下有什么办法能让设置页的 Cloudflare Account ID 同步到此处 baseURL?
配置项写在 src/app/api/chat/agentRuntime.ts
case ModelProvider.Cloudflare: {
const { CLOUDFLARE_API_KEY, CLOUDFLARE_ACCOUNT_ID } = getLLMConfig();
const apiKey = apiKeyManager.pick(payload?.apiKey || CLOUDFLARE_API_KEY);
const accountID = payload.apiKey && payload.cloudflareAccountID ? payload.cloudflareAccountID : CLOUDFLARE_ACCOUNT_ID;
return { accountID, apiKey };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accountId 作为参数传给 server端。然后 server 端的 LobeCloudflareAI 初始化时候 baseURL 的逻辑变成 accountId 拼接的?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2966 +/- ##
==========================================
- Coverage 94.21% 93.45% -0.77%
==========================================
Files 403 405 +2
Lines 25657 26038 +381
Branches 2751 2034 -717
==========================================
+ Hits 24174 24335 +161
- Misses 1483 1703 +220
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Gotta reabse |
@sxjeru Will you write test or shall I? |
@BrandonStudio If you have free time, please do it.
|
OK. I will continue working on it. Please close this PR, and I will start a new one. |
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
由 #3402 代替。
参考 #2804 完成,目前已可对话,剩余事项如下:
尝试了文档中列出的所有模型,将其中能用中文正常交流的模型都加入列表了。
由于 beta 模型目前可免费使用,所以基本所有模型都是 enabled 状态。
📝 补充信息 | Additional Information
// ref https://developers.cloudflare.com/workers-ai/models/#text-generation
// api https://developers.cloudflare.com/workers-ai/configuration/open-ai-compatibility