Skip to content

Commit

Permalink
✨ feat: support openrouter as a new model provider (lobehub#1572)
Browse files Browse the repository at this point in the history
* ✨ feat: add openrouter provider

* ✨ feat: add openrouter default headers

* 🐛 fix: test case bug
  • Loading branch information
danielglh authored Mar 16, 2024
1 parent 6119be1 commit 780b1a2
Show file tree
Hide file tree
Showing 78 changed files with 1,151 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ OPENAI_API_KEY=sk-xxxxxxxxx

# GROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

########################################
######### OpenRouter Service ##########
########################################

#OPENROUTER_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

########################################
############ Market Service ############
########################################
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ ENV ANTHROPIC_API_KEY ""
# Mistral
ENV MISTRAL_API_KEY ""

# OpenRouter
ENV OPENROUTER_API_KEY ""

CMD ["node", "server.js"]
18 changes: 14 additions & 4 deletions docs/self-hosting/environment-variables/model-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ When using the `turn` mode, the API Keys will be retrieved in a round-robin mann
- Default: -
- Example: `sk-ant-apixx-xxxxxxxxx-xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx`

## Mistral AI

### `MISTRAL_API_KEY`

- Type: Required
- Description: This is the API key you applied for in the Mistral AI service
- Default: -
- Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=`

## Groq AI

### `GROQ_API_KEY`
Expand All @@ -170,13 +179,14 @@ When using the `turn` mode, the API Keys will be retrieved in a round-robin mann
- Default: -
- Example: `gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`

## Mistral AI
## OpenRouter AI

### `MISTRAL_API_KEY`
### `OPENROUTER_API_KEY`

- Type: Required
- Description: This is the API key you applied for in the Mistral AI service
- Description: This is the API key you applied for in the OpenRouter AI service
- Default: -
- Example: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=`
- Example: `sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=`


[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,13 @@ LobeChat 在部署时提供了丰富的模型服务商相关的环境变量,
- 描述:这是你在 Groq AI 服务中申请的 API 密钥
- 默认值:-
- 示例:`gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
## OpenRouter AI

### `OPENROUTER_API_KEY`

- 类型:必选
- 描述:这是你在 OpenRouter AI 服务中申请的 API 密钥
- 默认值:-
- 示例:`sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=`

[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
3 changes: 2 additions & 1 deletion locales/ar/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"ollama": "أولاما",
"oneapi": "وان آبي آي",
"openai": "أوبن إيه آي",
"openrouter": "OpenRouter",
"perplexity": "Perplexity",
"zhipu": "Zhipu"
},
Expand Down Expand Up @@ -146,4 +147,4 @@
"hasNew": "يوجد تحديث متاح",
"newVersion": "هناك إصدار جديد متاح: {{version}}"
}
}
}
8 changes: 7 additions & 1 deletion locales/ar/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"InvalidMistralAPIKey": "مفتاح Mistral AI API غير صحيح أو فارغ، يرجى التحقق من مفتاح Mistral API وإعادة المحاولة",
"InvalidMoonshotAPIKey": "مفتاح API لـ Moonshot AI غير صحيح أو فارغ، يرجى التحقق من مفتاح API لـ Moonshot وإعادة المحاولة",
"InvalidOllamaArgs": "تكوين Ollama غير صحيح، يرجى التحقق من تكوين Ollama وإعادة المحاولة",
"InvalidOpenRouterAPIKey": "مفتاح OpenRouter API غير صحيح أو فارغ، يرجى التحقق من مفتاح OpenRouter API وإعادة المحاولة",
"InvalidPerplexityAPIKey": "مفتاح Perplexity API غير صحيح أو فارغ، يرجى التحقق من مفتاح Perplexity API وإعادة المحاولة",
"InvalidZhipuAPIKey": "مفتاح Zhipu API غير صحيح أو فارغ، يرجى التحقق من مفتاح Zhipu API وإعادة المحاولة",
"LocationNotSupportError": "عذرًا، لا يدعم موقعك الحالي خدمة هذا النموذج، قد يكون ذلك بسبب قيود المنطقة أو عدم توفر الخدمة. يرجى التحقق مما إذا كان الموقع الحالي يدعم استخدام هذه الخدمة، أو محاولة استخدام معلومات الموقع الأخرى.",
Expand All @@ -57,6 +58,7 @@
"OllamaBizError": "خطأ في طلب خدمة Ollama، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"OllamaServiceUnavailable": "خدمة Ollama غير متوفرة، يرجى التحقق مما إذا كانت قد تم تشغيلها بشكل صحيح",
"OpenAIBizError": "حدث خطأ في طلب خدمة OpenAI، يرجى التحقق من المعلومات أدناه وإعادة المحاولة",
"OpenRouterBizError": "خطأ في طلب خدمة OpenRouter AI، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"PerplexityBizError": "خطأ في طلب خدمة Perplexity AI، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"PluginApiNotFound": "عذرًا، لا يوجد API للإضافة في وصف الإضافة، يرجى التحقق من تطابق طريقة الطلب الخاصة بك مع API الوصف",
"PluginApiParamsError": "عذرًا، فشلت التحقق من صحة معلمات الطلب للإضافة، يرجى التحقق من تطابق المعلمات مع معلومات الوصف",
Expand Down Expand Up @@ -110,6 +112,10 @@
"description": "أدخل مفتاح OpenAI API الخاص بك لبدء الجلسة. لن يقوم التطبيق بتسجيل مفتاح الواجهة البرمجية الخاص بك",
"title": "استخدام مفتاح OpenAI API المخصص"
},
"OpenRouter": {
"description": "أدخل مفتاح OpenRouter API الخاص بك للبدء في الجلسة. لن يتم تسجيل مفتاح الخاص بك من قبل التطبيق",
"title": "استخدام مفتاح OpenRouter API المخصص"
},
"Perplexity": {
"description": "أدخل مفتاح Perplexity API الخاص بك للبدء في الجلسة. لن يتم تسجيل مفتاح الواجهة البرمجية لتطبيقات الجلسة",
"title": "استخدام مفتاح Perplexity API المخصص"
Expand Down Expand Up @@ -144,4 +150,4 @@
"password": "كلمة المرور"
}
}
}
}
16 changes: 16 additions & 0 deletions locales/ar/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@
"title": "استخدام Azure OpenAI"
}
},
"OpenRouter": {
"checker": {
"desc": "اختبار صحة عنوان الوكيل"
},
"customModelName": {
"desc": "إضافة نموذج مخصص، استخدم فاصلة (،) للنماذج المتعددة",
"placeholder": "mistralai/mistral-7b-instruct:free,openchat/openchat-7b:free",
"title": "اسم النموذج المخصص"
},
"title": "OpenRouter",
"token": {
"desc": "أدخل مفتاح API من OpenRouter AI",
"placeholder": "مفتاح API من OpenRouter AI",
"title": "مفتاح API"
}
},
"Perplexity": {
"title": "Perplexity AI",
"token": {
Expand Down
3 changes: 2 additions & 1 deletion locales/de-DE/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"openrouter": "OpenRouter",
"perplexity": "Perplexity",
"zhipu": "Zhipu AI"
},
Expand Down Expand Up @@ -146,4 +147,4 @@
"hasNew": "Neue Version verfügbar",
"newVersion": "Neue Version verfügbar: {{version}}"
}
}
}
8 changes: 7 additions & 1 deletion locales/de-DE/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"InvalidMistralAPIKey": "Der Mistral AI-API-Schlüssel ist ungültig oder leer. Bitte überprüfen Sie den Mistral-API-Schlüssel und versuchen Sie es erneut.",
"InvalidMoonshotAPIKey": "Ungültiger oder leerer Moonshot AI API-Schlüssel. Bitte überprüfen Sie den Moonshot API-Schlüssel und versuchen Sie es erneut.",
"InvalidOllamaArgs": "Ollama-Konfiguration ist ungültig. Bitte überprüfen Sie die Ollama-Konfiguration und versuchen Sie es erneut.",
"InvalidOpenRouterAPIKey": "OpenRouter API-Schlüssel ungültig oder leer. Bitte überprüfen Sie den OpenRouter API-Schlüssel und versuchen Sie es erneut.",
"InvalidPerplexityAPIKey": "Perplexity API Key ist ungültig oder leer. Bitte überprüfen Sie den Perplexity API Key und versuchen Sie es erneut.",
"InvalidZhipuAPIKey": "Der Zhipu API-Schlüssel ist ungültig oder leer. Bitte überprüfen Sie den Zhipu API-Schlüssel und versuchen Sie es erneut.",
"LocationNotSupportError": "Entschuldigung, Ihr Standort unterstützt diesen Modellservice möglicherweise aufgrund von regionalen Einschränkungen oder nicht aktivierten Diensten nicht. Bitte überprüfen Sie, ob der aktuelle Standort die Verwendung dieses Dienstes unterstützt, oder versuchen Sie, andere Standortinformationen zu verwenden.",
Expand All @@ -57,6 +58,7 @@
"OllamaBizError": "Fehler bei der Anforderung des Ollama-Dienstes. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"OllamaServiceUnavailable": "Ollama-Dienst nicht verfügbar. Bitte überprüfen Sie, ob er ordnungsgemäß gestartet wurde.",
"OpenAIBizError": "Fehler bei der OpenAI-Serviceanfrage. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut",
"OpenRouterBizError": "Fehler bei der Anforderung des OpenRouter AI-Dienstes. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"PerplexityBizError": "Fehler bei der Anforderung des Perplexity AI-Dienstes. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"PluginApiNotFound": "Entschuldigung, das API des Plugins im Plugin-Manifest existiert nicht. Bitte überprüfen Sie, ob Ihre Anfragemethode mit dem Plugin-Manifest-API übereinstimmt",
"PluginApiParamsError": "Entschuldigung, die Eingabeüberprüfung der Plugin-Anfrage ist fehlgeschlagen. Bitte überprüfen Sie, ob die Eingabe mit den API-Beschreibungsinformationen übereinstimmt",
Expand Down Expand Up @@ -110,6 +112,10 @@
"description": "Geben Sie Ihren OpenAI API-Schlüssel ein, um die Sitzung zu starten. Die Anwendung speichert Ihren API-Schlüssel nicht.",
"title": "Verwenden von benutzerdefinierten OpenAI API-Schlüssel"
},
"OpenRouter": {
"description": "Geben Sie Ihren OpenRouter API-Schlüssel ein, um die Sitzung zu starten. Die App speichert Ihren API-Schlüssel nicht.",
"title": "Verwenden Sie einen benutzerdefinierten OpenRouter API-Schlüssel"
},
"Perplexity": {
"description": "Geben Sie Ihren eigenen Perplexity API Key ein, um das Gespräch zu beginnen. Die App speichert Ihren API Key nicht.",
"title": "Verwenden Sie einen benutzerdefinierten Perplexity API Key"
Expand Down Expand Up @@ -144,4 +150,4 @@
"password": "Passwort"
}
}
}
}
16 changes: 16 additions & 0 deletions locales/de-DE/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@
"title": "Azure OpenAI verwenden"
}
},
"OpenRouter": {
"checker": {
"desc": "Überprüfen Sie, ob die Proxy-Adresse korrekt eingegeben wurde"
},
"customModelName": {
"desc": "Fügen Sie benutzerdefinierte Modelle hinzu. Verwenden Sie zur Angabe mehrerer Modelle ein Komma (,)",
"placeholder": "mistralai/mistral-7b-instruct:free,openchat/openchat-7b:free",
"title": "Benutzerdefinierte Modellnamen"
},
"title": "OpenRouter",
"token": {
"desc": "Geben Sie den API-Schlüssel von OpenRouter AI ein",
"placeholder": "OpenRouter AI API-Schlüssel",
"title": "API-Schlüssel"
}
},
"Perplexity": {
"title": "perplexity",
"token": {
Expand Down
3 changes: 2 additions & 1 deletion locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"openrouter": "OpenRouter",
"perplexity": "Perplexity",
"zhipu": "Zhipu AI"
},
Expand Down Expand Up @@ -146,4 +147,4 @@
"hasNew": "New update available",
"newVersion": "New version available: {{version}}"
}
}
}
8 changes: 7 additions & 1 deletion locales/en-US/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"InvalidMistralAPIKey": "Incorrect or empty Mistral AI API Key. Please check your Mistral API Key and try again.",
"InvalidMoonshotAPIKey": "The Moonshot AI API Key is incorrect or empty, please check the Moonshot API Key and try again.",
"InvalidOllamaArgs": "Invalid Ollama configuration, please check Ollama configuration and try again",
"InvalidOpenRouterAPIKey": "Invalid or empty OpenRouter API Key. Please check your OpenRouter API Key and try again.",
"InvalidPerplexityAPIKey": "Perplexity API Key is incorrect or empty. Please check the Perplexity API Key and retry.",
"InvalidZhipuAPIKey": "Zhipu API Key is incorrect or empty. Please check the Zhipu API Key and retry.",
"LocationNotSupportError": "We're sorry, your current location does not support this model service. This may be due to regional restrictions or the service not being available. Please confirm if the current location supports using this service, or try using a different location.",
Expand All @@ -57,6 +58,7 @@
"OllamaBizError": "Error requesting Ollama service, please troubleshoot or retry based on the following information",
"OllamaServiceUnavailable": "Ollama service not detected, please check if it is running properly",
"OpenAIBizError": "Error requesting OpenAI service. Please troubleshoot or retry based on the following information.",
"OpenRouterBizError": "Error requesting OpenRouter AI service. Please troubleshoot or retry based on the following information.",
"PerplexityBizError": "Error requesting Perplexity AI service. Please troubleshoot or retry based on the following information.",
"PluginApiNotFound": "Sorry, the API does not exist in the plugin's manifest. Please check if your request method matches the plugin manifest API",
"PluginApiParamsError": "Sorry, the input parameter validation for the plugin request failed. Please check if the input parameters match the API description",
Expand Down Expand Up @@ -110,6 +112,10 @@
"description": "Enter your OpenAI API Key to start the session. The app will not store your API Key.",
"title": "Use custom OpenAI API Key"
},
"OpenRouter": {
"description": "Enter your OpenRouter API Key to start the session. The application will not store your API Key.",
"title": "Use Custom OpenRouter API Key"
},
"Perplexity": {
"description": "Enter your Perplexity API Key to start the session. The app will not store your API Key.",
"title": "Use custom Perplexity API Key"
Expand Down Expand Up @@ -144,4 +150,4 @@
"password": "Password"
}
}
}
}
16 changes: 16 additions & 0 deletions locales/en-US/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@
"title": "Azure OpenAI"
}
},
"OpenRouter": {
"checker": {
"desc": "Test if the proxy address is filled in correctly"
},
"customModelName": {
"desc": "Add custom model, separate multiple models with comma (,)",
"placeholder": "mistralai/mistral-7b-instruct:free,openchat/openchat-7b:free",
"title": "Custom Model Name"
},
"title": "OpenRouter",
"token": {
"desc": "Enter the API Key from OpenRouter AI",
"placeholder": "OpenRouter AI API Key",
"title": "API Key"
}
},
"Perplexity": {
"title": "Perplexity AI",
"token": {
Expand Down
3 changes: 2 additions & 1 deletion locales/es-ES/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"openrouter": "OpenRouter",
"perplexity": "Perplexity",
"zhipu": "Zhipu AI"
},
Expand Down Expand Up @@ -146,4 +147,4 @@
"hasNew": "Hay una nueva actualización disponible",
"newVersion": "Nueva versión disponible: {{version}}"
}
}
}
8 changes: 7 additions & 1 deletion locales/es-ES/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"InvalidMistralAPIKey": "La clave de API de Mistral AI es incorrecta o está vacía. Por favor, revise la clave de API de Mistral y vuelva a intentarlo.",
"InvalidMoonshotAPIKey": "La clave de API de Moonshot AI no es válida o está vacía. Por favor, revise la clave de API de Moonshot e inténtelo de nuevo.",
"InvalidOllamaArgs": "La configuración de Ollama no es válida, por favor revisa la configuración de Ollama e inténtalo de nuevo",
"InvalidOpenRouterAPIKey": "La clave de API de OpenRouter es incorrecta o está vacía. Por favor, revisa la clave de API de OpenRouter e inténtalo de nuevo",
"InvalidPerplexityAPIKey": "La clave de API de Perplexity es inválida o está vacía. Por favor, verifica la clave de API de Perplexity e inténtalo de nuevo",
"InvalidZhipuAPIKey": "La clave de API de Zhipu es incorrecta o está vacía, por favor, verifica la clave de API de Zhipu e inténtalo de nuevo",
"LocationNotSupportError": "Lo sentimos, tu ubicación actual no es compatible con este servicio de modelo, puede ser debido a restricciones geográficas o a que el servicio no está disponible. Por favor, verifica si tu ubicación actual es compatible con este servicio o intenta usar otra información de ubicación.",
Expand All @@ -57,6 +58,7 @@
"OllamaBizError": "Error al solicitar el servicio de Ollama, por favor verifica la siguiente información o inténtalo de nuevo",
"OllamaServiceUnavailable": "Servicio Ollama no disponible: Ollama no detectado. Por favor, verifica si está iniciado correctamente.",
"OpenAIBizError": "Error al solicitar el servicio OpenAI. Depure o reintente según la siguiente información",
"OpenRouterBizError": "Error al solicitar el servicio de IA de OpenRouter. Por favor, revisa la siguiente información o inténtalo de nuevo",
"PerplexityBizError": "Error comercial al solicitar el servicio de IA de Perplexity. Por favor, revisa la siguiente información o inténtalo de nuevo",
"PluginApiNotFound": "Lo sentimos, el API especificado no existe en el manifiesto del complemento. Verifique si su método de solicitud coincide con el API del manifiesto del complemento",
"PluginApiParamsError": "Lo sentimos, la validación de los parámetros de entrada de la solicitud del complemento no ha pasado. Verifique si los parámetros de entrada coinciden con la información de descripción del API",
Expand Down Expand Up @@ -110,6 +112,10 @@
"description": "Ingresa tu clave de API de OpenAI para comenzar la sesión. La aplicación no guardará tu clave de API",
"title": "Usar clave de API personalizada de OpenAI"
},
"OpenRouter": {
"description": "Ingresa tu clave de API de OpenRouter para comenzar la sesión. La aplicación no almacenará tu clave de API",
"title": "Usar una clave de API personalizada de OpenRouter"
},
"Perplexity": {
"description": "Ingresa tu clave de API de Perplexity para comenzar la sesión. La aplicación no guardará tu clave de API",
"title": "Usar tu propia clave de API de Perplexity"
Expand Down Expand Up @@ -144,4 +150,4 @@
"password": "Contraseña"
}
}
}
}
16 changes: 16 additions & 0 deletions locales/es-ES/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@
"title": "Azure OpenAI"
}
},
"OpenRouter": {
"checker": {
"desc": "Verifica si la dirección del proxy está correctamente escrita"
},
"customModelName": {
"desc": "Agrega modelos personalizados, separados por comas (,) si son varios",
"placeholder": "mistralai/mistral-7b-instruct:free,openchat/openchat-7b:free",
"title": "Nombre del modelo personalizado"
},
"title": "OpenRouter",
"token": {
"desc": "Ingresa la API Key de OpenRouter AI",
"placeholder": "API Key de OpenRouter AI",
"title": "API Key"
}
},
"Perplexity": {
"title": "Perplexity AI",
"token": {
Expand Down
3 changes: 2 additions & 1 deletion locales/fr-FR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"openrouter": "OpenRouter",
"perplexity": "Perplexity",
"zhipu": "Zhipu AI"
},
Expand Down Expand Up @@ -146,4 +147,4 @@
"hasNew": "Nouvelle mise à jour disponible",
"newVersion": "Nouvelle version disponible : {{version}}"
}
}
}
Loading

0 comments on commit 780b1a2

Please sign in to comment.