Skip to content

Commit

Permalink
✨ feat: Support Cloudflare Workers AI (#3402)
Browse files Browse the repository at this point in the history
* Delete .nvmrc

* feat: Add Cloudflare as a model provider

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.

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix icon

* fix

* Create .nvmrc

* Delete src/config/modelProviders/.nvmrc

* CF -> CLOUDFLARE

* revert

* chore: Update agentRuntime.ts and auth.ts to support Cloudflare account ID in payload

* Add provider setting

* fix

* Update cloudflare.ts

* fix

* Update cloudflare.ts

* accountID

* fix

* i18n

* save changes

* commit check

* disable function calling for now

* does not catch errors when fetching models

* ready to add base url

* commit check

* revert change

* revert string boolean check

* fix type error on Vercel.
refer to vercel/next.js#38736 (comment)

* i18n by groq/llama-3.1-8b-instant

* rename env var

* add test

* Revert changes that are not relavant to Cloudflare and result in merge conflicts.

* add test for models()

* move helper code to standalone file

* add test for helper methods

* remove encoder

* Merge main into cf-chat-m

* remove brand

* remove template comment

* add provider card

* Update lobe-icons

* Fix setting layout

* minor modification of model list

---------

Co-authored-by: sxjeru <sxjeru@gmail.com>
  • Loading branch information
BrandonStudio and sxjeru authored Nov 11, 2024
1 parent b4514cf commit efb7adf
Show file tree
Hide file tree
Showing 40 changed files with 1,672 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ OPENAI_API_KEY=sk-xxxxxxxxx

# QWEN_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

### Cloudflare Workers AI ####

# CLOUDFLARE_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

### SiliconCloud AI ####

# SILICONCLOUD_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Expand Down
12 changes: 12 additions & 0 deletions locales/ar/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "استخدام معلومات المصادقة الخاصة بـ Bedrock المخصصة"
}
},
"cloudflare": {
"apiKey": {
"desc": "يرجى ملء Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "أدخل رقم حساب Cloudflare أو عنوان URL API المخصص",
"placeholder": "رقم حساب Cloudflare / عنوان URL API المخصص",
"title": "رقم حساب Cloudflare / عنوان URL API"
}
},
"github": {
"personalAccessToken": {
"desc": "أدخل رمز الوصول الشخصي الخاص بك على Github، انقر [هنا](https://github.com/settings/tokens) لإنشاء واحد",
Expand Down
12 changes: 12 additions & 0 deletions locales/bg-BG/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Използване на персонализирана информация за удостоверяване на Bedrock"
}
},
"cloudflare": {
"apiKey": {
"desc": "Моля, въведете Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Въведете ID на Cloudflare или личен API адрес",
"placeholder": "ID на Cloudflare / личен API адрес",
"title": "ID на Cloudflare / API адрес"
}
},
"github": {
"personalAccessToken": {
"desc": "Въведете вашия GitHub PAT, кликнете [тук](https://github.com/settings/tokens), за да създадете",
Expand Down
12 changes: 12 additions & 0 deletions locales/de-DE/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Verwenden Sie benutzerdefinierte Bedrock-Authentifizierungsinformationen"
}
},
"cloudflare": {
"apiKey": {
"desc": "Bitte füllen Sie die Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Eingeben Sie die Cloudflare-Kundenkennung oder die benutzerdefinierte API-Adresse",
"placeholder": "Cloudflare-Kundenkennung / benutzerdefinierte API-Adresse",
"title": "Cloudflare-Kundenkennung / API-Adresse"
}
},
"github": {
"personalAccessToken": {
"desc": "Geben Sie Ihr GitHub-PAT ein und klicken Sie [hier](https://github.com/settings/tokens), um eines zu erstellen.",
Expand Down
12 changes: 12 additions & 0 deletions locales/en-US/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Use Custom Bedrock Authentication Information"
}
},
"cloudflare": {
"apiKey": {
"desc": "Please enter Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Enter your Cloudflare account ID or custom API address",
"placeholder": "Cloudflare Account ID / custom API URL",
"title": "Cloudflare Account ID / API Address"
}
},
"github": {
"personalAccessToken": {
"desc": "Enter your GitHub PAT. Click [here](https://github.com/settings/tokens) to create one.",
Expand Down
12 changes: 12 additions & 0 deletions locales/es-ES/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Usar información de autenticación de Bedrock personalizada"
}
},
"cloudflare": {
"apiKey": {
"desc": "Por favor complete la Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Ingrese el ID de cuenta de Cloudflare o la dirección URL personalizada de API",
"placeholder": "ID de cuenta de Cloudflare / URL de API personalizada",
"title": "ID de cuenta de Cloudflare / dirección URL de API"
}
},
"github": {
"personalAccessToken": {
"desc": "Introduce tu PAT de Github, haz clic [aquí](https://github.com/settings/tokens) para crear uno",
Expand Down
12 changes: 12 additions & 0 deletions locales/fr-FR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Utiliser des informations d'authentification Bedrock personnalisées"
}
},
"cloudflare": {
"apiKey": {
"desc": "Veuillez remplir l'Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Saisir l'ID de compte Cloudflare ou l'adresse API personnalisée",
"placeholder": "ID de compte Cloudflare / URL API personnalisée",
"title": "ID de compte Cloudflare / adresse API"
}
},
"github": {
"personalAccessToken": {
"desc": "Entrez votre PAT GitHub, cliquez [ici](https://github.com/settings/tokens) pour en créer un.",
Expand Down
12 changes: 12 additions & 0 deletions locales/it-IT/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Usa le informazioni di autenticazione Bedrock personalizzate"
}
},
"cloudflare": {
"apiKey": {
"desc": "Compila l'Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Inserisci l'ID dell'account Cloudflare o l'indirizzo API personalizzato",
"placeholder": "ID account Cloudflare / URL API personalizzato",
"title": "ID account Cloudflare / indirizzo API"
}
},
"github": {
"personalAccessToken": {
"desc": "Inserisci il tuo PAT di Github, clicca [qui](https://github.com/settings/tokens) per crearne uno",
Expand Down
12 changes: 12 additions & 0 deletions locales/ja-JP/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "使用カスタム Bedrock 認証情報"
}
},
"cloudflare": {
"apiKey": {
"desc": "Cloudflare API Key を入力してください",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Cloudflare アカウント ID またはカスタム API アドレスを入力してください。",
"placeholder": "Cloudflare アカウント ID / カスタム API URL",
"title": "Cloudflare アカウント ID / API アドレス"
}
},
"github": {
"personalAccessToken": {
"desc": "あなたのGithub PATを入力してください。[こちら](https://github.com/settings/tokens)をクリックして作成します",
Expand Down
12 changes: 12 additions & 0 deletions locales/ko-KR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "사용자 정의 Bedrock 인증 정보 사용"
}
},
"cloudflare": {
"apiKey": {
"desc": "Cloudflare API Key 를 작성해 주세요.",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "클라우드 플레어 계정 ID 또는 사용자 지정 API 주소 입력",
"placeholder": "클라우드 플레어 계정 ID / 사용자 지정 API 주소",
"title": "클라우드 플레어 계정 ID / API 주소"
}
},
"github": {
"personalAccessToken": {
"desc": "당신의 Github PAT를 입력하세요. [여기](https://github.com/settings/tokens)를 클릭하여 생성하세요.",
Expand Down
12 changes: 12 additions & 0 deletions locales/nl-NL/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Gebruik aangepaste Bedrock-verificatiegegevens"
}
},
"cloudflare": {
"apiKey": {
"desc": "Voer Cloudflare API Key in",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Voer uw Cloudflare-account ID of een custom API-URL in",
"placeholder": "Cloudflare-account ID / custom API-URL",
"title": "Cloudflare-account ID / API-URL"
}
},
"github": {
"personalAccessToken": {
"desc": "Vul je Github PAT in, klik [hier](https://github.com/settings/tokens) om er een te maken",
Expand Down
12 changes: 12 additions & 0 deletions locales/pl-PL/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Użyj niestandardowych informacji uwierzytelniających Bedrock"
}
},
"cloudflare": {
"apiKey": {
"desc": "Wprowadź klucz Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Wprowadź ID konta Cloudflare lub adres API niestandardowy",
"placeholder": "ID konta Cloudflare / adres API niestandardowy",
"title": "ID konta Cloudflare / adres API"
}
},
"github": {
"personalAccessToken": {
"desc": "Wprowadź swój osobisty token dostępu GitHub (PAT), kliknij [tutaj](https://github.com/settings/tokens), aby go utworzyć",
Expand Down
12 changes: 12 additions & 0 deletions locales/pt-BR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Usar informações de autenticação Bedrock personalizadas"
}
},
"cloudflare": {
"apiKey": {
"desc": "Insira o Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Insira o ID da conta do Cloudflare ou o endereço da API personalizado",
"placeholder": "ID da conta do Cloudflare / URL da API personalizada",
"title": "ID da conta do Cloudflare / Endereço da API"
}
},
"github": {
"personalAccessToken": {
"desc": "Insira seu PAT do Github, clique [aqui](https://github.com/settings/tokens) para criar",
Expand Down
12 changes: 12 additions & 0 deletions locales/ru-RU/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Использовать пользовательскую информацию аутентификации Bedrock"
}
},
"cloudflare": {
"apiKey": {
"desc": "Пожалуйста, заполните Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Введите ID аккаунта Cloudflare или адрес API по умолчанию",
"placeholder": "ID аккаунта Cloudflare / адрес API по умолчанию",
"title": "ID аккаунта Cloudflare / адрес API"
}
},
"github": {
"personalAccessToken": {
"desc": "Введите ваш персональный токен доступа GitHub (PAT), нажмите [здесь](https://github.com/settings/tokens), чтобы создать его",
Expand Down
12 changes: 12 additions & 0 deletions locales/tr-TR/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Özel Bedrock Kimlik Bilgilerini Kullan"
}
},
"cloudflare": {
"apiKey": {
"desc": "Lütfen doldurun Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Cloudflare hesabınızın ID'sini veya özel API adresinizi girin",
"placeholder": "Cloudflare Hesap ID / Özel API Adresi",
"title": "Cloudflare Hesap ID / API Adresi"
}
},
"github": {
"personalAccessToken": {
"desc": "Github PAT'nizi girin, [buraya](https://github.com/settings/tokens) tıklayarak oluşturun",
Expand Down
12 changes: 12 additions & 0 deletions locales/vi-VN/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "Sử dụng Thông tin Xác thực Bedrock tùy chỉnh"
}
},
"cloudflare": {
"apiKey": {
"desc": "Vui lòng nhập Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "Nhập ID tài khoản Cloudflare hoặc địa chỉ API tùy chỉnh",
"placeholder": "ID tài khoản Cloudflare / địa chỉ API tùy chỉnh",
"title": "ID tài khoản Cloudflare / địa chỉ API"
}
},
"github": {
"personalAccessToken": {
"desc": "Nhập mã truy cập cá nhân Github của bạn, nhấp vào [đây](https://github.com/settings/tokens) để tạo",
Expand Down
12 changes: 12 additions & 0 deletions locales/zh-CN/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "使用自定义 Bedrock 鉴权信息"
}
},
"cloudflare": {
"apiKey": {
"desc": "请填写 Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "填入 Cloudflare 账户 ID 或 自定义 API 地址",
"placeholder": "Cloudflare Account ID / custom API URL",
"title": "Cloudflare 账户 ID / API 地址"
}
},
"github": {
"personalAccessToken": {
"desc": "填入你的 Github PAT,点击 [这里](https://github.com/settings/tokens) 创建",
Expand Down
12 changes: 12 additions & 0 deletions locales/zh-TW/modelProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"title": "使用自定義 Bedrock 驗證資訊"
}
},
"cloudflare": {
"apiKey": {
"desc": "請填入 Cloudflare API Key",
"placeholder": "Cloudflare API Key",
"title": "Cloudflare API Key"
},
"baseURLOrAccountID": {
"desc": "填入 Cloudflare 帳戶 ID 或 自定義 API 位址",
"placeholder": "Cloudflare 帳戶 ID / 自定義 API 位址",
"title": "Cloudflare 帳戶 ID / API 位址"
}
},
"github": {
"personalAccessToken": {
"desc": "填入你的 Github 個人存取權杖,點擊[這裡](https://github.com/settings/tokens) 創建",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"@langchain/community": "^0.3.0",
"@lobehub/chat-plugin-sdk": "^1.32.4",
"@lobehub/chat-plugins-gateway": "^1.9.0",
"@lobehub/icons": "^1.37.0",
"@lobehub/icons": "^1.38.1",
"@lobehub/tts": "^1.25.1",
"@lobehub/ui": "^1.152.0",
"@neondatabase/serverless": "^0.10.1",
Expand Down
43 changes: 43 additions & 0 deletions src/app/(main)/settings/llm/ProviderList/Cloudflare/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use client';

import { Input } from 'antd';
import { useTranslation } from 'react-i18next';

import { CloudflareProviderCard } from '@/config/modelProviders';
import { GlobalLLMProviderKey } from '@/types/user/settings';

import { KeyVaultsConfigKey } from '../../const';
import { ProviderItem } from '../../type';

const providerKey: GlobalLLMProviderKey = 'cloudflare';

export const useCloudflareProvider = (): ProviderItem => {
const { t } = useTranslation('modelProvider');

return {
...CloudflareProviderCard,
apiKeyItems: [
{
children: (
<Input.Password
autoComplete={'new-password'}
placeholder={t(`${providerKey}.apiKey.placeholder`)}
/>
),
desc: t(`${providerKey}.apiKey.desc`),
label: t(`${providerKey}.apiKey.title`),
name: [KeyVaultsConfigKey, providerKey, 'apiKey'],
},
{
children: (
<Input
placeholder={t(`${providerKey}.baseURLOrAccountID.placeholder`)}
/>
),
desc: t(`${providerKey}.baseURLOrAccountID.desc`),
label: t(`${providerKey}.baseURLOrAccountID.title`),
name: [KeyVaultsConfigKey, providerKey, 'baseURLOrAccountID'],
},
],
};
};
Loading

0 comments on commit efb7adf

Please sign in to comment.