Skip to content

Commit

Permalink
✨ feat: support anthropic as model provider (lobehub#1409)
Browse files Browse the repository at this point in the history
* ✨ feat: support anthropic as model provider

* ✨ feat: support anthropic with vision

* ✅ test: fix some with test

* 🐛 fix: anthropic error handling

* ✅ chore: fix broken tests

* 🐛 fix: remove unused imports

* 📝 doc: add note for anthropic with vercel/cloudflare

* 📝 docs: update docs

* 📝 docs: update docs

* 💄 style: update claude icons

* 💄 style: update tags

---------

Co-authored-by: arvinxx <arvinx@foxmail.com>
  • Loading branch information
danielglh and arvinxx authored Mar 5, 2024
1 parent 00a2972 commit a42cf8c
Show file tree
Hide file tree
Showing 84 changed files with 944 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ OPENAI_API_KEY=sk-xxxxxxxxx
# The local/remote ollama service url
# OLLAMA_PROXY_URL=http://127.0.0.1:11434/v1

########################################
######### Perplexity Service ##########
########################################

#PERPLEXITY_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

########################################
######### Anthropic Service ##########
########################################

#ANTHROPIC_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

########################################
############ Market Service ############
########################################
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ ENV MOONSHOT_API_KEY ""
# Ollama
ENV OLLAMA_PROXY_URL ""

# Perplexity
ENV PERPLEXITY_API_KEY ""

# Anthropic
ENV ANTHROPIC_API_KEY ""

CMD ["node", "server.js"]
24 changes: 24 additions & 0 deletions docs/self-hosting/environment-variables/model-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,27 @@ When using the `turn` mode, the API Keys will be retrieved in a round-robin mann
- Description: Used to enable the Ollama service, setting this will display optional open-source language models in the language model list and can also specify custom language models
- Default: -
- Example: `http://127.0.0.1:11434/v1`

## Perplexity AI

### `PERPLEXITY_API_KEY`

- Type: Required
- Description: This is the API key you applied from Perplexity AI
- Default: -
- Example: `pplx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`

## Anthropic AI

### `ANTHROPIC_API_KEY`

- Type: Required
- Description: This is the API key you applied from Anthropic AI
- Default: -
- Example: `sk-ant-apixx-xxxxxxxxx-xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx`


<Callout type={'warning'}>
There's [a known issue](https://github.com/anthropics/anthropic-sdk-typescript/issues/292) with the official Anthropic SDK on Vercel/Cloudflare edge runtime, which causes chat streams to be interrupted randomly. If you want to use the Anthropic provider, do not use Vercel/Cloudflare for now; the Anthropic provider should be working fine with other hosting options.
</Callout>

25 changes: 25 additions & 0 deletions docs/self-hosting/environment-variables/model-provider.zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,28 @@ LobeChat 在部署时提供了丰富的模型服务商相关的环境变量,
- 描述:用于启用 Ollama 服务,设置后可在语言模型列表内展示可选开源语言模型,也可以指定自定义语言模型
- 默认值:-
- 示例:`http://127.0.0.1:11434/v1`

## Perplexity AI

### `PERPLEXITY_API_KEY`

- 类型:必选
- 描述:这是你在 Perplexity AI 服务中申请的 API 密钥
- 默认值:-
- 示例:`pplx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`

## Anthropic AI

### `ANTHROPIC_API_KEY`

- 类型:必选
- 描述:这是你在 Anthropic AI 服务中申请的 API 密钥
- 默认值:-
- 示例:`sk-ant-apixx-xxxxxxxxx-xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx`

<Callout type={'warning'}>
官方 Anthropic SDK 在 Vercel/Cloudflare
边缘节点运行时存在一个[已知问题](https://github.com/anthropics/anthropic-sdk-typescript/issues/292)
,会导致聊天流出现随机中断。如果您希望在 lobe-chat 中使用 Anthropic 模型,请暂时不要部署到
Vercel/Cloudflare。Anthropic 模型在其他部署方式下可以正常工作。
</Callout>
1 change: 1 addition & 0 deletions locales/ar/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"layoutInitializing": "جاري تحميل التخطيط...",
"modelProvider": {
"anthropic": "Anthropic",
"azure": "أزور",
"bedrock": "بيدروك لأمازون ويب سيرفيس",
"google": "جوجل",
Expand Down
6 changes: 6 additions & 0 deletions locales/ar/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"503": "عذرًا، الخادم غير قادر حاليًا على معالجة طلبك، قد يكون بسبب الحمل الزائد أو الصيانة الجارية، يرجى المحاولة مرة أخرى لاحقًا",
"504": "عذرًا، الخادم لم ينتظر ردًا من الخادم الأصلي، يرجى المحاولة مرة أخرى لاحقًا",
"AgentRuntimeError": "حدث خطأ في تشغيل نموذج Lobe اللغوي، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"AnthropicBizError": "خطأ في طلب خدمة Anthropic AI، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"AzureBizError": "حدث خطأ في طلب خدمة Azure AI، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"BedrockBizError": "حدث خطأ في طلب خدمة Bedrock، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"GoogleBizError": "حدث خطأ في طلب خدمة Google، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"InvalidAccessCode": "كلمة المرور غير صحيحة أو فارغة، يرجى إدخال كلمة مرور الوصول الصحيحة أو إضافة مفتاح API مخصص",
"InvalidAnthropicAPIKey": "مفتاح Anthropic API غير صحيح أو فارغ، يرجى التحقق من مفتاح Anthropic API وإعادة المحاولة",
"InvalidAzureAPIKey": "مفتاح Azure API غير صحيح أو فارغ، يرجى التحقق من مفتاح Azure API وإعادة المحاولة",
"InvalidBedrockCredentials": "فشلت مصادقة Bedrock، يرجى التحقق من AccessKeyId/SecretAccessKey وإعادة المحاولة",
"InvalidGoogleAPIKey": "مفتاح Google API غير صحيح أو فارغ، يرجى التحقق من مفتاح Google API وإعادة المحاولة",
Expand Down Expand Up @@ -73,6 +75,10 @@
},
"unlock": {
"apikey": {
"Anthropic": {
"description": "أدخل مفتاح Anthropic API الخاص بك للبدء في الجلسة. لن يقوم التطبيق بتسجيل مفتاح الواجهة البرمجية الخاص بك",
"title": "استخدام مفتاح واجهة برمجة التطبيقات الخاص بـ Anthropic"
},
"Bedrock": {
"customRegion": "منطقة خدمة مخصصة",
"description": "أدخل مفتاح الوصول الخاص بك لـ Aws AccessKeyId / SecretAccessKey لبدء الجلسة. لن يقوم التطبيق بتسجيل تكوين المصادقة الخاص بك",
Expand Down
8 changes: 8 additions & 0 deletions locales/ar/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"sessionWithName": "إعدادات الجلسة · {{name}}"
},
"llm": {
"Anthropic": {
"title": "أنثروبيك",
"token": {
"desc": "أدخل مفتاح API من أنثروبيك",
"placeholder": "مفتاح API من أنثروبيك",
"title": "مفتاح API"
}
},
"AzureOpenAI": {
"azureApiVersion": {
"desc": "إصدار واجهة برمجة التطبيقات لـ Azure، يتبع تنسيق YYYY-MM-DD، راجع [أحدث الإصدار](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/de-DE/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"layoutInitializing": "Layout wird geladen...",
"modelProvider": {
"anthropic": "Anthropic",
"azure": "Azure",
"bedrock": "AWS Bedrock",
"google": "Google",
Expand Down
6 changes: 6 additions & 0 deletions locales/de-DE/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"503": "Entschuldigung, der Server kann Ihre Anfrage derzeit nicht verarbeiten. Möglicherweise aufgrund von Überlastung oder Wartungsarbeiten. Bitte versuchen Sie es später erneut",
"504": "Entschuldigung, der Server hat keine Antwort vom Upstream-Server erhalten. Bitte versuchen Sie es später erneut",
"AgentRuntimeError": "Es ist ein Fehler bei der Ausführung des Lobe-Sprachmodells aufgetreten. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"AnthropicBizError": "Fehler beim Anfordern des Anthropic AI-Dienstes. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"AzureBizError": "Es ist ein Fehler bei der Anforderung des Azure AI-Dienstes aufgetreten. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"BedrockBizError": "Es ist ein Fehler bei der Anforderung des Bedrock-Dienstes aufgetreten. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"GoogleBizError": "Es ist ein Fehler bei der Anforderung des Google-Dienstes aufgetreten. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"InvalidAccessCode": "Das Passwort ist ungültig oder leer. Bitte geben Sie das richtige Zugangspasswort ein oder fügen Sie einen benutzerdefinierten API-Schlüssel hinzu.",
"InvalidAnthropicAPIKey": "Ungültiger oder leerer Anthropic API-Schlüssel. Bitte überprüfen Sie den Anthropic API-Schlüssel und versuchen Sie es erneut.",
"InvalidAzureAPIKey": "Der Azure API-Schlüssel ist ungültig oder leer. Bitte überprüfen Sie den Azure API-Schlüssel und versuchen Sie es erneut.",
"InvalidBedrockCredentials": "Die Bedrock-Authentifizierung ist fehlgeschlagen. Bitte überprüfen Sie AccessKeyId/SecretAccessKey und versuchen Sie es erneut.",
"InvalidGoogleAPIKey": "Der Google API-Schlüssel ist ungültig oder leer. Bitte überprüfen Sie den Google API-Schlüssel und versuchen Sie es erneut.",
Expand Down Expand Up @@ -73,6 +75,10 @@
},
"unlock": {
"apikey": {
"Anthropic": {
"description": "Geben Sie Ihren Anthropic API-Schlüssel ein, um die Sitzung zu starten. Die Anwendung speichert Ihren API-Schlüssel nicht.",
"title": "Verwenden Sie einen benutzerdefinierten Anthropic API-Schlüssel"
},
"Bedrock": {
"customRegion": "Benutzerdefinierte Region",
"description": "Geben Sie Ihre Aws AccessKeyId / SecretAccessKey ein, um die Sitzung zu starten. Die Anwendung speichert Ihre Authentifizierungsinformationen nicht.",
Expand Down
8 changes: 8 additions & 0 deletions locales/de-DE/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"sessionWithName": "Sitzungseinstellungen · {{name}}"
},
"llm": {
"Anthropic": {
"title": "Anthropic",
"token": {
"desc": "Geben Sie den API-Schlüssel von Anthropic ein",
"placeholder": "Anthropic API-Schlüssel",
"title": "API-Schlüssel"
}
},
"AzureOpenAI": {
"azureApiVersion": {
"desc": "Die API-Version von Azure, die dem Format JJJJ-MM-TT folgt. Siehe [Neueste Version](https://learn.microsoft.com/de-de/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"layoutInitializing": "Initializing layout...",
"modelProvider": {
"anthropic": "Anthropic",
"azure": "Azure",
"bedrock": "AWS Bedrock",
"google": "Google",
Expand Down
6 changes: 6 additions & 0 deletions locales/en-US/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"503": "Sorry, the server is currently unable to process your request, possibly due to overload or maintenance. Please try again later.",
"504": "Sorry, the server did not receive a response from the upstream server. Please try again later.",
"AgentRuntimeError": "Lobe language model runtime execution error. Please troubleshoot or retry based on the following information.",
"AnthropicBizError": "Error requesting Anthropic service. Please troubleshoot or retry based on the following information.",
"AzureBizError": "Error requesting Azure AI service. Please troubleshoot or retry based on the following information.",
"BedrockBizError": "Error requesting Bedrock service. Please troubleshoot or retry based on the following information.",
"GoogleBizError": "Error requesting Google service. Please troubleshoot or retry based on the following information.",
"InvalidAccessCode": "Invalid access code or empty. Please enter the correct access code or add a custom API Key.",
"InvalidAnthropicAPIKey": "The Anthropic API Key is incorrect or empty. Please check the Anthropic API Key and retry.",
"InvalidAzureAPIKey": "Azure API Key is incorrect or empty. Please check the Azure API Key and retry.",
"InvalidBedrockCredentials": "Bedrock authentication failed. Please check the AccessKeyId/SecretAccessKey and retry.",
"InvalidGoogleAPIKey": "Google API Key is incorrect or empty. Please check the Google API Key and retry.",
Expand Down Expand Up @@ -73,6 +75,10 @@
},
"unlock": {
"apikey": {
"Anthropic": {
"description": "Enter your Anthropic API Key to start the session. The application will not store your API Key.",
"title": "Use Custom Anthropic API Key"
},
"Bedrock": {
"customRegion": "Custom service region",
"description": "Enter your Aws AccessKeyId / SecretAccessKey to start the session. The app will not store your authentication configuration.",
Expand Down
8 changes: 8 additions & 0 deletions locales/en-US/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"sessionWithName": "Session Settings · {{name}}"
},
"llm": {
"Anthropic": {
"title": "Anthropic",
"token": {
"desc": "Enter the API Key from Anthropic",
"placeholder": "Anthropic API Key",
"title": "API Key"
}
},
"AzureOpenAI": {
"azureApiVersion": {
"desc": "The API version of Azure, following the format YYYY-MM-DD. Check the [latest version](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/es-ES/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"layoutInitializing": "Inicializando diseño...",
"modelProvider": {
"anthropic": "Antropico",
"azure": "Azure",
"bedrock": "AWS Bedrock",
"google": "Google",
Expand Down
6 changes: 6 additions & 0 deletions locales/es-ES/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"503": "Lo sentimos, el servidor no puede procesar su solicitud en este momento, posiblemente debido a una sobrecarga o mantenimiento. Por favor, inténtelo de nuevo más tarde",
"504": "Lo sentimos, el servidor no recibió respuesta del servidor upstream. Por favor, inténtelo de nuevo más tarde",
"AgentRuntimeError": "Se produjo un error en la ejecución del tiempo de ejecución del modelo de lenguaje Lobe, por favor, verifica la siguiente información o inténtalo de nuevo",
"AnthropicBizError": "Se ha producido un error al solicitar el servicio de inteligencia artificial de Anthropic. Por favor, revisa la siguiente información o inténtalo de nuevo.",
"AzureBizError": "Se produjo un error al solicitar el servicio de Azure AI, por favor, verifica la siguiente información o inténtalo de nuevo",
"BedrockBizError": "Se produjo un error al solicitar el servicio de Bedrock, por favor, verifica la siguiente información o inténtalo de nuevo",
"GoogleBizError": "Se produjo un error al solicitar el servicio de Google, por favor, verifica la siguiente información o inténtalo de nuevo",
"InvalidAccessCode": "La contraseña no es válida o está vacía. Por favor, introduce una contraseña de acceso válida o añade una clave API personalizada",
"InvalidAnthropicAPIKey": "La clave de API de Anthropic es incorrecta o está vacía. Por favor, revisa la clave de API de Anthropic e inténtalo de nuevo.",
"InvalidAzureAPIKey": "La clave de API de Azure es incorrecta o está vacía, por favor, verifica la clave de API de Azure e inténtalo de nuevo",
"InvalidBedrockCredentials": "La autenticación de Bedrock no se ha completado con éxito, por favor, verifica AccessKeyId/SecretAccessKey e inténtalo de nuevo",
"InvalidGoogleAPIKey": "La clave de API de Google es incorrecta o está vacía, por favor, verifica la clave de API de Google e inténtalo de nuevo",
Expand Down Expand Up @@ -73,6 +75,10 @@
},
"unlock": {
"apikey": {
"Anthropic": {
"description": "Ingresa tu clave de API de Anthropic para comenzar la sesión. La aplicación no almacenará tu clave de API.",
"title": "Usar una clave de API personalizada de Anthropic"
},
"Bedrock": {
"customRegion": "Región de servicio personalizada",
"description": "Ingresa tu AccessKeyId/SecretAccessKey de Aws para comenzar la sesión. La aplicación no guardará tu configuración de autenticación",
Expand Down
8 changes: 8 additions & 0 deletions locales/es-ES/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"sessionWithName": "Configuración de la sesión · {{name}}"
},
"llm": {
"Anthropic": {
"title": "Anthropic",
"token": {
"desc": "Introduce la clave API de Anthropic",
"placeholder": "Clave API de Anthropic",
"title": "Clave API"
}
},
"AzureOpenAI": {
"azureApiVersion": {
"desc": "Versión de la API de Azure, en formato YYYY-MM-DD. Consulta la [última versión](https://learn.microsoft.com/es-es/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/fr-FR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"layoutInitializing": "Initialisation de la mise en page en cours...",
"modelProvider": {
"anthropic": "Anthropic",
"azure": "Azure",
"bedrock": "AWS Bedrock",
"google": "Google",
Expand Down
6 changes: 6 additions & 0 deletions locales/fr-FR/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"503": "Désolé, le serveur ne peut actuellement pas traiter votre requête, probablement en raison d'une surcharge ou de travaux de maintenance. Veuillez réessayer plus tard",
"504": "Désolé, le serveur n'a pas reçu de réponse de la part du serveur amont. Veuillez réessayer plus tard",
"AgentRuntimeError": "Erreur d'exécution du modèle linguistique Lobe, veuillez vérifier les informations ci-dessous ou réessayer",
"AnthropicBizError": "Erreur commerciale lors de la demande de service Anthropic AI. Veuillez vérifier les informations ci-dessous ou réessayer.",
"AzureBizError": "Erreur lors de la demande de service Azure AI, veuillez vérifier les informations ci-dessous ou réessayer",
"BedrockBizError": "Erreur lors de la demande de service Bedrock, veuillez vérifier les informations ci-dessous ou réessayer",
"GoogleBizError": "Erreur lors de la demande de service Google, veuillez vérifier les informations ci-dessous ou réessayer",
"InvalidAccessCode": "Le mot de passe est incorrect ou vide. Veuillez saisir le mot de passe d'accès correct ou ajouter une clé API personnalisée.",
"InvalidAnthropicAPIKey": "La clé API Anthropic est incorrecte ou manquante. Veuillez vérifier la clé API Anthropic et réessayer.",
"InvalidAzureAPIKey": "Clé API Azure incorrecte ou vide, veuillez vérifier la clé API Azure et réessayer",
"InvalidBedrockCredentials": "L'authentification Bedrock a échoué, veuillez vérifier AccessKeyId/SecretAccessKey et réessayer",
"InvalidGoogleAPIKey": "Clé API Google incorrecte ou vide, veuillez vérifier la clé API Google et réessayer",
Expand Down Expand Up @@ -73,6 +75,10 @@
},
"unlock": {
"apikey": {
"Anthropic": {
"description": "Entrez votre clé API Anthropic pour commencer la session. L'application ne stockera pas votre clé API.",
"title": "Utiliser une clé API Anthropic personnalisée"
},
"Bedrock": {
"customRegion": "Région de service personnalisée",
"description": "Entrez votre AccessKeyId/SecretAccessKey AWS pour commencer la session. L'application ne conservera pas votre configuration d'authentification",
Expand Down
8 changes: 8 additions & 0 deletions locales/fr-FR/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"sessionWithName": "Paramètres de session · {{name}}"
},
"llm": {
"Anthropic": {
"title": "Anthropic",
"token": {
"desc": "Entrez votre clé API Anthropic",
"placeholder": "Clé API Anthropic",
"title": "Clé API"
}
},
"AzureOpenAI": {
"azureApiVersion": {
"desc": "Version de l'API Azure, au format YYYY-MM-DD. Consultez la [dernière version](https://learn.microsoft.com/fr-fr/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/it-IT/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},
"layoutInitializing": "Inizializzazione layout in corso...",
"modelProvider": {
"anthropic": "Antropico",
"azure": "Azure",
"bedrock": "AWS Bedrock",
"google": "Google",
Expand Down
Loading

0 comments on commit a42cf8c

Please sign in to comment.